Wrap __dynamic_map_find for certain cases

This commit is contained in:
gingerBill
2022-09-17 13:11:29 +01:00
parent 40bcfc7c8d
commit fbf036a654
2 changed files with 12 additions and 9 deletions

View File

@@ -325,8 +325,7 @@ delete_key :: proc(m: ^$T/map[$K]$V, key: K) -> (deleted_key: K, deleted_value:
if m != nil {
key := key
h := __get_map_header(m)
hash := __get_map_hash(&key)
fr := __dynamic_map_find(h, hash)
fr := __map_find(h, &key)
if fr.entry_index >= 0 {
entry := __dynamic_map_get_entry(h, fr.entry_index)
deleted_key = (^K)(uintptr(entry)+h.key_offset)^
@@ -674,9 +673,8 @@ shrink_dynamic_array :: proc(array: ^$T/[dynamic]$E, new_cap := -1, loc := #call
map_insert :: proc(m: ^$T/map[$K]$V, key: K, value: V, loc := #caller_location) -> (ptr: ^V) {
key, value := key, value
h := __get_map_header(m)
hash := __get_map_hash(&key)
data := uintptr(__dynamic_map_set(h, hash, &value, loc))
data := uintptr(__dynamic_map_set(h, __get_map_key_hash(&key), &key, &value, loc))
return (^V)(data + h.value_offset)
}

View File

@@ -11,11 +11,9 @@ Map_Hash :: struct {
key_ptr: rawptr, // address of Map_Entry_Header.key
}
__get_map_hash :: proc "contextless" (k: ^$K) -> (map_hash: Map_Hash) {
__get_map_key_hash :: proc "contextless" (k: ^$K) -> uintptr {
hasher := intrinsics.type_hasher_proc(K)
map_hash.key_ptr = k
map_hash.hash = hasher(k, 0)
return
return hasher(k, 0)
}
__get_map_hash_from_entry :: proc "contextless" (h: Map_Header, entry: ^Map_Entry_Header, hash: ^Map_Hash) {
@@ -347,6 +345,13 @@ __dynamic_map_hash_equal :: #force_inline proc "contextless" (h: Map_Header, a,
return a.hash == b.hash && h.equal(a.key_ptr, b.key_ptr)
}
__map_find :: proc "contextless" (h: Map_Header, key_ptr: ^$K) -> Map_Find_Result #no_bounds_check {
hash := __get_map_key_hash(key_ptr)
return __dynamic_map_find(h, {hash, key_ptr})
}
__dynamic_map_find :: proc "contextless" (using h: Map_Header, hash: Map_Hash) -> Map_Find_Result #no_bounds_check {
fr := Map_Find_Result{MAP_SENTINEL, MAP_SENTINEL, MAP_SENTINEL}
if n := uintptr(len(m.hashes)); n != 0 {