diff --git a/engines/hpl1/std/map.h b/engines/hpl1/std/map.h index 477cf8254a2..14db26f9bda 100644 --- a/engines/hpl1/std/map.h +++ b/engines/hpl1/std/map.h @@ -22,8 +22,8 @@ #ifndef HPL1_STD_MAP_H #define HPL1_STD_MAP_H -#include "hpl1/algorithms.h" #include "hpl1/std/pair.h" +#include "hpl1/std/tree.h" namespace Hpl1 { namespace Std { @@ -31,9 +31,9 @@ namespace Std { template > class map { public: - using value_type = pair; - using iterator = typename Common::Array::iterator; - using const_iterator = typename Common::Array::const_iterator; + using value_type = typename Tree::ValueType; + using iterator = typename Tree::BasicIterator; + using const_iterator = typename Tree::ConstIterator; /** * Clears the map @@ -75,31 +75,29 @@ public: * not less than the given key */ const_iterator lower_bound(const Key &key) const { - return lowerBound(this->begin(), this->end(), key, [&](value_type const &p, Key const &k) { return _comp(p.first, k); }); + return _items.lowerBound(key); } iterator lower_bound(const Key &key) { - return lowerBound(this->begin(), this->end(), key, [&](value_type const &p, Key const &k) { return _comp(p.first, k); }); + return _items.lowerBound(key); } iterator upper_bound(const Key &key) { - return upperBound(this->begin(), this->end(), key, [&](Key const &k, value_type const &p) { return _comp(k, p.first); }); + return _items.upperBound(key); } /** * Find the entry with the given key */ iterator find(const Key &theKey) { - iterator it = this->lower_bound(theKey); - + iterator it = _items.lowerBound(theKey); if (it != this->end() && compareEqual(it->first, theKey)) return it; return this->end(); } const_iterator find(const Key &theKey) const { - const_iterator it = this->lower_bound(theKey); - + const_iterator it = _items.lowerBound(theKey); if (it != this->end() && compareEqual(it->first, theKey)) return it; return this->end(); @@ -109,15 +107,11 @@ public: * Square brackets operator accesses items by key, creating if necessary */ Val &operator[](const Key &theKey) { - iterator it = this->lower_bound(theKey); + iterator it = _items.lowerBound(theKey); if (it == this->end() || !compareEqual(it->first, theKey)) { - size_t idx = it - this->begin(); - _items.insert_at(idx, {}); - _items[idx].first = theKey; - return _items[idx].second; - } else { - return _items[it - this->begin()].second; + return _items.insert(theKey).second; } + return *it->second; } /** @@ -139,16 +133,9 @@ public: } pair insert(const value_type &val) { - if (_items.begin() == nullptr) { - _items.push_back(val); - return {_items.begin(), true}; - } - iterator it = this->lower_bound(val.first); - if (it == this->end() || !compareEqual(it->first, val.first)) { - size_t idx = it - this->begin(); - _items.insert_at(idx, val); - return {this->begin() + idx, true}; - } + iterator it = _items.lowerBound(val.first); + if (it == this->end() || !compareEqual(it->first, val.first)) + return {_items.insert(val), true}; return {it, false}; } @@ -160,7 +147,7 @@ public: } bool empty() const { - return _items.empty(); + return _items.isEmpty(); } /** @@ -172,7 +159,6 @@ public: if (compareEqual(it->first, theKey)) ++count_; } - return count_; } @@ -181,7 +167,7 @@ private: return !_comp(a, b) && !_comp(b, a); } - Common::Array _items; + Tree _items; CompFunc _comp; }; diff --git a/engines/hpl1/std/multimap.h b/engines/hpl1/std/multimap.h index e0ca492b9f3..a20106c9132 100644 --- a/engines/hpl1/std/multimap.h +++ b/engines/hpl1/std/multimap.h @@ -22,7 +22,7 @@ #ifndef HPL1_STD_MULTIMAP_H #define HPL1_STD_MULTIMAP_H -#include "common/array.h" +#include "hpl1/std/tree.h" #include "hpl1/std/pair.h" namespace Hpl1 { @@ -32,9 +32,9 @@ namespace Std { template > class multimap { public: - using value_type = pair; - using iterator = typename Common::Array::iterator; - using const_iterator = typename Common::Array::const_iterator; + using value_type = typename Tree::ValueType; + using iterator = typename Tree::BasicIterator; + using const_iterator = typename Tree::ConstIterator; /** * Clears the map @@ -76,31 +76,29 @@ public: * not less than the given key */ const_iterator lower_bound(const Key &key) const { - return lowerBound(this->begin(), this->end(), key, [&](value_type const &p, Key const &k) { return _comp(p.first, k); }); + return _items.lowerBound(key); } iterator lower_bound(const Key &key) { - return lowerBound(this->begin(), this->end(), key, [&](value_type const &p, Key const &k) { return _comp(p.first, k); }); + return _items.lowerBound(key); } iterator upper_bound(const Key &key) { - return upperBound(this->begin(), this->end(), key, [&](Key const &k, value_type const &p) { return _comp(k, p.first); }); + return _items.upperBound(key); } /** * Find the entry with the given key */ iterator find(const Key &theKey) { - iterator it = this->lower_bound(theKey); - + iterator it = _items.lowerBound(theKey); if (it != this->end() && compareEqual(it->first, theKey)) return it; return this->end(); } const_iterator find(const Key &theKey) const { - const_iterator it = this->lower_bound(theKey); - + const_iterator it = _items.lowerBound(theKey); if (it != this->end() && compareEqual(it->first, theKey)) return it; return this->end(); @@ -126,10 +124,7 @@ public: } iterator insert(const value_type &val) { - iterator it = this->lower_bound(val.first); - size_t idx = it - this->begin(); - _items.insert_at(idx, val); - return it; + return _items.insert(val); } /** @@ -140,7 +135,7 @@ public: } bool empty() const { - return _items.empty(); + return _items.isEmpty(); } /** @@ -152,7 +147,6 @@ public: if (compareEqual(it->first, theKey)) ++count_; } - return count_; } @@ -161,7 +155,7 @@ private: return !_comp(a, b) && !_comp(b, a); } - Common::Array _items; + Tree _items; CompFunc _comp; };