diff options
| author | gingerBill <bill@gingerbill.org> | 2025-04-16 10:52:35 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2025-04-16 10:52:35 +0100 |
| commit | 3dcc22fa6d0779e35e193ba4f5fae6b919d89080 (patch) | |
| tree | d7e8dd54a2f0981776ca70342137deaeaae4dae9 /base/runtime | |
| parent | 990cc56974fcaf6c77043c06ca41b62947a1fb98 (diff) | |
Change hashing rules for float-like types to make `0 == -0`
Diffstat (limited to 'base/runtime')
| -rw-r--r-- | base/runtime/dynamic_map_internal.odin | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/base/runtime/dynamic_map_internal.odin b/base/runtime/dynamic_map_internal.odin index 96ae9c73c..7b65a2fa0 100644 --- a/base/runtime/dynamic_map_internal.odin +++ b/base/runtime/dynamic_map_internal.odin @@ -1029,3 +1029,32 @@ default_hasher_cstring :: proc "contextless" (data: rawptr, seed: uintptr) -> ui h &= HASH_MASK return uintptr(h) | uintptr(uintptr(h) == 0) } + +default_hasher_f64 :: proc "contextless" (f: f64, seed: uintptr) -> uintptr { + f := f + buf: [size_of(f)]u8 + if f == 0 { + return default_hasher(&buf, seed, size_of(buf)) + } + if f != f { + // TODO(bill): What should the logic be for NaNs? + return default_hasher(&f, seed, size_of(f)) + } + return default_hasher(&f, seed, size_of(f)) +} + +default_hasher_complex128 :: proc "contextless" (x, y: f64, seed: uintptr) -> uintptr { + seed := seed + seed = default_hasher_f64(x, seed) + seed = default_hasher_f64(y, seed) + return seed +} + +default_hasher_quaternion256 :: proc "contextless" (x, y, z, w: f64, seed: uintptr) -> uintptr { + seed := seed + seed = default_hasher_f64(x, seed) + seed = default_hasher_f64(y, seed) + seed = default_hasher_f64(z, seed) + seed = default_hasher_f64(w, seed) + return seed +}
\ No newline at end of file |