diff options
author | Max Horn | 2006-03-28 12:35:50 +0000 |
---|---|---|
committer | Max Horn | 2006-03-28 12:35:50 +0000 |
commit | 37c79be74011eae8a78e369b455c565ebe5b6c8d (patch) | |
tree | 21b0be7617e1b09c3e136b135cee4563dfbf4f01 /common/map.h | |
parent | 41991f88a930d55804e2ed5b30cf04c4c3943c68 (diff) | |
download | scummvm-rg350-37c79be74011eae8a78e369b455c565ebe5b6c8d.tar.gz scummvm-rg350-37c79be74011eae8a78e369b455c565ebe5b6c8d.tar.bz2 scummvm-rg350-37c79be74011eae8a78e369b455c565ebe5b6c8d.zip |
- Renamed Map::remove to Map::erase (matching the STL and HashMap)
- Added Map::find() (see also HashMap), and made the ConfigManager use it
svn-id: r21477
Diffstat (limited to 'common/map.h')
-rw-r--r-- | common/map.h | 16 |
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) { |