diff options
Diffstat (limited to 'dep/CascLib/src/common/Map.h')
-rw-r--r-- | dep/CascLib/src/common/Map.h | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/dep/CascLib/src/common/Map.h b/dep/CascLib/src/common/Map.h index 54dda5baed8..68177c466fc 100644 --- a/dep/CascLib/src/common/Map.h +++ b/dep/CascLib/src/common/Map.h @@ -15,7 +15,6 @@ // Structures #define MIN_HASH_TABLE_SIZE 0x00000100 // The smallest size of the hash table. -#define MAX_HASH_TABLE_SIZE 0x00800000 // The largest size of the hash table. Should be enough for any game. typedef int (*PFNCOMPAREFUNC)(const void * pvObjectKey, const void * pvKey, size_t nKeyLength); typedef DWORD (*PFNHASHFUNC)(void * pvKey, size_t nKeyLength); @@ -36,7 +35,7 @@ typedef enum _KEY_TYPE inline DWORD CalcHashValue_Hash(void * pvKey, size_t /* nKeyLength */) { // Get the hash directly as value - return ConvertBytesToInteger_4((LPBYTE)pvKey); + return ConvertBytesToInteger_4_LE((LPBYTE)pvKey); } // Calculates hash value from a key @@ -328,20 +327,22 @@ class CASC_MAP size_t GetNearestPowerOfTwo(size_t MaxItems) { - size_t PowerOfTwo; + size_t PowerOfTwo = MIN_HASH_TABLE_SIZE; // Round the hash table size up to the nearest power of two - for(PowerOfTwo = MIN_HASH_TABLE_SIZE; PowerOfTwo <= MAX_HASH_TABLE_SIZE; PowerOfTwo <<= 1) + while(PowerOfTwo < MaxItems) { - if(PowerOfTwo > MaxItems) + // Overflow check + if((PowerOfTwo << 1) < PowerOfTwo) { - return PowerOfTwo; + assert(false); + return 0; } - } - // If the hash table is too big, we cannot create the map - assert(false); - return 0; + // Shift the value + PowerOfTwo <<= 1; + } + return PowerOfTwo; } PFNHASHFUNC PfnCalcHashValue; |