aboutsummaryrefslogtreecommitdiff
path: root/common/hashmap.h
diff options
context:
space:
mode:
authorJohannes Schickel2011-01-30 17:28:35 +0000
committerJohannes Schickel2011-01-30 17:28:35 +0000
commit867c0d9645a6475e000cd7f49d72450517aea9aa (patch)
treebc7671373f28ee98f7d3c8d40dc28e8c0633f45d /common/hashmap.h
parentec885e5665b662f5c531d790e80fd064b3c4c428 (diff)
downloadscummvm-rg350-867c0d9645a6475e000cd7f49d72450517aea9aa.tar.gz
scummvm-rg350-867c0d9645a6475e000cd7f49d72450517aea9aa.tar.bz2
scummvm-rg350-867c0d9645a6475e000cd7f49d72450517aea9aa.zip
COMMON: Add an erase method which takes an iterator to HashMap.
Currently there is no iterator returned from this method, to have some similarity to associative containers of the STL. I also "added" one unit test for this method, which is basically just a copy of the HashMap::erase(const Key &) test with the required adaptions. svn-id: r55661
Diffstat (limited to 'common/hashmap.h')
-rw-r--r--common/hashmap.h18
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);