31#ifndef ETL_MULTISET_INCLUDED
32#define ETL_MULTISET_INCLUDED
200 children[0] = ETL_NULLPTR;
201 children[1] = ETL_NULLPTR;
211 parent = ETL_NULLPTR;
212 children[0] = ETL_NULLPTR;
213 children[1] = ETL_NULLPTR;
248 node.parent = parent;
284 if (
swap->children[kLeft])
286 swap->children[kLeft]->parent =
swap;
288 if (
swap->children[kRight])
290 swap->children[kRight]->parent =
swap;
389 if (position->children[kRight])
398 Node* parent = position;
403 parent = position->parent;
405 }
while (parent && parent->children[kRight] == position);
421 if (position->children[kRight])
430 const Node* parent = position;
435 parent = position->parent;
437 }
while (parent && parent->children[kRight] == position);
459 if (position->children[kLeft])
468 Node* parent = position;
473 parent = position->parent;
475 }
while (parent && parent->children[kLeft] == position);
497 if (position->children[kLeft])
506 const Node* parent = position;
511 parent = position->parent;
513 }
while (parent && parent->children[kLeft] == position);
541 position->children[dir] =
new_root->children[1 - dir];
543 if (position->children[dir])
545 position->children[dir]->parent = position;
549 new_root->parent = position->parent;
550 new_root->children[1 - dir] = position;
554 position->weight = kNeither;
559 position->weight = kNeither;
580 Node*
new_root = position->children[dir]->children[1 - dir];
585 position->children[dir]->children[1 - dir] =
new_root->children[dir];
589 new_root->children[dir]->parent = position->children[dir];
593 new_root->children[dir] = position->children[dir];
594 position->children[dir]->parent =
new_root;
597 position->weight =
third != kNeither &&
third == dir ? 1 - dir : kNeither;
600 position->children[dir] =
new_root->children[1 - dir];
603 new_root->children[1 - dir]->parent = position;
607 new_root->parent = position->parent;
608 new_root->children[1 - dir] = position;
615 position->weight = kNeither;
621 ETL_DECLARE_DEBUG_COUNT;
628 template <
typename TKey,
typename TCompare = ETL_OR_STD::less<TKey> >
633 typedef TKey key_type;
634 typedef TKey value_type;
637 typedef value_type& reference;
638 typedef const value_type& const_reference;
642 typedef value_type* pointer;
643 typedef const value_type* const_pointer;
644 typedef size_t size_type;
679 return compare(key,
node.value);
686 return compare(
node.value, key);
692 return compare(key,
node.value);
706 static Data_Node* data_cast(Node* p_node)
708 return static_cast<Data_Node*
>(p_node);
714 static Data_Node& data_cast(Node&
node)
716 return static_cast<Data_Node&
>(
node);
722 static const Data_Node* data_cast(
const Node* p_node)
724 return static_cast<const Data_Node*
>(p_node);
730 static const Data_Node& data_cast(
const Node&
node)
732 return static_cast<const Data_Node&
>(
node);
747 : p_multiset(ETL_NULLPTR)
748 , p_node(ETL_NULLPTR)
754 , p_node(ETL_NULLPTR)
765 : p_multiset(
other.p_multiset)
766 , p_node(
other.p_node)
802 p_multiset =
other.p_multiset;
803 p_node =
other.p_node;
807 reference operator *()
const
809 return imultiset::data_cast(p_node)->value;
812 pointer operator &()
const
814 return &(imultiset::data_cast(p_node)->value);
817 pointer operator ->()
const
819 return &(imultiset::data_cast(p_node)->value);
824 return lhs.p_multiset ==
rhs.p_multiset &&
lhs.p_node ==
rhs.p_node;
853 : p_multiset(ETL_NULLPTR)
854 , p_node(ETL_NULLPTR)
860 , p_node(ETL_NULLPTR)
871 : p_multiset(
other.p_multiset)
872 , p_node(
other.p_node)
877 : p_multiset(
other.p_multiset)
878 , p_node(
other.p_node)
914 p_multiset =
other.p_multiset;
915 p_node =
other.p_node;
919 const_reference operator *()
const
921 return imultiset::data_cast(p_node)->value;
924 const_pointer operator &()
const
926 return imultiset::data_cast(p_node)->value;
929 const_pointer operator ->()
const
931 return &(imultiset::data_cast(p_node)->value);
936 return lhs.p_multiset ==
rhs.p_multiset &&
lhs.p_node ==
rhs.p_node;
961 typedef typename etl::iterator_traits<iterator>::difference_type difference_type;
963 typedef ETL_OR_STD::reverse_iterator<iterator> reverse_iterator;
964 typedef ETL_OR_STD::reverse_iterator<const_iterator> const_reverse_iterator;
1019 return reverse_iterator(
iterator(*
this));
1041 const_reverse_iterator
rend()
const
1069 template <
typename TIterator>
1091 return count_nodes(key);
1097 size_type
count(
const K& key)
const
1099 return count_nodes(key);
1109 return ETL_OR_STD::make_pair<iterator, iterator>(
iterator(*
this, find_lower_node(
root_node, key)),
1116 ETL_OR_STD::pair<iterator, iterator>
equal_range(
const K& key)
1118 return ETL_OR_STD::make_pair<iterator, iterator>(
iterator(*
this, find_lower_node(
root_node, key)),
1129 return ETL_OR_STD::make_pair<const_iterator, const_iterator>(
const_iterator(*
this, find_lower_node(
root_node, key)),
1138 return ETL_OR_STD::make_pair<const_iterator, const_iterator>(const_iterator(*
this, find_lower_node(
root_node, key)),
1139 const_iterator(*
this, find_upper_node(
root_node, key)));
1219 while (first != last)
1221 first =
erase(first);
1224 return last.to_iterator();
1259 const_iterator
find(
const K&
k)
const
1261 return const_iterator(*
this, find_node(
root_node,
k));
1301 Data_Node&
node = allocate_data_node(etl::move(value));
1333 return insert(etl::move(value));
1344 template <
class TIterator>
1347 while (first != last)
1390 return const_iterator(*
this, find_lower_node(
root_node, key));
1430 return const_iterator(*
this, find_upper_node(
root_node, key));
1515 , p_node_pool(&node_pool)
1537 Data_Node& allocate_data_node(const_reference value)
1539 Data_Node*
node = allocate_data_node();
1540 ::new ((
void*)&
node->value) value_type(value);
1541 ETL_INCREMENT_DEBUG_COUNT;
1551 Data_Node*
node = allocate_data_node();
1552 ::new ((
void*)&
node->value) value_type(etl::move(value));
1553 ETL_INCREMENT_DEBUG_COUNT;
1561 Data_Node* allocate_data_node()
1563 Data_Node* (
etl::ipool::*
func)() = &etl::ipool::allocate<Data_Node>;
1564 return (p_node_pool->*
func)();
1570 void destroy_data_node(Data_Node&
node)
1572 node.value.~value_type();
1573 p_node_pool->release(&
node);
1574 ETL_DECREMENT_DEBUG_COUNT;
1583 size_type result = 0;
1612 size_type count_nodes(
const K& key)
const
1615 size_type result = 0;
1647 Node*
found = ETL_NULLPTR;
1651 Data_Node&
data_node = imultiset::data_cast(*position);
1656 position = position->children[kLeft];
1661 position = position->children[kRight];
1667 position = position->children[kLeft];
1678 Node* find_node(Node* position,
const K& key)
1680 Node*
found = ETL_NULLPTR;
1684 Data_Node&
data_node = imultiset::data_cast(*position);
1689 position = position->children[kLeft];
1694 position = position->children[kRight];
1700 position = position->children[kLeft];
1712 const Node* find_node(
const Node* position,
key_parameter_t key)
const
1714 const Node*
found = ETL_NULLPTR;
1718 const Data_Node&
data_node = imultiset::data_cast(*position);
1723 position = position->children[kLeft];
1728 position = position->children[kRight];
1734 position = position->children[kLeft];
1745 const Node* find_node(
const Node* position,
const K& key)
const
1747 const Node*
found = ETL_NULLPTR;
1751 const Data_Node&
data_node = imultiset::data_cast(*position);
1756 position = position->children[kLeft];
1761 position = position->children[kRight];
1767 position = position->children[kLeft];
1786 Data_Node&
data_node = imultiset::data_cast(*position);
1791 if (position->children[kLeft])
1793 position = position->children[kLeft];
1803 position = position->children[kRight];
1809 position = position->children[kLeft];
1820 Node* find_lower_node(Node* position,
const K& key)
const
1827 Data_Node&
data_node = imultiset::data_cast(*position);
1832 if (position->children[kLeft])
1834 position = position->children[kLeft];
1844 position = position->children[kRight];
1850 position = position->children[kLeft];
1871 Data_Node&
data_node = imultiset::data_cast(*position);
1875 position = position->children[kRight];
1881 if (!
found && position->children[kLeft])
1883 position = position->children[kLeft];
1905 Node* find_upper_node(Node* position,
const K& key)
const
1914 Data_Node&
data_node = imultiset::data_cast(*position);
1918 position = position->children[kRight];
1924 if (!
found && position->children[kLeft])
1926 position = position->children[kLeft];
1949 Node* insert_node(Node*& position, Data_Node&
node)
1952 Node*
found = position;
1965 if (kNeither !=
found->weight)
1983 found->dir = kRight;
1989 found->dir = kRight;
1997 if (kNeither !=
found->children[
found->dir]->weight)
2055 void remove_node(Node*
node)
2076 node->parent->children[kLeft] ==
node ? kLeft : kRight;
2098 node->dir =
node->children[kLeft] ? kLeft : kRight;
2109 if ((
node->weight == kNeither) ||
2110 (
node->weight == (1 -
node->dir) &&
2111 node->children[1 -
node->dir]->weight == kNeither))
2132 if (
node->children[
node->dir] == ETL_NULLPTR)
2142 if ((
node->weight == kNeither) ||
2143 (
node->weight == (1 -
node->dir) &&
2144 node->children[1 -
node->dir]->weight == kNeither))
2170 node->dir =
node->children[kLeft] ? kLeft : kRight;
2179 if (balance->children[balance->dir] == ETL_NULLPTR)
2186 if (balance->weight == kNeither)
2188 balance->weight = 1 - balance->dir;
2192 else if (balance->weight == balance->dir)
2194 balance->weight = kNeither;
2199 int weight = balance->children[1 - balance->dir]->weight;
2201 if (weight == balance->dir)
2204 if (balance->parent == ETL_NULLPTR)
2207 balance->children[1 - balance->dir]->children[balance->dir]->weight);
2211 rotate_3node(balance->parent->children[balance->parent->dir], 1 - balance->dir,
2212 balance->children[1 - balance->dir]->children[balance->dir]->weight);
2217 else if (weight == kNeither)
2220 if (balance->parent == ETL_NULLPTR)
2231 rotate_2node(balance->parent->children[balance->parent->dir], 1 - balance->dir);
2235 balance->weight = 1 - balance->dir;
2241 if (balance->parent == ETL_NULLPTR)
2247 rotate_2node(balance->parent->children[balance->parent->dir], 1 - balance->dir);
2253 balance = balance->children[balance->dir];
2261 node->parent->children[
node->parent->dir]);
2292#if defined(ETL_POLYMORPHIC_MULTISET) || defined(ETL_POLYMORPHIC_CONTAINERS)
2308 template <
typename TKey, const
size_t MAX_SIZE_,
typename TCompare = ETL_OR_STD::less<TKey> >
2313 static ETL_CONSTANT
size_t MAX_SIZE =
MAX_SIZE_;
2362 template <
typename TIterator>
2366 this->
assign(first, last);
2369#if ETL_HAS_INITIALIZER_LIST
2373 multiset(std::initializer_list<
typename etl::imultiset<TKey, TCompare>::value_type>
init)
2431 template <
typename TKey, const
size_t MAX_SIZE_,
typename TCompare>
2432 ETL_CONSTANT
size_t multiset<TKey, MAX_SIZE_, TCompare>::MAX_SIZE;
2437#if ETL_USING_CPP17 && ETL_HAS_INITIALIZER_LIST
2438 template <
typename...
T>
2445#if ETL_USING_CPP11 && ETL_HAS_INITIALIZER_LIST
2446 template <
typename TKey,
typename TKeyCompare = etl::less<TKey>,
typename... T>
2460 template <
typename TKey,
typename TCompare>
2463 return (
lhs.size() ==
rhs.size()) && ETL_OR_STD::equal(
lhs.begin(),
lhs.end(),
rhs.begin());
2473 template <
typename TKey,
typename TCompare>
2486 template <
typename TKey,
typename TCompare>
2489 return ETL_OR_STD::lexicographical_compare(
lhs.begin(),
lhs.end(),
2491 etl::imultiset<TKey, TCompare>::value_compare());
2501 template <
typename TKey,
typename TCompare>
2514 template <
typename TKey,
typename TCompare>
2527 template <
typename TKey,
typename TCompare>
const_iterator
Definition multiset.h:847
iterator.
Definition multiset.h:740
A templated multiset implementation that uses a fixed size buffer.
Definition multiset.h:2310
multiset(const multiset &other)
Copy constructor.
Definition multiset.h:2327
multiset()
Default constructor.
Definition multiset.h:2318
~multiset()
Destructor.
Definition multiset.h:2383
multiset & operator=(const multiset &rhs)
Assignment operator.
Definition multiset.h:2391
multiset(TIterator first, TIterator last)
Definition multiset.h:2363
ETL_CONSTEXPR14 bool operator==(const etl::expected< TValue, TError > &lhs, const etl::expected< TValue2, TError2 > &rhs)
Equivalence operators.
Definition expected.h:974
#define ETL_ASSERT(b, e)
Definition error_handler.h:356
Definition exception.h:47
iterator begin()
Gets the beginning of the multiset.
Definition multiset.h:969
iterator lower_bound(key_parameter_t key)
Definition multiset.h:1360
bool full() const
Checks to see if the set is full.
Definition multiset.h:155
void next_node(const Node *&position) const
Find the next node in sequence from the node provided.
Definition multiset.h:416
reverse_iterator rbegin()
Gets the reverse beginning of the list.
Definition multiset.h:1017
iterator insert(const_reference value)
Definition multiset.h:1270
void clear()
Clears the multiset.
Definition multiset.h:1079
const_iterator upper_bound(key_parameter_t key) const
Definition multiset.h:1420
size_type count(key_parameter_t key) const
Definition multiset.h:1089
imultiset & operator=(const imultiset &rhs)
Assignment operator.
Definition multiset.h:1437
bool contains(key_parameter_t key) const
Check if the set contains the key.
Definition multiset.h:1494
bool node_comp(const Data_Node &node1, const Data_Node &node2) const
How to compare node elements.
Definition multiset.h:667
const size_type CAPACITY
The maximum size of the set.
Definition multiset.h:619
size_t size_type
The type used for determining the size of set.
Definition multiset.h:126
const TKey & key_parameter_t
Defines the key value parameter type.
Definition multiset.h:662
void rotate_2node(Node *&position, uint_least8_t dir)
Rotate two nodes at the position provided the to balance the tree.
Definition multiset.h:524
const_reverse_iterator crbegin() const
Gets the reverse beginning of the list.
Definition multiset.h:1049
Node * find_limit_node(Node *position, const int8_t dir) const
Definition multiset.h:368
iterator erase(const_iterator first, const_iterator last)
Erases a range of elements.
Definition multiset.h:1216
iterator end()
Gets the end of the multiset.
Definition multiset.h:985
ETL_OR_STD::pair< const_iterator, const_iterator > equal_range(key_parameter_t key) const
Definition multiset.h:1127
const_iterator lower_bound(key_parameter_t key) const
Definition multiset.h:1380
size_type size() const
Gets the size of the set.
Definition multiset.h:131
void balance_node(Node *&critical_node)
Balance the critical node at the position provided as needed.
Definition multiset.h:298
const_iterator end() const
Gets the end of the multiset.
Definition multiset.h:993
const_iterator cend() const
Gets the end of the multiset.
Definition multiset.h:1009
const_iterator cbegin() const
Gets the beginning of the multiset.
Definition multiset.h:1001
iterator find(key_parameter_t key_value)
Definition multiset.h:1232
void next_node(Node *&position) const
Find the next node in sequence from the node provided.
Definition multiset.h:384
void initialise()
Initialise the multiset.
Definition multiset.h:1522
void assign(TIterator first, TIterator last)
Definition multiset.h:1070
const_iterator find(key_parameter_t key_value) const
Definition multiset.h:1251
size_type capacity() const
Definition multiset.h:164
reverse_iterator rend()
Gets the reverse end of the list.
Definition multiset.h:1033
void attach_node(Node *parent, Node *&position, Node &node)
Attach the provided node to the position provided.
Definition multiset.h:242
const_iterator begin() const
Gets the beginning of the multiset.
Definition multiset.h:977
ETL_OR_STD::pair< iterator, iterator > equal_range(key_parameter_t key)
Definition multiset.h:1107
void prev_node(Node *&position) const
Find the previous node in sequence from the node provided.
Definition multiset.h:448
void prev_node(const Node *&position) const
Find the previous node in sequence from the node provided.
Definition multiset.h:486
imultiset(etl::ipool &node_pool, size_t max_size_)
Constructor.
Definition multiset.h:1513
Node * root_node
The node that acts as the multiset root.
Definition multiset.h:620
size_type max_size() const
Gets the maximum possible size of the set.
Definition multiset.h:139
const_reverse_iterator rend() const
Gets the reverse end of the list.
Definition multiset.h:1041
~imultiset()
Destructor.
Definition multiset.h:2299
void insert(TIterator first, TIterator last)
Definition multiset.h:1345
value_compare value_comp() const
How to compare two value elements.
Definition multiset.h:1486
~multiset_base()
Destructor.
Definition multiset.h:235
iterator insert(const_iterator, const_reference value)
Definition multiset.h:1317
multiset_base(size_type max_size_)
The constructor that is called from derived classes.
Definition multiset.h:225
iterator upper_bound(key_parameter_t key)
Definition multiset.h:1400
key_compare key_comp() const
How to compare two key elements.
Definition multiset.h:1478
iterator erase(const_iterator position)
Erases the value at the specified position.
Definition multiset.h:1155
const_reverse_iterator rbegin() const
Gets the reverse beginning of the list.
Definition multiset.h:1025
void detach_node(Node *&position, Node *&replacement)
Detach the node at the position provided.
Definition multiset.h:260
iterator erase(iterator position)
Erases the value at the specified position.
Definition multiset.h:1146
const_reverse_iterator crend() const
Gets the reverse end of the list.
Definition multiset.h:1057
bool empty() const
Checks to see if the set is empty.
Definition multiset.h:147
size_type current_size
The number of the used nodes.
Definition multiset.h:618
size_t available() const
Definition multiset.h:173
void rotate_3node(Node *&position, uint_least8_t dir, uint_least8_t third)
Rotate three nodes at the position provided the to balance the tree.
Definition multiset.h:565
Definition multiset.h:630
Definition multiset.h:123
Definition multiset.h:109
bitset_ext
Definition absolute.h:38
bool operator>(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1148
bool operator>=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1160
bool operator!=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1109
void swap(etl::array< T, SIZE > &lhs, etl::array< T, SIZE > &rhs)
Template deduction guides.
Definition array.h:1085
bool operator==(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1097
ETL_NODISCARD ETL_CONSTEXPR14 T round_half_even_unscaled(T value) ETL_NOEXCEPT
Definition scaled_rounding.h:314
bool operator<(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1121
bool operator<=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1136
The data node element in the multiset.
Definition multiset.h:652
iterator
Definition iterator.h:399
The node element in the multiset.
Definition multiset.h:191
void mark_as_leaf()
Marks the node as a leaf.
Definition multiset.h:207
Node()
Constructor.
Definition multiset.h:195