From 747ed1e59a6d609b366e38a1891f69cc3d442c2a Mon Sep 17 00:00:00 2001 From: David Anderson Date: Thu, 29 Jan 2009 12:50:32 -0500 Subject: [PATCH] Fixed bugs in the Knight shared files (not that these are used in SM). --- knight/shared/KeHashTable.cpp | 11 +++++++++-- knight/shared/KeHashTable.h | 12 +++++++++++- knight/shared/KeLumpAllocator.cpp | 5 +++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/knight/shared/KeHashTable.cpp b/knight/shared/KeHashTable.cpp index 24bc1e4b..d601f11d 100644 --- a/knight/shared/KeHashTable.cpp +++ b/knight/shared/KeHashTable.cpp @@ -1,3 +1,4 @@ +#include #include using namespace Knight; @@ -82,7 +83,7 @@ KeHashTable *Knight::KE_CreateHashTable( table->key_m = *key_marshal; table->val_m = *val_marshal; table->num_entries = 0; - table->shift = bits; + table->shift = 32 - bits; table->node_alloc = nodeAlloc == NULL ? &s_DefHashAllocator : nodeAlloc; table->num_buckets = (1 << bits); table->grow_limit = (uint32_t)(0.9f * table->num_buckets); @@ -145,7 +146,7 @@ void ke_ResizeHashTable(KeHashTable *table, uint32_t new_shift) /* Save new data */ table->num_buckets = (1 << new_shift); - table->shift = new_shift; + table->shift = 32 - new_shift; table->grow_limit = (uint32_t)(0.9f * table->num_buckets); table->buckets = (KeHashNode **)malloc(sizeof(KeHashNode *) * table->num_buckets); @@ -407,3 +408,9 @@ uint32_t Knight::KE_HashString(const void *str) return h; } + +bool Knight::KE_AreStringsEqual(const void* str1, const void* str2) +{ + return (strcmp((const char*)str1, (const char*)str2) == 0) ? true : false; +} + diff --git a/knight/shared/KeHashTable.h b/knight/shared/KeHashTable.h index 79a69952..663903ab 100644 --- a/knight/shared/KeHashTable.h +++ b/knight/shared/KeHashTable.h @@ -117,12 +117,22 @@ namespace Knight extern void KE_ClearHashTable(KeHashTable *table); /** - * @brief Generic function for hasing strings. + * @brief Generic function for hashing strings. * * @param str Key string. * @return Hash value. */ extern uint32_t KE_HashString(const void *str); + + /** + * @brief Generic case-sensitive comparison of strings. + * + * @param str1 First string. + * @param str2 Second string. + * @return True if equal, false otherwise. + */ + extern bool KE_AreStringsEqual(const void* str1, const void* str2); } #endif //_INCLUDE_KNIGHT_KE_HASHTABLE_H_ + diff --git a/knight/shared/KeLumpAllocator.cpp b/knight/shared/KeLumpAllocator.cpp index 022be142..151e030e 100644 --- a/knight/shared/KeLumpAllocator.cpp +++ b/knight/shared/KeLumpAllocator.cpp @@ -88,6 +88,8 @@ public: #if defined KE_PLATFORM_WINDOWS VirtualFree(region, 0, MEM_RELEASE); +#else + free(region); #endif region = next; } @@ -193,6 +195,8 @@ private: m_DefLumpSize, MEM_COMMIT|MEM_RESERVE, PAGE_READWRITE); +#else + base = (char*)valloc(m_DefLumpSize); #endif /* Initialize the region */ @@ -256,3 +260,4 @@ void KE_LINK Knight::KE_ResetLumpAllocator(ke_allocator_t *alloc) { ke_LumpFromAllocator(alloc)->Reset(); } +