31#ifndef ETL_INTRUSIVE_LIST_INCLUDED
32#define ETL_INTRUSIVE_LIST_INCLUDED
40#include "static_assert.h"
125 template <
typename TLink>
131 typedef TLink link_type;
138 template <
typename TIterator>
141#if ETL_IS_DEBUG_BUILD
142 intmax_t d = etl::distance(first, last);
151 while (first != last)
153 link_type& link = *first++;
175#if defined(ETL_CHECK_PUSH_POP)
196#if defined(ETL_CHECK_PUSH_POP)
212 link_type* p_next =
p_unlink->etl_next;
423 link_type* result = ETL_NULLPTR;
427 link_type* p_next = link->etl_next;
450 link_type* p_next =
p_first->etl_next;
471 template <
typename TValue,
typename TLink>
477 typedef typename etl::intrusive_list_base<TLink>::link_type link_type;
484 typedef TValue value_type;
485 typedef value_type* pointer;
486 typedef const value_type* const_pointer;
487 typedef value_type& reference;
488 typedef const value_type& const_reference;
489 typedef size_t size_type;
502 : p_value(ETL_NULLPTR)
507 : p_value(
other.p_value)
514 p_value = p_value->etl_next;
522 p_value = p_value->etl_next;
529 p_value = p_value->etl_previous;
537 p_value = p_value->etl_previous;
543 p_value =
other.p_value;
547 reference operator *()
const
550 return *
static_cast<pointer
>(p_value);
554 pointer operator &()
const
556 return static_cast<pointer
>(p_value);
559 pointer operator ->()
const
561 return static_cast<pointer
>(p_value);
566 return lhs.p_value ==
rhs.p_value;
594 : p_value(ETL_NULLPTR)
599 : p_value(
other.p_value)
604 : p_value(
other.p_value)
611 p_value = p_value->etl_next;
619 p_value = p_value->etl_next;
626 p_value = p_value->etl_previous;
634 p_value = p_value->etl_previous;
640 p_value =
other.p_value;
644 const_reference operator *()
const
646 return *
static_cast<const_pointer
>(p_value);
649 const_pointer operator &()
const
651 return static_cast<const_pointer
>(p_value);
654 const_pointer operator ->()
const
656 return static_cast<const_pointer
>(p_value);
661 return lhs.p_value ==
rhs.p_value;
676 const link_type* p_value;
679 typedef typename etl::iterator_traits<iterator>::difference_type difference_type;
700 template <
typename TIterator>
703 this->
assign(first, last);
710 template <
typename...
TLinks>
713 ETL_STATIC_ASSERT((etl::is_base_of_all<link_type, TLinks...>::value),
"Mixed link types");
777 return *
static_cast<pointer
>(this->
get_head());
785 return *
static_cast<const_pointer
>(this->
get_head());
793 return *
static_cast<pointer
>(this->
get_tail());
801 return *
static_cast<const_pointer
>(this->
get_tail());
809 this->
insert_link(position.p_value->link_type::etl_previous, value);
816 template <
typename TIterator>
819 while (first != last)
822 this->
insert_link(*position.p_value->link_type::etl_previous, *first);
859 const link_type*
cp_first = first.p_value;
860 const link_type*
cp_last = last.p_value;
869 if (
p_last == ETL_NULLPTR)
884 return static_cast<node_type*
>(this->
remove_link(
const_cast<node_type*
>(&
node)));
890 node_type*
erase(
const node_type* p_node)
892 return static_cast<node_type*
>(this->
remove_link(
const_cast<node_type*
>(p_node)));
899 template <
typename TIsEqual>
958 template <
typename TCompare>
1069 void remove(const_reference value)
1089 template <
typename TPredicate>
1117 link_type& first = *
other.get_head();
1118 link_type& last = *
other.get_tail();
1125 link_type&
after = *position.p_value;
1141 link_type&
before = *position.p_value->link_type::etl_previous;
1167 link_type& first = *
begin_.p_value;
1168 link_type& last = *
end_.p_value->link_type::etl_previous;
1171 etl::unlink(first, last);
1174 link_type&
before = *position.p_value->link_type::etl_previous;
1191 template <
typename TCompare>
1196#if ETL_IS_DEBUG_BUILD
1266 template <
typename...
TLinks>
1269 TLink* current = &first;
1271 ((current->etl_next = &
links,
static_cast<TLink&
>(
links).etl_previous = current, current = &
links, ++count), ...);
1275#elif ETL_USING_CPP11
1289 template <
typename...
TLinks>
1293 first.etl_next = &next;
1294 next.etl_previous = &first;
const_iterator
Definition intrusive_list.h:588
iterator.
Definition intrusive_list.h:495
Definition intrusive_list.h:127
void disconnect_link(link_type *link)
Remove a link.
Definition intrusive_list.h:350
size_t size() const
Returns the number of elements.
Definition intrusive_list.h:253
link_type * get_tail()
Get the tail link.
Definition intrusive_list.h:375
void insert_link(link_type &previous, link_type &new_link)
Insert a link.
Definition intrusive_list.h:301
~intrusive_list_base()
Destructor.
Definition intrusive_list.h:286
void assign(TIterator first, TIterator last)
Definition intrusive_list.h:139
bool contains_node(const link_type *search_link) const
Definition intrusive_list.h:271
size_t current_size
Counts the number of elements in the list.
Definition intrusive_list.h:281
bool is_link_in_list(const link_type *search_link) const
Tests if the link is in this list.
Definition intrusive_list.h:400
void disconnect_link(link_type &link)
Remove a link.
Definition intrusive_list.h:341
void insert_link(link_type &previous, link_type *new_link)
Insert a link.
Definition intrusive_list.h:321
void pop_back()
Removes a value from the back of the intrusive_list.
Definition intrusive_list.h:194
link_type * get_head()
Get the head link.
Definition intrusive_list.h:359
bool empty() const
Returns true if the list has no elements.
Definition intrusive_list.h:245
link_type * remove_link_range(link_type *p_first, link_type *p_last)
Removes a range of links.
Definition intrusive_list.h:443
void initialise()
Initialise the intrusive_list.
Definition intrusive_list.h:391
void reverse()
Reverses the list.
Definition intrusive_list.h:223
void insert_link(link_type *previous, link_type *new_link)
Insert a link.
Definition intrusive_list.h:331
const link_type * get_head() const
Get the head link.
Definition intrusive_list.h:367
link_type terminal_link
The link that acts as the intrusive_list start & end.
Definition intrusive_list.h:279
void insert_link(link_type *previous, link_type &new_link)
Insert a link.
Definition intrusive_list.h:311
void clear()
Clears the intrusive_list.
Definition intrusive_list.h:205
void push_front(link_type &value)
Pushes a value to the front of the intrusive_list.
Definition intrusive_list.h:163
void push_back(link_type &value)
Pushes a value to the back of the intrusive_list.
Definition intrusive_list.h:184
void pop_front()
Removes a value from the front of the intrusive_list.
Definition intrusive_list.h:173
bool contains_node(const link_type &search_link) const
Definition intrusive_list.h:262
const link_type * get_tail() const
Get the tail link.
Definition intrusive_list.h:383
bool is_trivial_list() const
Is the intrusive_list a trivial length?
Definition intrusive_list.h:293
link_type * remove_link(link_type *link)
Definition intrusive_list.h:421
Definition intrusive_list.h:70
Definition intrusive_list.h:56
Definition intrusive_list.h:84
Definition intrusive_list.h:98
Definition intrusive_list.h:112
Definition intrusive_list.h:473
~intrusive_list()
Destructor.
Definition intrusive_list.h:692
const_iterator end() const
Gets the end of the intrusive_list.
Definition intrusive_list.h:759
reference back()
Gets a reference to the last element.
Definition intrusive_list.h:791
iterator begin()
Gets the beginning of the intrusive_list.
Definition intrusive_list.h:727
node_type * erase(const node_type &node)
Erases the specified node.
Definition intrusive_list.h:882
void unique(TIsEqual isEqual)
Definition intrusive_list.h:900
const_iterator begin() const
Gets the beginning of the intrusive_list.
Definition intrusive_list.h:735
void splice(iterator position, list_type &other)
Splice another list into this one.
Definition intrusive_list.h:1110
iterator erase(const_iterator position)
Erases the value at the specified position.
Definition intrusive_list.h:843
void splice(iterator position, list_type &other, iterator begin_, iterator end_)
Splice a range of elements from another list into this one.
Definition intrusive_list.h:1156
reference front()
Gets a reference to the first element.
Definition intrusive_list.h:775
void insert(const_iterator position, TIterator first, TIterator last)
Inserts a range of values to the intrusive_list after the specified position.
Definition intrusive_list.h:817
void merge(list_type &other, TCompare compare)
Merge another list into this one. Both lists should be sorted.
Definition intrusive_list.h:1192
bool contains(const_reference value) const
Definition intrusive_list.h:1243
void sort(TCompare compare)
Definition intrusive_list.h:959
void splice(iterator position, list_type &other, iterator isource)
Splice an element from another list into this one.
Definition intrusive_list.h:1139
intrusive_list()
Constructor.
Definition intrusive_list.h:684
iterator erase(const_iterator first, const_iterator last)
Definition intrusive_list.h:857
const_iterator cend() const
Gets the end of the intrusive_list.
Definition intrusive_list.h:767
iterator erase(iterator position)
Erases the value at the specified position.
Definition intrusive_list.h:830
const_iterator cbegin() const
Gets the beginning of the intrusive_list.
Definition intrusive_list.h:743
void remove_if(TPredicate predicate)
Removes according to a predicate.
Definition intrusive_list.h:1090
void sort()
Sort using in-place merge sort algorithm.
Definition intrusive_list.h:928
iterator insert(const_iterator position, value_type &value)
Inserts a value to the intrusive_list before the specified position.
Definition intrusive_list.h:807
const_reference front() const
Gets a const reference to the first element.
Definition intrusive_list.h:783
iterator end()
Gets the end of the intrusive_list.
Definition intrusive_list.h:751
node_type * erase(const node_type *p_node)
Erases the specified node.
Definition intrusive_list.h:890
intrusive_list(TIterator first, TIterator last, typename etl::enable_if<!etl::is_integral< TIterator >::value, int >::type=0)
Constructor from range.
Definition intrusive_list.h:701
const_reference back() const
Gets a const reference to the last element.
Definition intrusive_list.h:799
void merge(list_type &other)
Merge another list into this one. Both lists should be sorted.
Definition intrusive_list.h:1183
ETL_CONSTEXPR14 bool operator==(const etl::expected< TValue, TError > &lhs, const etl::expected< TValue2, TError2 > &rhs)
Equivalence operators.
Definition expected.h:974
ETL_NODISCARD ETL_CONSTEXPR14 bool is_sorted(TIterator begin, TIterator end)
Definition algorithm.h:1709
#define ETL_ASSERT(b, e)
Definition error_handler.h:356
Definition exception.h:47
enable_if
Definition type_traits_generator.h:1230
is_integral
Definition type_traits_generator.h:1040
bitset_ext
Definition absolute.h:38
ETL_NODISCARD ETL_CONSTEXPR14 T round_half_even_unscaled(T value) ETL_NOEXCEPT
Definition scaled_rounding.h:314
iterator
Definition iterator.h:399
Definition functional.h:170