20#include "pw_containers/internal/intrusive_item.h"
21#include "pw_containers/internal/intrusive_list_item.h"
23namespace pw::containers::internal {
37template <
typename Item>
40 static_assert(std::is_same_v<Item, IntrusiveForwardListItem> ||
41 std::is_same_v<Item, IntrusiveListItem>);
45 template <
typename Iterator>
56 head_.replace(other.head_);
62 head_.replace(other.head_);
68 template <
typename Iterator>
69 void assign(Iterator first, Iterator last) {
78 constexpr const Item*
before_begin() const noexcept {
return &head_; }
81 constexpr Item*
begin() noexcept {
return head_.next_; }
82 constexpr const Item*
begin() const noexcept {
return head_.next_; }
88 constexpr Item*
end() noexcept {
return &head_; }
89 constexpr const Item*
end() const noexcept {
return &head_; }
93 bool empty() const noexcept {
return begin() ==
end(); }
99 return std::numeric_limits<ptrdiff_t>::max();
133 CheckIntrusiveItemIsUncontained(item.unlisted());
134 item.next_ = prev->next_;
135 item.set_previous(prev);
137 item.next_->set_previous(&item);
146 template <
typename Iterator>
148 for (Iterator it = first; it != last; ++it) {
161 item->next_->unlist(item);
167 while (first->next_ != last) {
178 head_.replace(other.head_);
179 other.head_.replace(tmp);
189 template <
typename Compare>
192 Item* item =
begin();
193 Item* other_item = other.
begin();
194 while (!other.empty()) {
195 if (item ==
end() || !comp(*item, *other_item)) {
196 Item* tmp = other_item;
213 if (first == last && first != &other.head_) {
216 Item* first_next = first->next_;
217 if (first_next == last) {
220 Item* last_prev = last->previous();
221 Item* pos_next = pos->next_;
224 last->set_previous(first);
226 pos->next_ = first_next;
227 first_next->set_previous(pos);
229 pos_next->set_previous(last_prev);
230 last_prev->next_ = pos_next;
236 bool remove(
const Item& item_to_remove) {
238 [&item_to_remove](
const Item& item) ->
bool {
239 return &item_to_remove == &item;
250 template <
typename UnaryPredicate>
252 size_t max = std::numeric_limits<size_t>::max()) {
256 Item* item = prev->next_;
263 if (removed == max) {
277 Item* item =
begin();
289 template <
typename BinaryPredicate>
295 Item* prev =
begin();
297 Item* item = prev->next_;
301 if (pred(*prev, *item)) {
316 template <
typename Compare>
320 for (Item* item =
begin(); item !=
end(); item = item->next_) {
345 template <
typename Iterator>
346 static Item* FromIterator(Iterator& it) {
347 if constexpr (std::is_pointer<std::remove_reference_t<
decltype(*it)>>()) {
Definition: intrusive_list.h:38
static Item * erase_after(Item *first, Item *last)
Removes the range of items exclusively between first and last.
Definition: intrusive_list.h:166
size_t unique(BinaryPredicate pred)
Definition: intrusive_list.h:290
void push_front(Item &item)
Inserts an element at the beginning of the list.
Definition: intrusive_list.h:118
Item * before_end() noexcept
Returns a pointer to the last item.
Definition: intrusive_list.h:85
void sort(Compare comp)
Definition: intrusive_list.h:317
constexpr size_t max_size() const noexcept
Definition: intrusive_list.h:98
size_t remove_if(UnaryPredicate pred, size_t max=std::numeric_limits< size_t >::max())
Definition: intrusive_list.h:251
static Item * insert_after(Item *prev, Iterator first, Iterator last)
Definition: intrusive_list.h:147
void reverse()
Reverses the order of items in the list.
Definition: intrusive_list.h:274
void pop_front()
Removes the first item in the list. The list must not be empty.
Definition: intrusive_list.h:121
constexpr Item * before_begin() noexcept
Returns a pointer to the sentinel item.
Definition: intrusive_list.h:77
constexpr Item * begin() noexcept
Returns a pointer to the first item.
Definition: intrusive_list.h:81
void merge(GenericIntrusiveList< Item > &other, Compare comp)
Definition: intrusive_list.h:190
void pop_back()
Removes the last item in the list. The list must not be empty.
Definition: intrusive_list.h:115
static Item * insert_after(Item *prev, Item &item)
Definition: intrusive_list.h:132
static void splice_after(Item *pos, GenericIntrusiveList< Item > &other, Item *first, Item *last)
Definition: intrusive_list.h:208
void clear()
Removes all items from the list.
Definition: intrusive_list.h:105
void push_back(Item &item)
Inserts an element at the end of the list.
Definition: intrusive_list.h:112
constexpr Item * end() noexcept
Returns a pointer to the sentinel item.
Definition: intrusive_list.h:88
static Item * erase_after(Item *item)
Definition: intrusive_list.h:160