aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2020-11-23 19:14:36 +0000
committergingerBill <bill@gingerbill.org>2020-11-23 19:14:36 +0000
commita55568b0c480b8a4ba7cf2f24ff2bb41cfc759ff (patch)
tree7f2634130ec16da3655fe292f036173abe4c64c2 /core
parentb08ec005b29c28917cfe6ae664dcdb7b97f8f6b6 (diff)
Make hash internal key be `uintptr` rather than `u64` to reduce entry size
Diffstat (limited to 'core')
-rw-r--r--core/runtime/core_builtin.odin2
-rw-r--r--core/runtime/dynamic_map_internal.odin68
2 files changed, 36 insertions, 34 deletions
diff --git a/core/runtime/core_builtin.odin b/core/runtime/core_builtin.odin
index fd6c7c9af..8a1be60d9 100644
--- a/core/runtime/core_builtin.odin
+++ b/core/runtime/core_builtin.odin
@@ -265,7 +265,7 @@ reserve_map :: proc(m: ^$T/map[$K]$V, capacity: int) {
delete_key :: proc(m: ^$T/map[$K]$V, key: K) {
if m != nil {
key := key;
- __dynamic_map_delete_key(__get_map_header(m), __get_map_key(&key));
+ __dynamic_map_delete_key(__get_map_header(m), __get_map_hash(&key));
}
}
diff --git a/core/runtime/dynamic_map_internal.odin b/core/runtime/dynamic_map_internal.odin
index 7d93bb918..051d4073d 100644
--- a/core/runtime/dynamic_map_internal.odin
+++ b/core/runtime/dynamic_map_internal.odin
@@ -6,7 +6,7 @@ _ :: intrinsics;
INITIAL_MAP_CAP :: 16;
Map_Hash :: struct {
- hash: u64,
+ hash: uintptr,
key_ptr: rawptr, // address of Map_Entry_Header.key
}
@@ -39,6 +39,37 @@ Map_Header :: struct {
value_size: int,
}
+INITIAL_HASH_SEED :: 0xcbf29ce484222325;
+
+_fnv64a :: proc "contextless" (data: []byte, seed: u64 = INITIAL_HASH_SEED) -> u64 {
+ h: u64 = seed;
+ for b in data {
+ h = (h ~ u64(b)) * 0x100000001b3;
+ }
+ return h;
+}
+
+default_hash :: inline proc "contextless" (data: []byte) -> uintptr {
+ return uintptr(_fnv64a(data));
+}
+default_hash_string :: inline proc "contextless" (s: string) -> uintptr {
+ return default_hash(transmute([]byte)(s));
+}
+default_hash_ptr :: inline proc "contextless" (data: rawptr, size: int) -> uintptr {
+ s := Raw_Slice{data, size};
+ return default_hash(transmute([]byte)(s));
+}
+
+
+source_code_location_hash :: proc(s: Source_Code_Location) -> uintptr {
+ hash := _fnv64a(transmute([]byte)s.file_path);
+ hash = hash ~ (u64(s.line) * 0x100000001b3);
+ hash = hash ~ (u64(s.column) * 0x100000001b3);
+ return uintptr(hash);
+}
+
+
+
__get_map_header :: proc "contextless" (m: ^$T/map[$K]$V) -> Map_Header {
header := Map_Header{m = (^Raw_Map)(m)};
Entry :: struct {
@@ -58,10 +89,11 @@ __get_map_header :: proc "contextless" (m: ^$T/map[$K]$V) -> Map_Header {
header.value_offset = uintptr(offset_of(Entry, value));
header.value_size = int(size_of(V));
+
return header;
}
-__get_map_key :: proc "contextless" (k: ^$K) -> Map_Hash {
+__get_map_hash :: proc "contextless" (k: ^$K) -> Map_Hash {
key := k;
map_hash: Map_Hash;
@@ -88,36 +120,6 @@ __get_map_key :: proc "contextless" (k: ^$K) -> Map_Hash {
return map_hash;
}
-_fnv64a :: proc "contextless" (data: []byte, seed: u64 = 0xcbf29ce484222325) -> u64 {
- h: u64 = seed;
- for b in data {
- h = (h ~ u64(b)) * 0x100000001b3;
- }
- return h;
-}
-
-
-default_hash :: inline proc "contextless" (data: []byte) -> u64 {
- return _fnv64a(data);
-}
-default_hash_string :: inline proc "contextless" (s: string) -> u64 {
- return default_hash(transmute([]byte)(s));
-}
-default_hash_ptr :: inline proc "contextless" (data: rawptr, size: int) -> u64 {
- s := Raw_Slice{data, size};
- return default_hash(transmute([]byte)(s));
-}
-
-
-source_code_location_hash :: proc(s: Source_Code_Location) -> u64 {
- hash := _fnv64a(transmute([]byte)s.file_path);
- hash = hash ~ (u64(s.line) * 0x100000001b3);
- hash = hash ~ (u64(s.column) * 0x100000001b3);
- return hash;
-}
-
-
-
__slice_resize :: proc(array_: ^$T/[]$E, new_count: int, allocator: Allocator, loc := #caller_location) -> bool {
array := (^Raw_Slice)(array_);
@@ -275,7 +277,7 @@ __dynamic_map_hash_equal :: proc(h: Map_Header, a, b: Map_Hash) -> bool {
__dynamic_map_find :: proc(using h: Map_Header, hash: Map_Hash) -> Map_Find_Result #no_bounds_check {
fr := Map_Find_Result{-1, -1, -1};
- if n := u64(len(m.hashes)); n > 0 {
+ if n := uintptr(len(m.hashes)); n > 0 {
fr.hash_index = int(hash.hash % n);
fr.entry_index = m.hashes[fr.hash_index];
for fr.entry_index >= 0 {