aboutsummaryrefslogtreecommitdiff
path: root/src/exact_value.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2024-04-26 15:04:46 +0100
committergingerBill <bill@gingerbill.org>2024-04-26 15:04:46 +0100
commit2b26384b89ed2b29f9d7db13f73c52029a2a2341 (patch)
tree717b4d630ec3044107dc970b286c5ff94e014657 /src/exact_value.cpp
parentc685b404ea9cc9807b6d8cfc6f2a119924a79b4f (diff)
Implement dumb `PtrMap`
Diffstat (limited to 'src/exact_value.cpp')
-rw-r--r--src/exact_value.cpp37
1 files changed, 25 insertions, 12 deletions
diff --git a/src/exact_value.cpp b/src/exact_value.cpp
index b744d2db0..83af82f55 100644
--- a/src/exact_value.cpp
+++ b/src/exact_value.cpp
@@ -54,37 +54,50 @@ gb_global ExactValue const empty_exact_value = {};
gb_internal uintptr hash_exact_value(ExactValue v) {
mutex_lock(&hash_exact_value_mutex);
defer (mutex_unlock(&hash_exact_value_mutex));
+
+ uintptr res = 0;
switch (v.kind) {
case ExactValue_Invalid:
return 0;
case ExactValue_Bool:
- return gb_fnv32a(&v.value_bool, gb_size_of(v.value_bool));
+ res = gb_fnv32a(&v.value_bool, gb_size_of(v.value_bool));
+ break;
case ExactValue_String:
- return gb_fnv32a(v.value_string.text, v.value_string.len);
+ res = gb_fnv32a(v.value_string.text, v.value_string.len);
+ break;
case ExactValue_Integer:
{
u32 key = gb_fnv32a(v.value_integer.dp, gb_size_of(*v.value_integer.dp) * v.value_integer.used);
u8 last = (u8)v.value_integer.sign;
- return (key ^ last) * 0x01000193;
+ res = (key ^ last) * 0x01000193;
+ break;
}
case ExactValue_Float:
- return gb_fnv32a(&v.value_float, gb_size_of(v.value_float));
+ res = gb_fnv32a(&v.value_float, gb_size_of(v.value_float));
+ break;
case ExactValue_Pointer:
- return ptr_map_hash_key(v.value_pointer);
+ res = ptr_map_hash_key(v.value_pointer);
+ break;
case ExactValue_Complex:
- return gb_fnv32a(v.value_complex, gb_size_of(Complex128));
+ res = gb_fnv32a(v.value_complex, gb_size_of(Complex128));
+ break;
case ExactValue_Quaternion:
- return gb_fnv32a(v.value_quaternion, gb_size_of(Quaternion256));
+ res = gb_fnv32a(v.value_quaternion, gb_size_of(Quaternion256));
+ break;
case ExactValue_Compound:
- return ptr_map_hash_key(v.value_compound);
+ res = ptr_map_hash_key(v.value_compound);
+ break;
case ExactValue_Procedure:
- return ptr_map_hash_key(v.value_procedure);
+ res = ptr_map_hash_key(v.value_procedure);
+ break;
case ExactValue_Typeid:
- return ptr_map_hash_key(v.value_typeid);
+ res = ptr_map_hash_key(v.value_typeid);
+ break;
+ default:
+ res = gb_fnv32a(&v, gb_size_of(ExactValue));
}
- return gb_fnv32a(&v, gb_size_of(ExactValue));
-
+ return res & 0x7fffffff;
}