diff options
author | Gil <mcg@google.com> | 2018-04-19 11:30:29 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-19 11:30:29 -0700 |
commit | 0df8378971553a203cc6982a298f342baecae543 (patch) | |
tree | 0db33e6bea1cb4ed6ca74ad299eb868bdb943693 /Firestore/core/src/firebase/firestore/immutable/tree_sorted_map.h | |
parent | 81ac1761e2195aa2f16c0377471e084910ccdb35 (diff) |
Implement iterators for our immutable maps (#1132)
* Add a minimal LlrbNodeIterator
* Remove fixed_size type parameter from FixedArray
The parameter wasn't that useful and caused problems in trying to define
dependent iterator types.
* Add begin()/end() to SortedMap.
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 | 18 |
1 files changed, 18 insertions, 0 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 ff8c9f9..c5eddc2 100644 --- a/Firestore/core/src/firebase/firestore/immutable/tree_sorted_map.h +++ b/Firestore/core/src/firebase/firestore/immutable/tree_sorted_map.h @@ -51,6 +51,7 @@ class TreeSortedMap : public SortedMapBase, private util::ComparatorHolder<C> { * The type of the node containing entries of value_type. */ using node_type = LlrbNode<K, V>; + using const_iterator = typename node_type::const_iterator; /** * Creates an empty TreeSortedMap. @@ -110,6 +111,23 @@ class TreeSortedMap : public SortedMapBase, private util::ComparatorHolder<C> { return root_; } + /** + * Returns a forward iterator pointing to the first entry in the map. If there + * are no entries in the map, begin() == end(). + * + * See LlrbNodeIterator for details + */ + const_iterator begin() const { + return const_iterator::Begin(&root_); + } + + /** + * Returns an iterator pointing past the last entry in the map. + */ + const_iterator end() const { + return const_iterator::End(); + } + private: TreeSortedMap(node_type&& root, const C& comparator) noexcept : util::ComparatorHolder<C>{comparator}, root_{std::move(root)} { |