Fixed bugs in the Knight shared files (not that these are used in SM).
This commit is contained in:
parent
992c05b6aa
commit
747ed1e59a
knight/shared
@ -1,3 +1,4 @@
|
|||||||
|
#include <string.h>
|
||||||
#include <KeHashTable.h>
|
#include <KeHashTable.h>
|
||||||
|
|
||||||
using namespace Knight;
|
using namespace Knight;
|
||||||
@ -82,7 +83,7 @@ KeHashTable *Knight::KE_CreateHashTable(
|
|||||||
table->key_m = *key_marshal;
|
table->key_m = *key_marshal;
|
||||||
table->val_m = *val_marshal;
|
table->val_m = *val_marshal;
|
||||||
table->num_entries = 0;
|
table->num_entries = 0;
|
||||||
table->shift = bits;
|
table->shift = 32 - bits;
|
||||||
table->node_alloc = nodeAlloc == NULL ? &s_DefHashAllocator : nodeAlloc;
|
table->node_alloc = nodeAlloc == NULL ? &s_DefHashAllocator : nodeAlloc;
|
||||||
table->num_buckets = (1 << bits);
|
table->num_buckets = (1 << bits);
|
||||||
table->grow_limit = (uint32_t)(0.9f * table->num_buckets);
|
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 */
|
/* Save new data */
|
||||||
table->num_buckets = (1 << new_shift);
|
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->grow_limit = (uint32_t)(0.9f * table->num_buckets);
|
||||||
|
|
||||||
table->buckets = (KeHashNode **)malloc(sizeof(KeHashNode *) * 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;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Knight::KE_AreStringsEqual(const void* str1, const void* str2)
|
||||||
|
{
|
||||||
|
return (strcmp((const char*)str1, (const char*)str2) == 0) ? true : false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -117,12 +117,22 @@ namespace Knight
|
|||||||
extern void KE_ClearHashTable(KeHashTable *table);
|
extern void KE_ClearHashTable(KeHashTable *table);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Generic function for hasing strings.
|
* @brief Generic function for hashing strings.
|
||||||
*
|
*
|
||||||
* @param str Key string.
|
* @param str Key string.
|
||||||
* @return Hash value.
|
* @return Hash value.
|
||||||
*/
|
*/
|
||||||
extern uint32_t KE_HashString(const void *str);
|
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_
|
#endif //_INCLUDE_KNIGHT_KE_HASHTABLE_H_
|
||||||
|
|
||||||
|
@ -88,6 +88,8 @@ public:
|
|||||||
|
|
||||||
#if defined KE_PLATFORM_WINDOWS
|
#if defined KE_PLATFORM_WINDOWS
|
||||||
VirtualFree(region, 0, MEM_RELEASE);
|
VirtualFree(region, 0, MEM_RELEASE);
|
||||||
|
#else
|
||||||
|
free(region);
|
||||||
#endif
|
#endif
|
||||||
region = next;
|
region = next;
|
||||||
}
|
}
|
||||||
@ -193,6 +195,8 @@ private:
|
|||||||
m_DefLumpSize,
|
m_DefLumpSize,
|
||||||
MEM_COMMIT|MEM_RESERVE,
|
MEM_COMMIT|MEM_RESERVE,
|
||||||
PAGE_READWRITE);
|
PAGE_READWRITE);
|
||||||
|
#else
|
||||||
|
base = (char*)valloc(m_DefLumpSize);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Initialize the region */
|
/* Initialize the region */
|
||||||
@ -256,3 +260,4 @@ void KE_LINK Knight::KE_ResetLumpAllocator(ke_allocator_t *alloc)
|
|||||||
{
|
{
|
||||||
ke_LumpFromAllocator(alloc)->Reset();
|
ke_LumpFromAllocator(alloc)->Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user