16#include "pw_containers/internal/aa_tree.h"
17#include "pw_containers/internal/aa_tree_item.h"
64template <
typename Key,
typename T>
67 using GenericIterator = containers::internal::GenericAATree::iterator;
69 using Compare =
typename Tree::Compare;
70 using GetKey =
typename Tree::GetKey;
77 using Item =
typename Tree::Item;
78 using Pair =
typename Tree::Pair;
81 using mapped_type = std::remove_cv_t<T>;
82 using value_type =
Item;
83 using size_type = std::size_t;
84 using difference_type = std::ptrdiff_t;
85 using key_compare = Compare;
86 using reference = value_type&;
87 using const_reference =
const value_type&;
88 using pointer = value_type*;
89 using const_pointer =
const value_type*;
91 class iterator :
public containers::internal::AATreeIterator<T> {
96 using Base = containers::internal::AATreeIterator<T>;
98 constexpr explicit iterator(GenericIterator iter) : Base(iter) {}
102 :
public containers::internal::AATreeIterator<std::add_const_t<T>> {
107 using Base = containers::internal::AATreeIterator<std::add_const_t<T>>;
109 constexpr explicit const_iterator(GenericIterator iter) : Base(iter) {}
112 using reverse_iterator = std::reverse_iterator<iterator>;
113 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
126 template <
typename Comparator>
129 [](const T& t) {
return t.key(); }) {}
137 template <
typename Comparator,
typename KeyRetriever>
140 std::forward<Comparator>(compare),
141 std::forward<KeyRetriever>(get_key)) {
149 template <
typename Iterator,
typename... Functors>
152 tree_.
insert(first, last);
157 template <
typename... Functors>
160 items.begin(), items.end(), std::forward<Functors>(functors)...) {}
164 iterator begin() noexcept {
return iterator(tree_.
begin()); }
165 const_iterator begin() const noexcept {
166 return const_iterator(tree_.
begin());
168 const_iterator cbegin() const noexcept {
return begin(); }
170 iterator end() noexcept {
return iterator(tree_.
end()); }
171 const_iterator end() const noexcept {
return const_iterator(tree_.
end()); }
172 const_iterator cend() const noexcept {
return end(); }
174 reverse_iterator rbegin() noexcept {
return reverse_iterator(end()); }
175 const_reverse_iterator rbegin() const noexcept {
176 return const_reverse_iterator(end());
178 const_reverse_iterator crbegin() const noexcept {
return rbegin(); }
180 reverse_iterator rend() noexcept {
return reverse_iterator(begin()); }
181 const_reverse_iterator rend() const noexcept {
182 return const_reverse_iterator(begin());
184 const_reverse_iterator crend() const noexcept {
return rend(); }
189 [[nodiscard]]
bool empty() const noexcept {
return tree_.
empty(); }
209 iterator
insert(iterator, T& item) {
211 return iterator(
insert(item));
214 template <
class Iterator>
215 void insert(Iterator first, Iterator last) {
216 tree_.
insert(first, last);
219 void insert(std::initializer_list<T*> ilist) {
220 tree_.
insert(ilist.begin(), ilist.end());
229 iterator
erase(iterator pos) {
return iterator(tree_.
erase_one(*pos)); }
231 iterator
erase(iterator first, iterator last) {
241 template <
typename MapType>
243 tree_.
merge(other.tree_);
247 size_t count(
const Key& key)
const {
return tree_.
count(key); }
253 const_iterator
find(
const Key& key)
const {
254 return const_iterator(tree_.
find(key));
264 std::pair<const_iterator, const_iterator>
equal_range(
const Key& key)
const {
266 return std::make_pair(const_iterator(result.first),
267 const_iterator(result.second));
293 static constexpr void CheckItemType() {
294 using ItemBase = containers::internal::AATreeItem;
295 using IntrusiveItemType =
296 typename containers::internal::IntrusiveItem<ItemBase, T>::Type;
298 std::is_base_of<IntrusiveItemType, T>(),
299 "IntrusiveMultiMap items must be derived from "
300 "IntrusiveMultiMap<Key, T>::Item, where T is the item or one of its "
305 template <
typename,
typename>
306 friend class IntrusiveMap;
Definition: intrusive_multimap.h:102
Definition: intrusive_multimap.h:91
Definition: intrusive_multimap.h:65
iterator erase_range(AATreeItem &first, AATreeItem &last)
iterator erase_one(AATreeItem &item)
constexpr IntrusiveMultiMap(Comparator &&compare, KeyRetriever &&get_key)
Definition: intrusive_multimap.h:138
iterator insert(T &item)
Adds the given item to the multimap.
Definition: intrusive_multimap.h:207
iterator upper_bound(const Key &key)
Definition: intrusive_multimap.h:283
std::pair< iterator, iterator > equal_range(const Key &key)
Definition: intrusive_multimap.h:260
typename Tree::Item Item
Definition: intrusive_multimap.h:77
constexpr IntrusiveMultiMap()
Constructs an empty map of items.
Definition: intrusive_multimap.h:116
void merge(MapType &other)
Splices items from the other map into this one.
Definition: intrusive_multimap.h:242
iterator lower_bound(const Key &key)
Definition: intrusive_multimap.h:273
IntrusiveMultiMap(Iterator first, Iterator last, Functors &&... functors)
Definition: intrusive_multimap.h:150
IntrusiveMultiMap(std::initializer_list< T * > items, Functors &&... functors)
Definition: intrusive_multimap.h:158
void swap(IntrusiveMultiMap< Key, T > &other)
Exchanges this multimap's items with the other multimap's items.
Definition: intrusive_multimap.h:238
iterator find(const Key &key)
Definition: intrusive_multimap.h:251
size_t count(const Key &key) const
Returns the number of items in the multimap with the given key.
Definition: intrusive_multimap.h:247
size_t size() const
Returns the number of items in the multimap.
Definition: intrusive_multimap.h:192
bool empty() const noexcept
Returns whether the multimap has zero items or not.
Definition: intrusive_multimap.h:189
iterator erase(T &item)
Definition: intrusive_multimap.h:227
void clear()
Definition: intrusive_multimap.h:204
constexpr IntrusiveMultiMap(Comparator compare)
Definition: intrusive_multimap.h:127
constexpr size_t max_size() const noexcept
Definition: intrusive_multimap.h:197
iterator lower_bound(Key key)
Definition: aa_tree.h:408
constexpr iterator begin() noexcept
Returns a pointer to the first item, if any.
Definition: aa_tree.h:63
constexpr size_t max_size() const noexcept
Definition: aa_tree.h:84
std::pair< iterator, iterator > equal_range(Key key)
Definition: aa_tree.h:403
iterator upper_bound(Key key)
Definition: aa_tree.h:432
void merge(KeyedAATree< K > &other)
Definition: aa_tree.h:378
iterator find(Key key)
Definition: aa_tree.h:393
std::pair< iterator, bool > insert(AATreeItem &item)
Definition: aa_tree.h:314
size_t erase_all(Key key)
Definition: aa_tree.h:367
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:76
size_t count(Key key)
Definition: aa_tree.h:388
constexpr iterator end() noexcept
Returns a pointer to the last item, if any.
Definition: aa_tree.h:68
The Pigweed namespace.
Definition: alignment.h:27