diff options
Diffstat (limited to 'common/hashmap.h')
-rw-r--r-- | common/hashmap.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/common/hashmap.h b/common/hashmap.h index 81a136f671..b645a37b01 100644 --- a/common/hashmap.h +++ b/common/hashmap.h @@ -240,6 +240,7 @@ public: void clear(bool shrinkArray = 0); + void erase(iterator entry); void erase(const Key &key); uint size() const { return _size; } @@ -591,6 +592,23 @@ void HashMap<Key, Val, HashFunc, EqualFunc>::setVal(const Key &key, const Val &v } template<class Key, class Val, class HashFunc, class EqualFunc> +void HashMap<Key, Val, HashFunc, EqualFunc>::erase(iterator entry) { + // Check whether we have a valid iterator + assert(entry._hashmap == this); + const uint ctr = entry._idx; + assert(ctr <= _mask); + Node * const node = _storage[ctr]; + assert(node != NULL); + assert(node != HASHMAP_DUMMY_NODE); + + // If we remove a key, we replace it with a dummy node. + freeNode(node); + _storage[ctr] = HASHMAP_DUMMY_NODE; + _size--; + _deleted++; +} + +template<class Key, class Val, class HashFunc, class EqualFunc> void HashMap<Key, Val, HashFunc, EqualFunc>::erase(const Key &key) { uint ctr = lookup(key); |