diff options
| author | gingerBill <bill@gingerbill.org> | 2020-11-29 15:50:29 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2020-11-29 15:50:29 +0000 |
| commit | 1dfe0cdd1de44d6c8b94c4e902a731655f8972c9 (patch) | |
| tree | 326812daa6c1351ac23f3a94bd14e3d480febe85 /core/runtime | |
| parent | 97c66c9c732af1e0735ee3f48a8af08b199bddf9 (diff) | |
Simplify hashing approach `map`
Diffstat (limited to 'core/runtime')
| -rw-r--r-- | core/runtime/core.odin | 6 | ||||
| -rw-r--r-- | core/runtime/dynamic_map_internal.odin | 10 |
2 files changed, 14 insertions, 2 deletions
diff --git a/core/runtime/core.odin b/core/runtime/core.odin index 74b1338c7..b0c76720a 100644 --- a/core/runtime/core.odin +++ b/core/runtime/core.odin @@ -42,8 +42,10 @@ Platform_Endianness :: enum u8 { Big = 2, } -Equal_Proc :: distinct proc "contextless" (rawptr, rawptr) -> bool; -Hasher_Proc :: distinct proc "contextless" (data: rawptr, seed: uintptr) -> uintptr; +// Procedure type to test whether two values of the same type are equal +Equal_Proc :: distinct proc "contextless" (rawptr, rawptr) -> bool; +// Procedure type to hash a value, default seed value is 0 +Hasher_Proc :: distinct proc "contextless" (data: rawptr, seed: uintptr = 0) -> uintptr; Type_Info_Struct_Soa_Kind :: enum u8 { None = 0, diff --git a/core/runtime/dynamic_map_internal.odin b/core/runtime/dynamic_map_internal.odin index 99c2e92ee..8ae366db3 100644 --- a/core/runtime/dynamic_map_internal.odin +++ b/core/runtime/dynamic_map_internal.odin @@ -110,6 +110,16 @@ default_hasher_string :: proc "contextless" (data: rawptr, seed: uintptr) -> uin } return uintptr(h); } +default_hasher_cstring :: proc "contextless" (data: rawptr, seed: uintptr) -> uintptr { + h := u64(seed) + 0xcbf29ce484222325; + ptr := (^uintptr)(data)^; + for (^byte)(ptr)^ != 0 { + b := (^byte)(ptr)^; + h = (h ~ u64(b)) * 0x100000001b3; + ptr += 1; + } + return uintptr(h); +} |