aboutsummaryrefslogtreecommitdiff
path: root/core/runtime
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-07-04 18:52:47 +0100
committergingerBill <bill@gingerbill.org>2021-07-04 18:52:47 +0100
commita4be1a5e4c9d76b617fe17f564dc97e325e6fec8 (patch)
tree34964fd7f30b89a550ae1bb67f6ba930818333dc /core/runtime
parentee908c00deb92d2acffbb92be761b2eb169e8a89 (diff)
`delete_key` now returns the deleted key and deleted value (if found)
Diffstat (limited to 'core/runtime')
-rw-r--r--core/runtime/core_builtin.odin15
1 files changed, 13 insertions, 2 deletions
diff --git a/core/runtime/core_builtin.odin b/core/runtime/core_builtin.odin
index 29c84a59e..946f326ca 100644
--- a/core/runtime/core_builtin.odin
+++ b/core/runtime/core_builtin.odin
@@ -270,11 +270,22 @@ reserve_map :: proc(m: ^$T/map[$K]$V, capacity: int) {
// The delete_key built-in procedure deletes the element with the specified key (m[key]) from the map.
// If m is nil, or there is no such element, this procedure is a no-op
@builtin
-delete_key :: proc(m: ^$T/map[$K]$V, key: K) {
+delete_key :: proc(m: ^$T/map[$K]$V, key: K) -> (deleted_key: K, deleted_value: V) {
if m != nil {
key := key;
- __dynamic_map_delete_key(__get_map_header(m), __get_map_hash(&key));
+ h := __get_map_header(m);
+ hash := __get_map_hash(&key);
+ fr := __dynamic_map_find(h, hash);
+ if fr.entry_index >= 0 {
+ entry := __dynamic_map_get_entry(h, fr.entry_index);
+ deleted_key = (^K)(uintptr(entry)+h.key_offset)^;
+ deleted_value = (^V)(uintptr(entry)+h.value_offset)^;
+
+ __dynamic_map_erase(h, fr);
+ }
}
+
+ return;
}