Fixed bugs in the Knight shared files (not that these are used in SM).

This commit is contained in:
David Anderson 2009-01-29 12:50:32 -05:00
parent 992c05b6aa
commit 747ed1e59a
3 changed files with 25 additions and 3 deletions

View File

@ -1,3 +1,4 @@
#include <string.h>
#include <KeHashTable.h>
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;
}

View File

@ -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_

View File

@ -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();
}