Add map_insert which returns the pointer to inserted value

This commit is contained in:
gingerBill
2021-08-29 11:45:11 +01:00
parent b88e945268
commit a5c31bbee0
3 changed files with 35 additions and 10 deletions
+9
View File
@@ -523,6 +523,15 @@ resize_dynamic_array :: proc(array: ^$T/[dynamic]$E, length: int, loc := #caller
return true;
}
@builtin
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));
return (^V)(data + h.value_offset);
}
@builtin