|
@@ -45,27 +45,30 @@ static size_t searchSlot(CoreHashMap* m, const void* key) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-static void* searchValueU32(const CoreHashMap* m, const void* rawKey) {
|
|
|
|
- u32 key = *(const u32*)rawKey;
|
|
|
|
- if(m->capacity != 0) {
|
|
|
|
- if(key == 0) {
|
|
|
|
- size_t i = m->capacity - 1;
|
|
|
|
- return ((u32*)m->keys)[i] == 0 ? getValue(m, i) : nullptr;
|
|
|
|
- }
|
|
|
|
- size_t baseHash = ((size_t)key) * 514685581u;
|
|
|
|
- size_t end = m->capacity - 2;
|
|
|
|
- for(size_t i = 0; i <= end; i++) {
|
|
|
|
- size_t hash = (baseHash + i) & end;
|
|
|
|
- u32 keyEntry = *(u32*)getKey(m, hash);
|
|
|
|
- if(keyEntry == key) {
|
|
|
|
- return getValue(m, hash);
|
|
|
|
- } else if(keyEntry == 0) {
|
|
|
|
- return nullptr;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+#define SEARCH_VALUE(type, Type) \
|
|
|
|
+ static void* searchValue##Type(const CoreHashMap* m, const void* rawKey) { \
|
|
|
|
+ type key = *(const type*)rawKey; \
|
|
|
|
+ if(m->capacity != 0) { \
|
|
|
|
+ if(key == 0) { \
|
|
|
|
+ size_t i = m->capacity - 1; \
|
|
|
|
+ return ((type*)m->keys)[i] == 0 ? getValue(m, i) : nullptr; \
|
|
|
|
+ } \
|
|
|
|
+ size_t baseHash = ((size_t)key) * 514685581u; \
|
|
|
|
+ size_t end = m->capacity - 2; \
|
|
|
|
+ for(size_t i = 0; i <= end; i++) { \
|
|
|
|
+ size_t hash = (baseHash + i) & end; \
|
|
|
|
+ type keyEntry = *(type*)getKey(m, hash); \
|
|
|
|
+ if(keyEntry == key) { \
|
|
|
|
+ return getValue(m, hash); \
|
|
|
|
+ } else if(keyEntry == 0) { \
|
|
|
|
+ return nullptr; \
|
|
|
|
+ } \
|
|
|
|
+ } \
|
|
|
|
+ } \
|
|
|
|
+ return nullptr; \
|
|
}
|
|
}
|
|
- return nullptr;
|
|
|
|
-}
|
|
|
|
|
|
+SEARCH_VALUE(u32, U32)
|
|
|
|
+SEARCH_VALUE(u64, U64)
|
|
|
|
|
|
static void* searchValue(const CoreHashMap* m, const void* key) {
|
|
static void* searchValue(const CoreHashMap* m, const void* key) {
|
|
if(m->capacity != 0) {
|
|
if(m->capacity != 0) {
|
|
@@ -102,6 +105,7 @@ CoreHashMap coreInitHashMap(size_t keySize, size_t valueSize, CoreHasher hasher,
|
|
if(hasher == coreHash && equal == coreEqual) {
|
|
if(hasher == coreHash && equal == coreEqual) {
|
|
switch(keySize) {
|
|
switch(keySize) {
|
|
case sizeof(u32): search = searchValueU32; break;
|
|
case sizeof(u32): search = searchValueU32; break;
|
|
|
|
+ case sizeof(u64): search = searchValueU64; break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return (CoreHashMap){nullptr, nullptr, keySize, valueSize, 0,
|
|
return (CoreHashMap){nullptr, nullptr, keySize, valueSize, 0,
|