aboutsummaryrefslogtreecommitdiff
path: root/common/map.h
diff options
context:
space:
mode:
Diffstat (limited to 'common/map.h')
-rw-r--r--common/map.h16
1 files changed, 13 insertions, 3 deletions
diff --git a/common/map.h b/common/map.h
index caedd8eb9b..bbc9709507 100644
--- a/common/map.h
+++ b/common/map.h
@@ -166,13 +166,13 @@ public:
return node->_value;
}
- void remove(const Key &key) {
+ size_t erase(const Key &key) {
// TODO - implement efficiently. Indeed, maybe switch to using red-black trees?
// For now, just a lame, bad remove algorithm. Rule: don't remove elements
// from one of our maps if you need to be efficient :-)
Node *node = findNode(_root, key);
if (!node)
- return;
+ return 0; // key wasn't present, so no work has to be done
// Now we have to remove 'node'. There are two simple cases and one hard.
Node *parent = node->_parent;
@@ -206,8 +206,10 @@ public:
// Finally free the allocated memory
delete node;
- }
+ return 1;
+ }
+
void merge(const Map<Key, Value, Comparator> &map) {
merge(map._root);
}
@@ -225,6 +227,14 @@ public:
return const_iterator();
}
+ const_iterator find(const Key &key) const {
+ Node *node = findNode(_root, key);
+ if (node)
+ return const_iterator(node);
+ return end();
+ }
+
+
protected:
/** Merge the content of the given tree into this tree. */
void merge(const Node *node) {