From ef73a284e3e438a25a4e329d59057cfa8cddf44c Mon Sep 17 00:00:00 2001 From: gingerBill Date: Fri, 22 Oct 2021 14:12:48 +0100 Subject: Fix check_remove_expr_info --- src/map.cpp | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) (limited to 'src/map.cpp') diff --git a/src/map.cpp b/src/map.cpp index 55eb4fbce..3a34764bf 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -114,16 +114,17 @@ gb_internal isize map__add_entry(Map *h, HashKey const &key) { template gb_internal MapFindResult map__find(Map *h, HashKey const &key) { MapFindResult fr = {-1, -1, -1}; - if (h->hashes.count > 0) { - fr.hash_index = key.key & (h->hashes.count-1); - fr.entry_index = h->hashes.data[fr.hash_index]; - while (fr.entry_index >= 0) { - if (hash_key_equal(h->entries.data[fr.entry_index].key, key)) { - return fr; - } - fr.entry_prev = fr.entry_index; - fr.entry_index = h->entries.data[fr.entry_index].next; + if (h->hashes.count == 0) { + return fr; + } + fr.hash_index = key.key & (h->hashes.count-1); + fr.entry_index = h->hashes.data[fr.hash_index]; + while (fr.entry_index >= 0) { + if (hash_key_equal(h->entries.data[fr.entry_index].key, key)) { + return fr; } + fr.entry_prev = fr.entry_index; + fr.entry_index = h->entries.data[fr.entry_index].next; } return fr; } @@ -131,16 +132,17 @@ gb_internal MapFindResult map__find(Map *h, HashKey const &key) { template gb_internal MapFindResult map__find_from_entry(Map *h, MapEntry *e) { MapFindResult fr = {-1, -1, -1}; - if (h->hashes.count > 0) { - fr.hash_index = e->key.key & (h->hashes.count-1); - fr.entry_index = h->hashes.data[fr.hash_index]; - while (fr.entry_index >= 0) { - if (&h->entries.data[fr.entry_index] == e) { - return fr; - } - fr.entry_prev = fr.entry_index; - fr.entry_index = h->entries.data[fr.entry_index].next; + if (h->hashes.count == 0) { + return fr; + } + fr.hash_index = e->key.key & (h->hashes.count-1); + fr.entry_index = h->hashes.data[fr.hash_index]; + while (fr.entry_index >= 0) { + if (&h->entries.data[fr.entry_index] == e) { + return fr; } + fr.entry_prev = fr.entry_index; + fr.entry_index = h->entries.data[fr.entry_index].next; } return fr; } @@ -246,6 +248,8 @@ void map__erase(Map *h, MapFindResult const &fr) { return; } h->entries.data[fr.entry_index] = h->entries.data[h->entries.count-1]; + array_pop(&h->entries); + last = map__find(h, h->entries.data[fr.entry_index].key); if (last.entry_prev >= 0) { h->entries.data[last.entry_prev].next = fr.entry_index; -- cgit v1.2.3