31 #ifndef ETL_INTRUSIVE_FORWARD_LIST_INCLUDED
32 #define ETL_INTRUSIVE_FORWARD_LIST_INCLUDED
67 :
exception(reason_, file_name_, line_number_)
132 template <
typename TLink>
138 typedef TLink link_type;
152 template <
typename TIterator>
153 void assign(TIterator first, TIterator last)
155 #if defined(ETL_DEBUG)
156 intmax_t d = etl::distance(first, last);
165 while (first != last)
167 link_type& link = *first++;
168 etl::link_splice<link_type>(p_last_link, link);
187 #if defined(ETL_CHECK_PUSH_POP)
203 link_type* first = ETL_NULLPTR;
207 while (track != NULL)
209 track = track->etl_next;
210 second->etl_next = first;
252 return (
start_link.link_type::etl_next == ETL_NULLPTR) || (
start_link.link_type::etl_next->etl_next == ETL_NULLPTR);
261 etl::link_splice<link_type>(position, link);
270 link_type* p_next = link.etl_next;
272 if (p_next != ETL_NULLPTR)
274 etl::unlink_after<link_type>(link);
310 template <
typename TValue,
typename TLink = etl::forward_link<0> >
316 typedef typename etl::intrusive_forward_list_base<TLink>::link_type link_type;
319 typedef TValue value_type;
320 typedef value_type* pointer;
321 typedef const value_type* const_pointer;
322 typedef value_type& reference;
323 typedef const value_type& const_reference;
324 typedef size_t size_type;
339 : p_value(ETL_NULLPTR)
349 : p_value(other.p_value)
356 p_value =
static_cast<value_type*
>(p_value->link_type::etl_next);
364 p_value =
static_cast<value_type*
>(p_value->link_type::etl_next);
370 p_value = other.p_value;
374 reference operator *()
379 const_reference operator *()
const
394 pointer operator ->()
399 const_pointer operator ->()
const
406 return lhs.p_value == rhs.p_value;
411 return !(lhs == rhs);
429 : p_value(ETL_NULLPTR)
439 : p_value(other.p_value)
444 : p_value(other.p_value)
451 p_value =
static_cast<value_type*
>(p_value->link_type::etl_next);
459 p_value =
static_cast<value_type*
>(p_value->link_type::etl_next);
465 p_value = other.p_value;
469 const_reference operator *()
const
479 const_pointer operator ->()
const
486 return lhs.p_value == rhs.p_value;
491 return !(lhs == rhs);
496 const value_type* p_value;
499 typedef typename etl::iterator_traits<iterator>::difference_type difference_type;
520 template <
typename TIterator>
523 this->
assign(first, last);
595 return static_cast<value_type&
>(*(this->
get_head()));
603 return static_cast<const value_type&
>(*(this->
get_head()));
618 template <
typename TIterator>
621 while (first != last)
653 if (first !=
end() && (first != last))
657 link_type* p_first = first.p_value;
658 link_type* p_last = last.p_value;
659 link_type* p_next = p_first->etl_next;
662 etl::link<link_type>(p_first, p_last);
664 if (p_next == ETL_NULLPTR)
683 template <
typename TIsEqual>
692 link_type* current = last->etl_next;
694 while (current != ETL_NULLPTR)
697 if (isEqual(*
static_cast<value_type*
>(current), *
static_cast<value_type*
>(last)))
707 current = last->etl_next;
744 template <
typename TCompare>
753 int number_of_merges;
768 number_of_merges = 0;
770 while (i_left !=
end())
777 for (
int i = 0; i < list_size; ++i)
783 if (i_right ==
end())
790 right_size = list_size;
793 while (left_size > 0 || (right_size > 0 && i_right !=
end()))
803 else if (right_size == 0 || i_right ==
end())
810 else if (!
compare(*i_right, *i_left))
828 etl::link<link_type>(i_head.p_value, i_link.p_value);
834 etl::link<link_type>(i_tail.p_value, i_link.p_value);
838 i_tail.p_value->link_type::etl_next = ETL_NULLPTR;
846 if (number_of_merges <= 1)
859 void remove(const_reference value)
864 while (i_item !=
end())
866 if (*i_item == value)
881 template <
typename TPredicate>
887 while (i_item !=
end())
889 if (predicate(*i_item))
911 link_type& first = *other.
get_head();
918 link_type& before = *position.p_value;
919 link_type& after = *position.p_value->link_type::etl_next;
921 etl::link<link_type>(before, first);
923 link_type* last = &before;
924 while (last->link_type::etl_next != ETL_NULLPTR)
926 last = last->link_type::etl_next;
929 etl::link<link_type>(last, after);
941 link_type& before = *position.p_value;
943 etl::unlink<link_type>(*isource.p_value);
944 etl::link_splice<link_type>(before, *isource.p_value);
962 size_t n = etl::distance(begin_, end_) - 1;
967 link_type* first = begin_.p_value;
968 link_type* last = first;
970 while (last->link_type::etl_next != end_.p_value)
972 last = last->link_type::etl_next;
976 link_type* first_next = first->link_type::etl_next;
977 etl::unlink_after(*first, *last);
980 link_type* before = position.p_value;
982 etl::link_splice<link_type>(*before, *first_next, *last);
997 template <
typename TCompare>
1000 if ((
this != &other) && !other.
empty())
1002 #if defined(ETL_DEBUG)
1007 value_type* other_begin =
static_cast<value_type*
>(other.
get_head());
1008 value_type* other_terminal = ETL_NULLPTR;
1010 value_type* before =
static_cast<value_type*
>(&this->
start_link);
1011 value_type* before_next = get_next(before);
1012 value_type* terminal = ETL_NULLPTR;
1014 while ((before->link_type::etl_next != terminal) && (other_begin != other_terminal))
1017 while ((before_next != terminal) && !(
compare(*other_begin, *before_next)))
1019 before = before_next;
1020 before_next = get_next(before_next);
1024 if (before_next != terminal)
1026 while ((other_begin != other_terminal) && (
compare(*other_begin, *before_next)))
1028 value_type* value = other_begin;
1029 other_begin = get_next(other_begin);
1030 etl::link_splice<link_type>(*before, *value);
1031 before = get_next(before);
1037 if (before_next == terminal)
1039 while (other_begin != other_terminal)
1041 value_type* value = other_begin;
1042 other_begin = get_next(other_begin);
1043 etl::link_splice<link_type>(*before, *value);
1044 before = get_next(before);
1059 value_type* get_next(link_type* link)
const
1061 return static_cast<value_type*
>(link->etl_next);
const_iterator
Definition: intrusive_forward_list.h:423
iterator.
Definition: intrusive_forward_list.h:332
Definition: intrusive_forward_list.h:134
link_type * get_head()
Get the head link.
Definition: intrusive_forward_list.h:282
bool is_trivial_list() const
Is the intrusive_forward_list a trivial length?
Definition: intrusive_forward_list.h:250
void reverse()
Reverses the intrusive_forward_list.
Definition: intrusive_forward_list.h:196
void insert_link_after(link_type &position, link_type &link)
Insert a link.
Definition: intrusive_forward_list.h:258
~intrusive_forward_list_base()
Destructor.
Definition: intrusive_forward_list.h:243
bool empty() const
Returns true if the list has no elements.
Definition: intrusive_forward_list.h:221
link_type start_link
The link that acts as the intrusive_forward_list start.
Definition: intrusive_forward_list.h:236
size_t current_size
Counts the number of elements in the list.
Definition: intrusive_forward_list.h:238
void remove_link_after(link_type &link)
Remove a link.
Definition: intrusive_forward_list.h:268
void initialise()
Initialise the intrusive_forward_list.
Definition: intrusive_forward_list.h:298
void pop_front()
Removes a value from the front of the intrusive_forward_list.
Definition: intrusive_forward_list.h:185
void assign(TIterator first, TIterator last)
Definition: intrusive_forward_list.h:153
size_t size() const
Returns the number of elements.
Definition: intrusive_forward_list.h:229
void push_front(link_type &value)
Pushes a value to the front of the intrusive_forward_list.
Definition: intrusive_forward_list.h:177
const link_type * get_head() const
Get the head link.
Definition: intrusive_forward_list.h:290
void clear()
Clears the intrusive_forward_list.
Definition: intrusive_forward_list.h:143
Definition: intrusive_forward_list.h:77
Definition: intrusive_forward_list.h:63
Definition: intrusive_forward_list.h:105
Definition: intrusive_forward_list.h:91
Definition: intrusive_forward_list.h:119
Definition: intrusive_forward_list.h:312
const_iterator before_begin() const
Gets before the beginning of the intrusive_forward_list.
Definition: intrusive_forward_list.h:553
iterator erase_after(iterator first, iterator last)
Erases a range of elements.
Definition: intrusive_forward_list.h:651
void sort(TCompare compare)
Definition: intrusive_forward_list.h:745
const_iterator cbegin() const
Gets the beginning of the intrusive_forward_list.
Definition: intrusive_forward_list.h:561
void splice_after(iterator position, etl::intrusive_forward_list< TValue, TLink > &other)
Splice another list into this one.
Definition: intrusive_forward_list.h:904
~intrusive_forward_list()
Destructor.
Definition: intrusive_forward_list.h:512
void unique(TIsEqual isEqual)
Definition: intrusive_forward_list.h:684
void splice_after(iterator position, etl::intrusive_forward_list< TValue, TLink > &other, iterator begin_, iterator end_)
Splice a range of elements from another list into this one.
Definition: intrusive_forward_list.h:956
void splice_after(iterator position, etl::intrusive_forward_list< TValue, TLink > &other, iterator isource)
Splice an element from another list into this one.
Definition: intrusive_forward_list.h:939
void insert_after(iterator position, TIterator first, TIterator last)
Inserts a range of values to the intrusive_forward_list after the specified position.
Definition: intrusive_forward_list.h:619
void remove_if(TPredicate predicate)
Removes according to a predicate.
Definition: intrusive_forward_list.h:882
iterator erase_after(iterator position)
Erases the value at the specified position.
Definition: intrusive_forward_list.h:632
iterator insert_after(iterator position, value_type &value)
Inserts a value to the intrusive_forward_list after the specified position.
Definition: intrusive_forward_list.h:609
const_iterator begin() const
Gets the beginning of the intrusive_forward_list.
Definition: intrusive_forward_list.h:537
intrusive_forward_list(TIterator first, TIterator last)
Constructor from range.
Definition: intrusive_forward_list.h:521
void merge(list_type &other, TCompare compare)
Merge another list into this one. Both lists should be sorted.
Definition: intrusive_forward_list.h:998
iterator end()
Gets the end of the intrusive_forward_list.
Definition: intrusive_forward_list.h:569
iterator before_begin()
Gets before the beginning of the intrusive_forward_list.
Definition: intrusive_forward_list.h:545
const_iterator end() const
Gets the end of the intrusive_forward_list.
Definition: intrusive_forward_list.h:577
const_reference front() const
Gets a const reference to the first element.
Definition: intrusive_forward_list.h:601
const_iterator cend() const
Gets the end of the intrusive_forward_list.
Definition: intrusive_forward_list.h:585
void merge(list_type &other)
Merge another list into this one. Both lists should be sorted.
Definition: intrusive_forward_list.h:989
void sort()
Sort using in-place merge sort algorithm.
Definition: intrusive_forward_list.h:714
intrusive_forward_list()
Constructor.
Definition: intrusive_forward_list.h:504
iterator begin()
Gets the beginning of the intrusive_forward_list.
Definition: intrusive_forward_list.h:529
reference front()
Gets a reference to the first element.
Definition: intrusive_forward_list.h:593
ETL_NODISCARD bool is_sorted(TIterator begin, TIterator end)
Definition: algorithm.h:1923
bitset< MAXN > operator&(const bitset< MAXN > &lhs, const bitset< MAXN > &rhs)
Definition: bitset.h:1157
#define ETL_ASSERT(b, e)
Definition: error_handler.h:290
exception(string_type reason_, string_type file_, numeric_type line_)
Constructor.
Definition: exception.h:67
Definition: exception.h:47
Definition: absolute.h:37
bool operator!=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition: array.h:594
bool operator==(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition: array.h:582
iterator
Definition: iterator.h:422
Definition: functional.h:112