aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firestore/core/src/firebase/firestore/immutable/sorted_map.h
diff options
context:
space:
mode:
Diffstat (limited to 'Firestore/core/src/firebase/firestore/immutable/sorted_map.h')
-rw-r--r--Firestore/core/src/firebase/firestore/immutable/sorted_map.h37
1 files changed, 35 insertions, 2 deletions
diff --git a/Firestore/core/src/firebase/firestore/immutable/sorted_map.h b/Firestore/core/src/firebase/firestore/immutable/sorted_map.h
index b7729b3..7c8c832 100644
--- a/Firestore/core/src/firebase/firestore/immutable/sorted_map.h
+++ b/Firestore/core/src/firebase/firestore/immutable/sorted_map.h
@@ -21,6 +21,7 @@
#include "Firestore/core/src/firebase/firestore/immutable/array_sorted_map.h"
#include "Firestore/core/src/firebase/firestore/immutable/sorted_map_base.h"
+#include "Firestore/core/src/firebase/firestore/immutable/sorted_map_iterator.h"
#include "Firestore/core/src/firebase/firestore/immutable/tree_sorted_map.h"
#include "Firestore/core/src/firebase/firestore/util/comparison.h"
@@ -40,6 +41,11 @@ class SortedMap : public impl::SortedMapBase {
using array_type = impl::ArraySortedMap<K, V, C>;
using tree_type = impl::TreeSortedMap<K, V, C>;
+ using const_iterator = impl::SortedMapIterator<
+ value_type,
+ typename impl::FixedArray<value_type>::const_iterator,
+ typename impl::LlrbNode<K, V>::const_iterator>;
+
/**
* Creates an empty SortedMap.
*/
@@ -71,7 +77,7 @@ class SortedMap : public impl::SortedMapBase {
}
}
- SortedMap(SortedMap&& other) : tag_{other.tag_} {
+ SortedMap(SortedMap&& other) noexcept : tag_{other.tag_} {
switch (tag_) {
case Tag::Array:
new (&array_) array_type{std::move(other.array_)};
@@ -110,7 +116,7 @@ class SortedMap : public impl::SortedMapBase {
return *this;
}
- SortedMap& operator=(SortedMap&& other) {
+ SortedMap& operator=(SortedMap&& other) noexcept {
if (tag_ == other.tag_) {
switch (tag_) {
case Tag::Array:
@@ -195,6 +201,33 @@ class SortedMap : public impl::SortedMapBase {
FIREBASE_UNREACHABLE();
}
+ /**
+ * Returns an iterator pointing to the first entry in the map. If there are
+ * no entries in the map, begin() == end().
+ */
+ const_iterator begin() const {
+ switch (tag_) {
+ case Tag::Array:
+ return const_iterator{array_.begin()};
+ case Tag::Tree:
+ return const_iterator{tree_.begin()};
+ }
+ FIREBASE_UNREACHABLE();
+ }
+
+ /**
+ * Returns an iterator pointing past the last entry in the map.
+ */
+ const_iterator end() const {
+ switch (tag_) {
+ case Tag::Array:
+ return const_iterator{array_.end()};
+ case Tag::Tree:
+ return const_iterator{tree_.end()};
+ }
+ FIREBASE_UNREACHABLE();
+ }
+
private:
explicit SortedMap(array_type&& array)
: tag_{Tag::Array}, array_{std::move(array)} {