31 #define __ETL_IN_ILIST_H__
60 typedef const T* const_pointer;
62 typedef const T& const_reference;
88 return next ==
nullptr;
107 class iterator :
public std::iterator<std::forward_iterator_tag, T>
124 : p_node(other.p_node)
130 p_node = p_node->next;
137 p_node = p_node->next;
143 p_node = other.p_node;
147 reference operator *()
149 return iforward_list::data_cast(p_node)->value;
152 const_reference operator *()
const
154 return iforward_list::data_cast(p_node)->value;
159 return &(iforward_list::data_cast(p_node)->value);
164 return &(iforward_list::data_cast(p_node)->value);
167 pointer operator ->()
169 return &(iforward_list::data_cast(p_node)->value);
172 const_pointer operator ->()
const
174 return &(iforward_list::data_cast(p_node)->value);
179 return lhs.p_node == rhs.p_node;
184 return !(lhs == rhs);
217 : p_node(other.p_node)
222 : p_node(other.p_node)
228 p_node = p_node->next;
235 p_node = p_node->next;
241 p_node = other.p_node;
245 const_reference operator *()
const
247 return iforward_list::data_cast(p_node)->value;
252 return iforward_list::data_cast(p_node)->value;
255 const_pointer operator ->()
const
257 return &(iforward_list::data_cast(p_node)->value);
262 return lhs.p_node == rhs.p_node;
267 return !(lhs == rhs);
275 typedef typename std::iterator_traits<iterator>::difference_type difference_type;
282 return iterator(data_cast(get_head()));
364 return data_cast(get_head()).value;
372 return data_cast(get_head()).value;
380 template <
typename TIterator>
381 void assign(TIterator first, TIterator last)
391 while (first != last)
396 data_node.value = *first++;
397 join(*p_last_node, data_node);
399 p_last_node = &data_node;
402 #ifdef ETL_THROW_EXCEPTIONS
419 node_pool[i].mark_as_free();
442 data_node.value = value;
443 join(*p_last_node, data_node);
445 p_last_node = &data_node;
448 #ifdef ETL_THROW_EXCEPTIONS
465 node_pool[i].mark_as_free();
479 insert_node(get_head(), data_node);
482 #ifdef ETL_THROW_EXCEPTIONS
501 data_node.value = value;
503 insert_node_after(get_head(), data_node);
506 #ifdef ETL_THROW_EXCEPTIONS
549 while ((i < n) && (i_node !=
end()))
560 else if (i_node ==
end())
570 #ifdef ETL_THROW_EXCEPTIONS
586 if (is_trivial_list())
592 Node* p_current = p_last->next;
593 Node* p_next = p_current->next;
601 p_next = p_current->next;
603 p_current->next =
static_cast<Data_Node*
>(p_last);
617 data_node.value = value;
619 insert_node_after(*position.p_node, data_node);
624 #ifdef ETL_THROW_EXCEPTIONS
644 for (
size_t i = 0; !
full() && (i < n); ++i)
648 data_node.value = value;
650 insert_node(*position.p_node, data_node);
654 #ifdef ETL_THROW_EXCEPTIONS
668 template <
typename TIterator>
671 while (first != last)
677 data_node.value = *first;
679 insert_node_after(*position.p_node, data_node);
684 #ifdef ETL_THROW_EXCEPTIONS
705 remove_node_after(*position.p_node);
715 Node* p_first = first.p_node;
716 Node* p_last = last.p_node;
717 Node* p_next = p_first->next;
720 join(*p_first, *p_last);
725 while (p_first != p_last)
728 size_t new_free = std::distance(&node_pool[0], static_cast<Data_Node*>(p_first));
734 p_next = p_first->next;
735 p_first->mark_as_free();
748 unique(std::equal_to<T>());
755 template <
typename TIsEqual>
763 Node* last = &get_head();
764 Node* current = last->next;
769 if (isEqual(data_cast(current)->value, data_cast(last)->value))
771 remove_node_after(*last);
779 current = last->next;
789 sort(std::less<T>());
797 template <
typename TCompare>
806 int number_of_merges;
810 if (is_trivial_list())
821 number_of_merges = 0;
823 while (p_left !=
end())
830 for (
int i = 0; i < list_size; ++i)
836 if (p_right ==
end())
843 right_size = list_size;
846 while (left_size > 0 || (right_size > 0 && p_right !=
end()))
856 else if (right_size == 0 || p_right ==
end())
863 else if (compare(*p_left, *p_right))
881 join(*p_head.p_node, *p_node.p_node);
887 join(*p_tail.p_node, *p_node.p_node);
899 if (number_of_merges <= 1)
912 void remove(parameter_t value)
914 iterator i_item =
begin();
917 while (i_item !=
end())
919 if (*i_item == value)
934 template <
typename TPredicate>
940 while (i_item !=
end())
942 if (predicate(*i_item))
984 static Data_Node& data_cast(Node& node)
986 return static_cast<Data_Node&
>(node);
992 static const Data_Node* data_cast(
const Node* p_node)
994 return static_cast<const Data_Node*
>(p_node);
1000 static const Data_Node& data_cast(
const Node& node)
1002 return static_cast<const Data_Node&
>(node);
1008 void join(Node& left, Node& right)
1010 left.next = &
static_cast<Data_Node&
>(right);
1016 void join(Data_Node& left, Data_Node& right)
1024 bool is_trivial_list()
const
1026 return (
size() < 2);
1032 void find_next_free()
1050 void insert_node_after(Node& position, Node& node)
1053 join(node, *position.next);
1054 join(position, node);
1066 void remove_node_after(Node& node)
1069 Node* p_node = node.next;
1075 join(node, *p_node->next);
1076 p_node->mark_as_free();
1079 size_t new_free = std::distance(&node_pool[0], static_cast<Data_Node*>(p_node));
1088 return static_cast<Data_Node&
>(*start_node.next);
1094 const Node& get_head()
const
1096 return *start_node.next;
1105 for (
size_t i = 0; i <
max_size(); ++i)
1107 node_pool[i].mark_as_free();
1112 join(start_node, end_node);
1113 join(end_node, start_node);
1124 template <
typename T>
1127 return (lhs.
size() == rhs.
size()) &&
1137 template <
typename T>
1140 return !(lhs == rhs);
1150 template <
typename T>
1153 return std::lexicographical_compare(lhs.begin(),
1166 template <
typename T>
1169 return std::lexicographical_compare(lhs.
begin(),
1183 template <
typename T>
1196 template <
typename T>
1203 #define min(a,b) (((a) < (b)) ? (a) : (b))
void push_front()
Adds a node to the front of the forward_list so a new value can be assigned to front().
Definition: iforward_list.h:473
bool full() const
Checks to see if the forward_list is full.
Definition: forward_list_base.h:120
bool operator==(const etl::iforward_list< T > &lhs, const etl::iforward_list< T > &rhs)
Definition: iforward_list.h:1125
iterator erase_after(iterator position)
Erases the value at the specified position.
Definition: iforward_list.h:699
const_iterator end() const
Gets the end of the forward_list.
Definition: iforward_list.h:328
const_iterator cbegin() const
Gets the beginning of the forward_list.
Definition: iforward_list.h:312
iforward_list(Data_Node *node_pool, size_t max_size_)
Constructor.
Definition: iforward_list.h:959
bitset< N > operator&(const bitset< N > &lhs, const bitset< N > &rhs)
Definition: bitset.h:1154
void unique(TIsEqual isEqual)
Definition: iforward_list.h:756
Node start_node
The node that acts as the forward_list start.
Definition: iforward_list.h:966
void sort(TCompare compare)
Definition: iforward_list.h:798
iterator erase_after(iterator first, iterator last)
Erases a range of elements.
Definition: iforward_list.h:713
size_t size_type
The type used for determining the size of forward_list.
Definition: forward_list_base.h:91
size_type next_free
The index of the next free node.
Definition: forward_list_base.h:147
Determine how to pass parameters.
Definition: parameter_type.h:40
void resize(size_t n, T value)
Definition: iforward_list.h:541
iterator insert_after(iterator position, parameter_t value)
Inserts a value to the forward_list after the specified position.
Definition: iforward_list.h:612
iterator begin()
Gets the beginning of the forward_list.
Definition: iforward_list.h:280
Definition: forward_list_base.h:87
bool operator>(const etl::iforward_list< T > &lhs, const etl::iforward_list< T > &rhs)
Definition: iforward_list.h:1167
iforward_list & operator=(const iforward_list &rhs)
Assignment operator.
Definition: iforward_list.h:344
const_iterator cend() const
Gets the end of the forward_list.
Definition: iforward_list.h:336
void unique()
Definition: iforward_list.h:746
void insert_after(iterator position, TIterator first, TIterator last)
Inserts a range of values to the forward_list after the specified position.
Definition: iforward_list.h:669
void push_front(parameter_t value)
Pushes a value to the front of the forward_list.
Definition: iforward_list.h:496
size_type size() const
Gets the size of the forward_list.
Definition: forward_list_base.h:96
Definition: algorithm.h:43
void assign(TIterator first, TIterator last)
If ETL_THROW_EXCEPTIONS & _DEBUG are defined throws forward_list_iterator if the iterators are revers...
Definition: iforward_list.h:381
bool operator>=(const etl::iforward_list< T > &lhs, const etl::iforward_list< T > &rhs)
Definition: iforward_list.h:1197
The data node element in the forward_list.
Definition: iforward_list.h:97
iterator.
Definition: iforward_list.h:107
void resize(size_t n)
Resizes the forward_list.
Definition: iforward_list.h:531
void clear()
Clears the forward_list.
Definition: iforward_list.h:354
iterator before_begin()
Gets before the beginning of the forward_list.
Definition: iforward_list.h:296
void assign(size_t n, parameter_t value)
Assigns 'n' copies of a value to the forward_list.
Definition: iforward_list.h:427
void reverse()
Reverses the forward_list.
Definition: iforward_list.h:584
const_iterator before_begin() const
Gets before the beginning of the forward_list.
Definition: iforward_list.h:304
size_type max_size() const
Gets the maximum possible size of the forward_list.
Definition: forward_list_base.h:104
const_reference front() const
Gets a const reference to the first element.
Definition: iforward_list.h:370
bool operator<(const etl::iforward_list< T > &lhs, const etl::iforward_list< T > &rhs)
Definition: iforward_list.h:1151
iterator end()
Gets the end of the forward_list.
Definition: iforward_list.h:320
const_iterator begin() const
Gets the beginning of the forward_list.
Definition: iforward_list.h:288
TIterator next(TIterator iterator, ptrdiff_t n=1)
Definition: container.h:245
bool empty() const
Checks to see if the forward_list is empty.
Definition: forward_list_base.h:112
void sort()
Definition: iforward_list.h:787
Definition: type_traits.h:226
reference front()
Gets a reference to the first element.
Definition: iforward_list.h:362
static void error(const exception &e)
Definition: error_handler.cpp:50
Node end_node
The node that acts as the forward_list end.
Definition: iforward_list.h:967
const size_type MAX_SIZE
The maximum size of the forward_list.
Definition: forward_list_base.h:149
void remove_if(TPredicate predicate)
Removes according to a predicate.
Definition: iforward_list.h:935
bool operator!=(const etl::iforward_list< T > &lhs, const etl::iforward_list< T > &rhs)
Definition: iforward_list.h:1138
void pop_front()
Removes a value from the front of the forward_list.
Definition: iforward_list.h:520
Definition: forward_list_base.h:59
void insert_after(iterator position, size_t n, parameter_t value)
Inserts 'n' copies of a value to the forward_list after the specified position.
Definition: iforward_list.h:640
const_iterator
Definition: iforward_list.h:195
size_type count
The number of the used nodes.
Definition: forward_list_base.h:148
Definition: iforward_list.h:74
Definition: iforward_list.h:54