16#include "pw_containers/internal/aa_tree.h"
17#include "pw_containers/internal/aa_tree_item.h"
59template <
typename Key,
typename T>
62 using GenericIterator = containers::internal::GenericAATree::iterator;
64 using Compare =
typename Tree::Compare;
65 using GetKey =
typename Tree::GetKey;
72 using Item =
typename Tree::Item;
73 using Pair =
typename Tree::Pair;
76 using mapped_type = std::remove_cv_t<T>;
77 using value_type =
Item;
78 using size_type = std::size_t;
79 using difference_type = std::ptrdiff_t;
80 using key_compare = Compare;
81 using reference = value_type&;
82 using const_reference =
const value_type&;
83 using pointer = value_type*;
84 using const_pointer =
const value_type*;
86 class iterator :
public containers::internal::AATreeIterator<T> {
91 using Base = containers::internal::AATreeIterator<T>;
93 constexpr explicit iterator(GenericIterator iter) : Base(iter) {}
97 :
public containers::internal::AATreeIterator<std::add_const_t<T>> {
102 using Base = containers::internal::AATreeIterator<std::add_const_t<T>>;
104 constexpr explicit const_iterator(GenericIterator iter) : Base(iter) {}
107 using reverse_iterator = std::reverse_iterator<iterator>;
108 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
123 template <
typename Comparator>
126 [](const T& t) {
return t.key(); }) {}
134 template <
typename Comparator,
typename KeyRetriever>
137 std::forward<Comparator>(compare),
138 std::forward<KeyRetriever>(get_key)) {
146 template <
typename Iterator,
typename... Functors>
149 tree_.
insert(first, last);
154 template <
typename... Functors>
157 items.begin(), items.end(), std::forward<Functors>(functors)...) {}
161 iterator begin() noexcept {
return iterator(tree_.
begin()); }
162 const_iterator begin() const noexcept {
163 return const_iterator(tree_.
begin());
165 const_iterator cbegin() const noexcept {
return begin(); }
167 iterator end() noexcept {
return iterator(tree_.
end()); }
168 const_iterator end() const noexcept {
return const_iterator(tree_.
end()); }
169 const_iterator cend() const noexcept {
return end(); }
171 reverse_iterator rbegin() noexcept {
return reverse_iterator(end()); }
172 const_reverse_iterator rbegin() const noexcept {
173 return const_reverse_iterator(end());
175 const_reverse_iterator crbegin() const noexcept {
return rbegin(); }
177 reverse_iterator rend() noexcept {
return reverse_iterator(begin()); }
178 const_reverse_iterator rend() const noexcept {
179 return const_reverse_iterator(begin());
181 const_reverse_iterator crend() const noexcept {
return rend(); }
186 [[nodiscard]]
bool empty() const noexcept {
return tree_.
empty(); }
206 iterator
insert(iterator, T& item) {
208 return iterator(
insert(item));
211 template <
class Iterator>
212 void insert(Iterator first, Iterator last) {
213 tree_.
insert(first, last);
216 void insert(std::initializer_list<T*> ilist) {
217 tree_.
insert(ilist.begin(), ilist.end());
226 iterator
erase(iterator pos) {
return iterator(tree_.
erase_one(*pos)); }
228 iterator
erase(iterator first, iterator last) {
238 template <
typename MapType>
240 tree_.
merge(other.tree_);
244 size_t count(
const Key& key)
const {
return tree_.
count(key); }
250 const_iterator
find(
const Key& key)
const {
251 return const_iterator(tree_.
find(key));
261 std::pair<const_iterator, const_iterator>
equal_range(
const Key& key)
const {
263 return std::make_pair(const_iterator(result.first),
264 const_iterator(result.second));
290 static constexpr void CheckItemType() {
291 using ItemBase = containers::internal::AATreeItem;
292 using IntrusiveItemType =
293 typename containers::internal::IntrusiveItem<ItemBase, T>::Type;
295 std::is_base_of<IntrusiveItemType, T>(),
296 "IntrusiveMultiMap items must be derived from "
297 "IntrusiveMultiMap<Key, T>::Item, where T is the item or one of its "
302 template <
typename,
typename>
303 friend class IntrusiveMap;
Definition: intrusive_multimap.h:97
Definition: intrusive_multimap.h:86
Definition: intrusive_multimap.h:60
constexpr IntrusiveMultiMap(Comparator &&compare, KeyRetriever &&get_key)
Definition: intrusive_multimap.h:135
iterator insert(T &item)
Adds the given item to the multimap.
Definition: intrusive_multimap.h:204
iterator upper_bound(const Key &key)
Definition: intrusive_multimap.h:280
constexpr IntrusiveMultiMap(Comparator &&compare)
Definition: intrusive_multimap.h:124
std::pair< iterator, iterator > equal_range(const Key &key)
Definition: intrusive_multimap.h:257
typename Tree::Item Item
Definition: intrusive_multimap.h:72
constexpr IntrusiveMultiMap()
Constructs an empty map of items.
Definition: intrusive_multimap.h:111
void merge(MapType &other)
Splices items from the other map into this one.
Definition: intrusive_multimap.h:239
iterator lower_bound(const Key &key)
Definition: intrusive_multimap.h:270
IntrusiveMultiMap(Iterator first, Iterator last, Functors &&... functors)
Definition: intrusive_multimap.h:147
IntrusiveMultiMap(std::initializer_list< T * > items, Functors &&... functors)
Definition: intrusive_multimap.h:155
void swap(IntrusiveMultiMap< Key, T > &other)
Exchanges this multimap's items with the other multimap's items.
Definition: intrusive_multimap.h:235
iterator find(const Key &key)
Definition: intrusive_multimap.h:248
size_t count(const Key &key) const
Returns the number of items in the multimap with the given key.
Definition: intrusive_multimap.h:244
size_t size() const
Returns the number of items in the multimap.
Definition: intrusive_multimap.h:189
bool empty() const noexcept
Returns whether the multimap has zero items or not.
Definition: intrusive_multimap.h:186
iterator erase(T &item)
Definition: intrusive_multimap.h:224
void clear()
Definition: intrusive_multimap.h:201
constexpr size_t max_size() const noexcept
Definition: intrusive_multimap.h:194
iterator erase_range(AATreeItem &first, AATreeItem &last)
iterator find(Key key)
Definition: aa_tree.h:351
std::pair< iterator, bool > insert(AATreeItem &item)
Definition: aa_tree.h:272
size_t erase_all(Key key)
Definition: aa_tree.h:325
iterator upper_bound(Key key)
Definition: aa_tree.h:390
iterator erase_one(AATreeItem &item)
std::pair< iterator, iterator > equal_range(Key key)
Definition: aa_tree.h:361
iterator lower_bound(Key key)
Definition: aa_tree.h:366
void merge(AATree< K, V > &other)
Definition: aa_tree.h:336
size_t count(Key key)
Definition: aa_tree.h:346
constexpr iterator begin() noexcept
Returns a pointer to the first item, if any.
Definition: aa_tree.h:60
constexpr size_t max_size() const noexcept
Definition: aa_tree.h:81
void swap(GenericAATree &other)
Exchanges this tree's items with the other tree's items.
size_t size() const
Returns the number of items in the tree.
constexpr bool empty() const
Returns whether the tree has zero items or not.
Definition: aa_tree.h:73
constexpr iterator end() noexcept
Returns a pointer to the last item, if any.
Definition: aa_tree.h:65
Provides basic helpers for reading and writing UTF-8 encoded strings.
Definition: alignment.h:27