Fix delete_key #262

This commit is contained in:
gingerBill
2018-09-15 11:21:02 +01:00
parent 71d987bd2e
commit 9f3e42e4ef
+11 -6
View File
@@ -724,7 +724,7 @@ __get_map_key :: proc "contextless" (key: $K) -> Map_Key {
} }
case Type_Info_String: case Type_Info_String:
str := (^string)(&key)^; str := (^string)(&key)^;
map_key.hash = __default_hash_string(str); map_key.hash = default_hash_string(str);
map_key.str = str; map_key.str = str;
case: case:
panic("Unhandled map key type"); panic("Unhandled map key type");
@@ -924,15 +924,20 @@ __dynamic_map_erase :: proc(using h: Map_Header, fr: Map_Find_Result) #no_bounds
prev.next = curr.next; prev.next = curr.next;
} }
if (fr.entry_index == m.entries.len-1) { if (fr.entry_index == m.entries.len-1) {
m.entries.len -= 1; // NOTE(bill): No need to do anything else, just pop
return; } else {
} old := __dynamic_map_get_entry(h, fr.entry_index);
end := __dynamic_map_get_entry(h, m.entries.len-1);
mem.copy(old, end, entry_size);
last := __dynamic_map_find(h, __dynamic_map_get_entry(h, fr.entry_index).key); if last := __dynamic_map_find(h, old.key); last.entry_prev >= 0 {
if last.entry_prev >= 0 {
last_entry := __dynamic_map_get_entry(h, last.entry_prev); last_entry := __dynamic_map_get_entry(h, last.entry_prev);
last_entry.next = fr.entry_index; last_entry.next = fr.entry_index;
} else { } else {
m.hashes[last.hash_index] = fr.entry_index; m.hashes[last.hash_index] = fr.entry_index;
} }
} }
// TODO(bill): Is this correct behaviour?
m.entries.len -= 1;
}