aboutsummaryrefslogtreecommitdiff
path: root/dep/CascLib/src/common/Map.h
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2023-09-05 00:10:35 +0200
committerShauren <shauren.trinity@gmail.com>2023-09-05 00:10:35 +0200
commitd57b58849bda868f2463d38cc636f01af919316c (patch)
tree5beef62c041526d9468683e4388b6341f1530cc1 /dep/CascLib/src/common/Map.h
parentba224f70ad81fa0e5d1f0c4daf197e143317cdaa (diff)
Dep/CascLib: Update to ladislav-zezula/CascLib@5c60050770767f2e606f6fec0c35beb8b9b00c60
Diffstat (limited to 'dep/CascLib/src/common/Map.h')
-rw-r--r--dep/CascLib/src/common/Map.h21
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;