Index: runtime/platform/hashmap.cc |
diff --git a/runtime/platform/hashmap.cc b/runtime/platform/hashmap.cc |
index 461153398129a270433f45682ffd8f0765885a91..4d4b4774dd362a8e3c866f00c49c9abb6de84678 100644 |
--- a/runtime/platform/hashmap.cc |
+++ b/runtime/platform/hashmap.cc |
@@ -106,11 +106,27 @@ void HashMap::Remove(void* key, uint32_t hash) { |
// Clear the candidate which will not break searching the hash table. |
candidate->key = NULL; |
- candidate->value = NULL; |
occupancy_--; |
} |
+HashMap::Entry* HashMap::Remove(Entry* entry) { |
+ Remove(entry->key, entry->hash); |
+ |
+ // A key can only exist once in the map and we just removed `key`. This means |
+ // that either a left-rotation has happened (in which case `entry` points |
+ // already to the next element (in terms of iteration order)) or alternatively |
+ // we can use the normal `Next()` call to move in iteration order. |
+ if (entry->key != NULL) { |
+ // A left-rotation happened. `entry` points already to the next element in |
+ // iteration order. |
+ return entry; |
+ } else { |
+ return Next(entry); |
+ } |
+} |
+ |
+ |
void HashMap::Clear(ClearFun clear) { |
// Mark all entries as empty. |
const Entry* end = map_end(); |
@@ -118,7 +134,6 @@ void HashMap::Clear(ClearFun clear) { |
if ((clear != NULL) && (p->key != NULL)) { |
clear(p->value); |
} |
- p->value = NULL; |
p->key = NULL; |
} |
occupancy_ = 0; |