31 #define __ETL_IN_ILIST_H__
60 typedef const T* const_pointer;
62 typedef const T& const_reference;
63 typedef size_t size_type;
98 return next ==
nullptr;
140 static Data_Node& data_cast(Node& node)
142 return static_cast<Data_Node&
>(node);
148 static const Data_Node* data_cast(
const Node* p_node)
150 return static_cast<const Data_Node*
>(p_node);
156 static const Data_Node& data_cast(
const Node& node)
158 return static_cast<const Data_Node&
>(node);
166 class iterator :
public std::iterator<std::bidirectional_iterator_tag, T>
183 : p_node(other.p_node)
189 p_node = p_node->next;
196 p_node = p_node->next;
202 p_node = p_node->previous;
209 p_node = p_node->previous;
215 p_node = other.p_node;
219 reference operator *()
221 return ilist::data_cast(p_node)->value;
224 const_reference operator *()
const
226 return p_node->value;
231 return &(ilist::data_cast(p_node)->value);
236 return &(ilist::data_cast(p_node)->value);
239 pointer operator ->()
241 return &(ilist::data_cast(p_node)->value);
244 const_pointer operator ->()
const
246 return &(ilist::data_cast(p_node)->value);
251 return lhs.p_node == rhs.p_node;
256 return !(lhs == rhs);
267 class const_iterator :
public std::iterator<std::bidirectional_iterator_tag, const T>
289 : p_node(other.p_node)
294 : p_node(other.p_node)
300 p_node = p_node->next;
307 p_node = p_node->next;
313 p_node = p_node->previous;
320 p_node = p_node->previous;
326 p_node = other.p_node;
330 const_reference operator *()
const
332 return ilist::data_cast(p_node)->value;
337 return ilist::data_cast(p_node)->value;
347 return lhs.p_node == rhs.p_node;
352 return !(lhs == rhs);
360 typedef typename std::iterator_traits<iterator>::difference_type difference_type;
362 typedef std::reverse_iterator<iterator> reverse_iterator;
363 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
404 return const_iterator(static_cast<const Data_Node&>(terminal_node));
420 return const_iterator(static_cast<const Data_Node&>(terminal_node));
428 return reverse_iterator(terminal_node);
436 return const_reverse_iterator(static_cast<const Data_Node&>(terminal_node));
444 return reverse_iterator(get_head());
452 return const_reverse_iterator(static_cast<const Data_Node&>(terminal_node));
458 const_reverse_iterator
crend()
const
460 return const_reverse_iterator(get_head());
468 return data_cast(get_head()).value;
476 return data_cast(get_head()).value;
484 return data_cast(get_tail()).value;
492 return data_cast(get_tail()).value;
500 template <
typename TIterator>
501 void assign(TIterator first, TIterator last)
504 join(terminal_node, terminal_node);
508 while (first != last)
513 data_node.value = *first;
514 join(get_tail(), data_node);
515 join(data_node, terminal_node);
519 #ifdef ETL_THROW_EXCEPTIONS
545 join(terminal_node, terminal_node);
554 data_node.value = value;
555 join(*terminal_node.previous, data_node);
556 join(data_node, terminal_node);
560 #ifdef ETL_THROW_EXCEPTIONS
587 insert_node(get_head(), data_node);
591 #ifdef ETL_THROW_EXCEPTIONS
607 data_node.value = value;
608 insert_node(get_head(), data_node);
612 #ifdef ETL_THROW_EXCEPTIONS
627 remove_node(get_head());
639 insert_node(terminal_node, data_node);
643 #ifdef ETL_THROW_EXCEPTIONS
659 data_node.value = value;
660 insert_node(terminal_node, data_node);
664 #ifdef ETL_THROW_EXCEPTIONS
679 remove_node(get_tail());
691 data_node.value = value;
693 insert_node(*position.p_node, data_node);
699 #ifdef ETL_THROW_EXCEPTIONS
713 for (
size_t i = 0; i < n; ++i)
719 data_node.value = value;
720 insert_node(*position.p_node, data_node);
724 #ifdef ETL_THROW_EXCEPTIONS
736 template <
typename TIterator>
739 while (first != last)
745 data_node.value = *first++;
746 insert_node(*position.p_node, data_node);
750 #ifdef ETL_THROW_EXCEPTIONS
767 remove_node(*position.p_node);
777 Node* p_first = first.p_node;
778 Node* p_last = last.p_node;
782 join(*(p_first->previous), *p_last);
785 while (p_first != p_last)
788 size_t new_free = std::distance(&node_pool[0], data_cast(p_first));
794 p_next = p_first->next;
817 #ifdef ETL_THROW_EXCEPTIONS
829 std::advance(i_start, -difference_type(
size() - n));
850 void remove(
const value_type& value)
852 iterator iValue =
begin();
854 while (iValue !=
end())
856 if (value == *iValue)
858 iValue =
erase(iValue);
870 template <
typename TPredicate>
875 while (iValue !=
end())
877 if (predicate(*iValue))
879 iValue =
erase(iValue);
894 unique(std::equal_to<T>());
901 template <
typename TIsEqual>
913 while (i_item !=
end())
915 if (isEqual(*i_previous, *i_item))
917 i_item =
erase(i_item);
933 sort(std::less<T>());
941 template <
typename TCompare>
950 int number_of_merges;
954 if (is_trivial_list())
965 number_of_merges = 0;
967 while (i_left !=
end())
974 for (
int i = 0; i < list_size; ++i)
979 if (i_right ==
end())
986 right_size = list_size;
989 while (left_size > 0 || (right_size > 0 && i_right !=
end()))
998 else if (right_size == 0 || i_right ==
end())
1004 else if (compare(*i_left, *i_right))
1019 if (i_head ==
end())
1021 join(*i_head.p_node, *i_node.p_node);
1027 join(*i_tail.p_node, *i_node.p_node);
1031 join(*i_tail.p_node, terminal_node);
1039 if (number_of_merges <= 1)
1054 if (is_trivial_list())
1061 while (i_item !=
end())
1078 node_pool(node_pool)
1088 void join(Node& left, Node& right)
1091 right.previous = &left;
1097 void join(Data_Node& left, Data_Node& right)
1100 right.previous = &left;
1106 bool is_trivial_list()
const
1108 return (
size() < 2);
1114 void find_next_free()
1132 void insert_node(Node& position, Node& node)
1135 join(*position.previous, node);
1136 join(node, position);
1148 void remove_node(Node& node)
1151 size_t new_free = std::distance(&node_pool[0], data_cast(&node));
1158 join(*node.previous, *node.next);
1159 node.mark_as_free();
1167 return *terminal_node.next;
1173 const Node& get_head()
const
1175 return *terminal_node.next;
1183 return *terminal_node.previous;
1189 const Node& get_tail()
const
1191 return *terminal_node.previous;
1200 for (
size_t i = 0; i <
max_size(); ++i)
1207 join(terminal_node, terminal_node);
1218 template <
typename T>
1230 template <
typename T>
1233 return !(lhs == rhs);
1243 template <
typename T>
1246 return std::lexicographical_compare(lhs.begin(),
1259 template <
typename T>
1262 return std::lexicographical_compare(lhs.
begin(),
1276 template <
typename T>
1289 template <
typename T>
1296 #define min(a,b) (((a) < (b)) ? (a) : (b))
bool operator!=(const etl::ilist< T > &lhs, const etl::ilist< T > &rhs)
Definition: ilist.h:1231
const size_type MAX_SIZE
The maximum size of the list.
Definition: list_base.h:149
reference front()
Gets a reference to the first element.
Definition: ilist.h:466
void assign(size_t n, parameter_t value)
Assigns 'n' copies of a value to the list.
Definition: ilist.h:542
bitset< N > operator&(const bitset< N > &lhs, const bitset< N > &rhs)
Definition: bitset.h:1154
const_iterator
Definition: ilist.h:267
void assign(TIterator first, TIterator last)
If ETL_THROW_EXCEPTIONS & _DEBUG are defined throws list_iterator if the iterators are reversed...
Definition: ilist.h:501
const_reference front() const
Gets a const reference to the first element.
Definition: ilist.h:474
void clear()
Clears the list.
Definition: ilist.h:842
reference back()
Gets a reference to the last element.
Definition: ilist.h:482
void pop_back()
Removes a value from the back of the list.
Definition: ilist.h:675
iterator.
Definition: ilist.h:166
void swap(etl::bitset< N > &lhs, etl::bitset< N > &rhs)
swap
Definition: bitset.h:1200
void pop_front()
Removes a value from the front of the list.
Definition: ilist.h:623
Determine how to pass parameters.
Definition: parameter_type.h:40
void sort()
Definition: ilist.h:931
Node()
Constructor.
Definition: ilist.h:78
bool full() const
Checks to see if the list is full.
Definition: list_base.h:120
void push_back()
Adds a node to the back of the list so a new value can be assigned to back().
Definition: ilist.h:634
void unique()
Definition: ilist.h:892
void remove_if(TPredicate predicate)
Removes according to a predicate.
Definition: ilist.h:871
iterator end()
Gets the end of the list.
Definition: ilist.h:394
void push_front(parameter_t value)
Pushes a value to the front of the list.
Definition: ilist.h:602
Definition: list_base.h:59
size_type current_size
The number of the used nodes.
Definition: list_base.h:148
void reverse()
Reverses the previous & next pointers.
Definition: ilist.h:104
iterator erase(iterator position)
Erases the value at the specified position.
Definition: ilist.h:762
const_iterator end() const
Gets the end of the list.
Definition: ilist.h:402
void push_back(parameter_t value)
Pushes a value to the back of the list..
Definition: ilist.h:654
bool empty() const
Checks to see if the list is empty.
Definition: list_base.h:112
void reverse()
Reverses the list.
Definition: ilist.h:1052
The node element in the list.
Definition: ilist.h:73
const_reverse_iterator rbegin() const
Gets the reverse beginning of the list.
Definition: ilist.h:434
void unique(TIsEqual isEqual)
Definition: ilist.h:902
Definition: algorithm.h:43
bool operator>=(const etl::ilist< T > &lhs, const etl::ilist< T > &rhs)
Definition: ilist.h:1290
ilist(Data_Node *node_pool, size_t max_size_)
Constructor.
Definition: ilist.h:1076
void push_front()
Adds a node to the front of the list so a new value can be assigned to front().
Definition: ilist.h:582
const_reverse_iterator crbegin() const
Gets the reverse beginning of the list.
Definition: ilist.h:450
bool operator<(const etl::ilist< T > &lhs, const etl::ilist< T > &rhs)
Definition: ilist.h:1244
const_reverse_iterator crend() const
Gets the reverse end of the list.
Definition: ilist.h:458
const_iterator begin() const
Gets the beginning of the list.
Definition: ilist.h:386
ilist & operator=(const ilist &rhs)
Assignment operator.
Definition: ilist.h:368
TIterator next(TIterator iterator, ptrdiff_t n=1)
Definition: container.h:245
size_type max_size() const
Gets the maximum possible size of the list.
Definition: list_base.h:104
const_iterator cend() const
Gets the end of the list.
Definition: ilist.h:418
const_reference back() const
Gets a reference to the last element.
Definition: ilist.h:490
bool operator>(const etl::ilist< T > &lhs, const etl::ilist< T > &rhs)
Definition: ilist.h:1260
Definition: type_traits.h:226
size_type next_free
The index of the next free node.
Definition: list_base.h:147
void resize(size_t n)
Resizes the list.
Definition: ilist.h:805
Definition: list_base.h:87
void resize(size_t n, parameter_t value)
Resizes the list.
Definition: ilist.h:813
reverse_iterator rend()
Gets the reverse end of the list.
Definition: ilist.h:442
static void error(const exception &e)
Definition: error_handler.cpp:50
size_type size() const
Gets the size of the list.
Definition: list_base.h:96
Node terminal_node
The node that acts as the list start and end.
Definition: ilist.h:122
void sort(TCompare compare)
Definition: ilist.h:942
void mark_as_free()
Marks the node as free.
Definition: ilist.h:87
bool operator==(const etl::ilist< T > &lhs, const etl::ilist< T > &rhs)
Definition: ilist.h:1219
void insert(iterator position, TIterator first, TIterator last)
Inserts a range of values to the list at the specified position.
Definition: ilist.h:737
bool is_free() const
Checks if the node is free.
Definition: ilist.h:96
void insert(iterator position, size_t n, const value_type &value)
Inserts 'n' copies of a value to the list at the specified position.
Definition: ilist.h:711
iterator begin()
Gets the beginning of the list.
Definition: ilist.h:378
iterator insert(iterator position, const value_type &value)
Inserts a value to the list at the specified position.
Definition: ilist.h:686
reverse_iterator rbegin()
Gets the reverse beginning of the list.
Definition: ilist.h:426
const_iterator cbegin() const
Gets the beginning of the list.
Definition: ilist.h:410
iterator erase(iterator first, iterator last)
Erases a range of elements.
Definition: ilist.h:775
The data node element in the list.
Definition: ilist.h:116