Merge pull request #42 from birth-software/better-hash-conversion
Better hash conversion
This commit is contained in:
commit
c2ce7403ab
@ -384,6 +384,14 @@ may_be_unused fn Hash64 hash_bytes(String bytes)
|
||||
return result;
|
||||
}
|
||||
|
||||
may_be_unused fn Hash32 hash64_to_hash32(Hash64 hash64)
|
||||
{
|
||||
Hash32 low = hash64 & 0xffff;
|
||||
Hash32 high = (hash64 >> 32) & 0xffff;
|
||||
Hash32 result = (high << 16) | low;
|
||||
return result;
|
||||
}
|
||||
|
||||
#if LINK_LIBC == 0
|
||||
#ifdef __linux__
|
||||
may_be_unused fn forceinline long syscall0(long n)
|
||||
|
@ -153,7 +153,9 @@ fn StringMapPut string_map_get(StringMap* map, String key)
|
||||
{
|
||||
u32 value = 0;
|
||||
auto long_hash = hash_bytes(key);
|
||||
auto hash = (Hash32)long_hash;
|
||||
static_assert(sizeof(long_hash) == sizeof(u64));
|
||||
auto hash = hash64_to_hash32(long_hash);
|
||||
static_assert(sizeof(hash) == sizeof(u32));
|
||||
assert(hash);
|
||||
auto index = hash & (map->capacity - 1);
|
||||
auto slot = string_map_find_slot(map, index, key);
|
||||
@ -174,7 +176,9 @@ fn StringMapPut string_map_get(StringMap* map, String key)
|
||||
fn StringMapPut string_map_put(StringMap* map, Arena* arena, String key, u32 value)
|
||||
{
|
||||
auto long_hash = hash_bytes(key);
|
||||
auto hash = (Hash32)long_hash;
|
||||
static_assert(sizeof(long_hash) == sizeof(u64));
|
||||
auto hash = hash64_to_hash32(long_hash);
|
||||
static_assert(sizeof(hash) == sizeof(u32));
|
||||
assert(hash);
|
||||
auto index = hash & (map->capacity - 1);
|
||||
auto slot = string_map_find_slot(map, index, key);
|
||||
|
Loading…
x
Reference in New Issue
Block a user