diff options
author | Gil <mcg@google.com> | 2018-04-24 08:59:38 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-24 08:59:38 -0700 |
commit | 8327390ccc27853c5bee794029a9ab2cc54df335 (patch) | |
tree | b6a93e3613774b2228ea3d262cad566de62114e3 /Firestore/core/src/firebase/firestore/immutable/tree_sorted_map.h | |
parent | 6dfc142888410ef6906970d8cb90f69c0992852a (diff) |
Implement erase in C++ immutable maps (#1158)
* Add SortedMap::min
* Add SortedMap::erase
Diffstat (limited to 'Firestore/core/src/firebase/firestore/immutable/tree_sorted_map.h')
-rw-r--r-- | Firestore/core/src/firebase/firestore/immutable/tree_sorted_map.h | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/Firestore/core/src/firebase/firestore/immutable/tree_sorted_map.h b/Firestore/core/src/firebase/firestore/immutable/tree_sorted_map.h index dac07b4..609b9da 100644 --- a/Firestore/core/src/firebase/firestore/immutable/tree_sorted_map.h +++ b/Firestore/core/src/firebase/firestore/immutable/tree_sorted_map.h @@ -106,9 +106,8 @@ class TreeSortedMap : public SortedMapBase, private util::ComparatorHolder<C> { * @return A new map without that value. */ TreeSortedMap erase(const K& key) const { - // TODO(wilhuff): Actually implement erase - (void)key; - return TreeSortedMap{this->comparator()}; + const C& comparator = this->comparator(); + return TreeSortedMap{root_.erase(key, comparator), comparator}; } bool contains(const K& key) const { @@ -172,6 +171,21 @@ class TreeSortedMap : public SortedMapBase, private util::ComparatorHolder<C> { return npos; } + const_iterator min() const { + return begin(); + } + + const_iterator max() const { + if (empty()) { + return end(); + } + + const node_type& max_node = root_.max(); + typename const_iterator::stack_type stack; + stack.push(&max_node); + return const_iterator{std::move(stack)}; + } + /** * Returns a forward iterator pointing to the first entry in the map. If there * are no entries in the map, begin() == end(). |