16#include "pw_containers/internal/aa_tree.h"
17#include "pw_containers/internal/aa_tree_item.h"
58 using GenericIterator = containers::internal::GenericAATree::iterator;
60 using Compare =
typename Tree::Compare;
61 using GetKey =
typename Tree::GetKey;
65 using Item =
typename Tree::Item;
69 using size_type = std::size_t;
70 using difference_type = std::ptrdiff_t;
71 using key_compare = Compare;
72 using value_compare = Compare;
73 using reference = value_type&;
74 using const_reference =
const value_type&;
75 using pointer = value_type*;
76 using const_pointer =
const value_type*;
79 class iterator :
public containers::internal::AATreeIterator<T> {
84 using Base = containers::internal::AATreeIterator<T>;
86 constexpr explicit iterator(GenericIterator iter) : Base(iter) {}
90 :
public containers::internal::AATreeIterator<std::add_const_t<T>> {
95 using Base = containers::internal::AATreeIterator<std::add_const_t<T>>;
97 constexpr explicit const_iterator(GenericIterator iter) : Base(iter) {}
100 using reverse_iterator = std::reverse_iterator<iterator>;
101 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
113 template <
typename Comparator>
116 std::forward<Comparator>(compare),
117 [](const T& t) -> const T& {
return t; }) {
125 template <
typename Iterator,
typename... Functors>
128 tree_.
insert(first, last);
133 template <
typename... Functors>
136 items.begin(), items.end(), std::forward<Functors>(functors)...) {}
140 iterator begin() noexcept {
return iterator(tree_.
begin()); }
141 const_iterator begin() const noexcept {
142 return const_iterator(tree_.
begin());
144 const_iterator cbegin() const noexcept {
return begin(); }
146 iterator end() noexcept {
return iterator(tree_.
end()); }
147 const_iterator end() const noexcept {
return const_iterator(tree_.
end()); }
148 const_iterator cend() const noexcept {
return end(); }
150 reverse_iterator rbegin() noexcept {
return reverse_iterator(end()); }
151 const_reverse_iterator rbegin() const noexcept {
152 return const_reverse_iterator(end());
154 const_reverse_iterator crbegin() const noexcept {
return rbegin(); }
156 reverse_iterator rend() noexcept {
return reverse_iterator(begin()); }
157 const_reverse_iterator rend() const noexcept {
158 return const_reverse_iterator(begin());
160 const_reverse_iterator crend() const noexcept {
return rend(); }
165 [[nodiscard]]
bool empty() const noexcept {
return tree_.
empty(); }
185 iterator
insert(iterator, T& item) {
187 return iterator(
insert(item));
190 template <
class Iterator>
191 void insert(Iterator first, Iterator last) {
192 tree_.
insert(first, last);
195 void insert(std::initializer_list<T*> ilist) {
196 tree_.
insert(ilist.begin(), ilist.end());
205 iterator
erase(iterator first, iterator last) {
217 template <
typename MapType>
219 tree_.
merge(other.tree_);
223 size_t count(
const T& item)
const {
return tree_.
count(item); }
229 const_iterator
find(
const T& item)
const {
230 return const_iterator(tree_.
find(item));
240 std::pair<const_iterator, const_iterator>
equal_range(
const T& item)
const {
242 return std::make_pair(const_iterator(result.first),
243 const_iterator(result.second));
269 static constexpr void CheckItemType() {
270 using ItemBase = containers::internal::AATreeItem;
271 using IntrusiveItemType =
272 typename containers::internal::IntrusiveItem<ItemBase, T>::Type;
274 std::is_base_of<IntrusiveItemType, T>(),
275 "IntrusiveMultiSet items must be derived from "
276 "IntrusiveMultiSet<T>::Item, where T is the item or one of its "
282 friend class IntrusiveSet;
Definition: intrusive_multiset.h:90
Definition: intrusive_multiset.h:79
Definition: intrusive_multiset.h:56
void swap(IntrusiveMultiSet< T > &other)
Exchanges this multiset's items with the other multiset's items.
Definition: intrusive_multiset.h:212
iterator erase(iterator pos)
Definition: intrusive_multiset.h:203
constexpr IntrusiveMultiSet()
Constructs an empty set of items.
Definition: intrusive_multiset.h:104
IntrusiveMultiSet(std::initializer_list< T * > items, Functors &&... functors)
Definition: intrusive_multiset.h:134
constexpr IntrusiveMultiSet(Comparator &&compare)
Definition: intrusive_multiset.h:114
size_t size() const
Returns the number of items in the multiset.
Definition: intrusive_multiset.h:168
bool empty() const noexcept
Returns whether the multiset has zero items or not.
Definition: intrusive_multiset.h:165
iterator upper_bound(const T &item)
Definition: intrusive_multiset.h:259
void clear()
Definition: intrusive_multiset.h:180
iterator find(const T &item)
Definition: intrusive_multiset.h:227
typename Tree::Item Item
IntrusiveMultiSet items must derive from Item.
Definition: intrusive_multiset.h:65
iterator lower_bound(const T &item)
Definition: intrusive_multiset.h:249
std::pair< iterator, iterator > equal_range(const T &item)
Definition: intrusive_multiset.h:236
constexpr size_t max_size() const noexcept
Definition: intrusive_multiset.h:173
void merge(MapType &other)
Definition: intrusive_multiset.h:218
size_t count(const T &item) const
Returns the number of items in the multimap with the given key.
Definition: intrusive_multiset.h:223
iterator insert(T &item)
Adds the given item to the multiset.
Definition: intrusive_multiset.h:183
IntrusiveMultiSet(Iterator first, Iterator last, Functors &&... functors)
Definition: intrusive_multiset.h:126
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