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>;
128 template <
typename Comparator>
131 [](const T& t) {
return t.key(); }) {}
139 template <
typename Comparator,
typename KeyRetriever>
142 std::forward<Comparator>(compare),
143 std::forward<KeyRetriever>(get_key)) {
151 template <
typename Iterator,
typename... Functors>
154 tree_.
insert(first, last);
159 template <
typename... Functors>
162 items.begin(), items.end(), std::forward<Functors>(functors)...) {}
166 iterator begin() noexcept {
return iterator(tree_.
begin()); }
167 const_iterator begin() const noexcept {
168 return const_iterator(tree_.
begin());
170 const_iterator cbegin() const noexcept {
return begin(); }
172 iterator end() noexcept {
return iterator(tree_.
end()); }
173 const_iterator end() const noexcept {
return const_iterator(tree_.
end()); }
174 const_iterator cend() const noexcept {
return end(); }
176 reverse_iterator rbegin() noexcept {
return reverse_iterator(end()); }
177 const_reverse_iterator rbegin() const noexcept {
178 return const_reverse_iterator(end());
180 const_reverse_iterator crbegin() const noexcept {
return rbegin(); }
182 reverse_iterator rend() noexcept {
return reverse_iterator(begin()); }
183 const_reverse_iterator rend() const noexcept {
184 return const_reverse_iterator(begin());
186 const_reverse_iterator crend() const noexcept {
return rend(); }
191 [[nodiscard]]
bool empty() const noexcept {
return tree_.
empty(); }
211 iterator
insert(iterator, T& item) {
213 return iterator(
insert(item));
216 template <
class Iterator>
217 void insert(Iterator first, Iterator last) {
218 tree_.
insert(first, last);
221 void insert(std::initializer_list<T*> ilist) {
222 tree_.
insert(ilist.begin(), ilist.end());
231 iterator
erase(iterator pos) {
return iterator(tree_.
erase_one(*pos)); }
233 iterator
erase(iterator first, iterator last) {
243 template <
typename MapType>
245 tree_.
merge(other.tree_);
249 size_t count(
const Key& key)
const {
return tree_.
count(key); }
255 const_iterator
find(
const Key& key)
const {
256 return const_iterator(tree_.
find(key));
266 std::pair<const_iterator, const_iterator>
equal_range(
const Key& key)
const {
268 return std::make_pair(const_iterator(result.first),
269 const_iterator(result.second));
295 static constexpr void CheckItemType() {
296 using ItemBase = containers::internal::AATreeItem;
297 using IntrusiveItemType =
298 typename containers::internal::IntrusiveItem<ItemBase, T>::Type;
300 std::is_base_of<IntrusiveItemType, T>(),
301 "IntrusiveMultiMap items must be derived from "
302 "IntrusiveMultiMap<Key, T>::Item, where T is the item or one of its "
307 template <
typename,
typename>
308 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:140
iterator insert(T &item)
Adds the given item to the multimap.
Definition: intrusive_multimap.h:209
iterator upper_bound(const Key &key)
Definition: intrusive_multimap.h:285
std::pair< iterator, iterator > equal_range(const Key &key)
Definition: intrusive_multimap.h:262
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:244
iterator lower_bound(const Key &key)
Definition: intrusive_multimap.h:275
IntrusiveMultiMap(Iterator first, Iterator last, Functors &&... functors)
Definition: intrusive_multimap.h:152
IntrusiveMultiMap(std::initializer_list< T * > items, Functors &&... functors)
Definition: intrusive_multimap.h:160
void swap(IntrusiveMultiMap< Key, T > &other)
Exchanges this multimap's items with the other multimap's items.
Definition: intrusive_multimap.h:240
iterator find(const Key &key)
Definition: intrusive_multimap.h:253
size_t count(const Key &key) const
Returns the number of items in the multimap with the given key.
Definition: intrusive_multimap.h:249
size_t size() const
Returns the number of items in the multimap.
Definition: intrusive_multimap.h:194
bool empty() const noexcept
Returns whether the multimap has zero items or not.
Definition: intrusive_multimap.h:191
iterator erase(T &item)
Definition: intrusive_multimap.h:229
void clear()
Definition: intrusive_multimap.h:206
constexpr IntrusiveMultiMap(Comparator compare)
Definition: intrusive_multimap.h:129
constexpr size_t max_size() const noexcept
Definition: intrusive_multimap.h:199
iterator lower_bound(Key key)
Definition: aa_tree.h:400
constexpr iterator begin() noexcept
Returns a pointer to the first item, if any.
Definition: aa_tree.h:62
constexpr size_t max_size() const noexcept
Definition: aa_tree.h:83
std::pair< iterator, iterator > equal_range(Key key)
Definition: aa_tree.h:395
iterator upper_bound(Key key)
Definition: aa_tree.h:424
void merge(KeyedAATree< K > &other)
Definition: aa_tree.h:370
iterator find(Key key)
Definition: aa_tree.h:385
std::pair< iterator, bool > insert(AATreeItem &item)
Definition: aa_tree.h:306
size_t erase_all(Key key)
Definition: aa_tree.h:359
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:75
size_t count(Key key)
Definition: aa_tree.h:380
constexpr iterator end() noexcept
Returns a pointer to the last item, if any.
Definition: aa_tree.h:67
The Pigweed namespace.
Definition: alignment.h:27