31#ifndef ETL_MULTIMAP_INCLUDED
32#define ETL_MULTIMAP_INCLUDED
201 children[0] = ETL_NULLPTR;
202 children[1] = ETL_NULLPTR;
212 parent = ETL_NULLPTR;
213 children[0] = ETL_NULLPTR;
214 children[1] = ETL_NULLPTR;
329 position->children[dir] =
new_root->children[1 - dir];
331 if (position->children[dir])
333 position->children[dir]->parent = position;
337 new_root->parent = position->parent;
338 new_root->children[1 - dir] = position;
368 Node*
new_root = position->children[dir]->children[1 - dir];
373 position->children[dir]->children[1 - dir] =
new_root->children[dir];
377 new_root->children[dir]->parent = position->children[dir];
381 new_root->children[dir] = position->children[dir];
382 position->children[dir]->parent =
new_root;
388 position->children[dir] =
new_root->children[1 - dir];
391 new_root->children[1 - dir]->parent = position;
395 new_root->parent = position->parent;
396 new_root->children[1 - dir] = position;
423 Node* parent = position;
428 parent = position->parent;
430 }
while (parent && parent->children[(
uint_least8_t) kRight] == position);
455 const Node* parent = position;
460 parent = position->parent;
462 }
while (parent && parent->children[(
uint_least8_t) kRight] == position);
493 Node* parent = position;
498 parent = position->parent;
500 }
while (parent && parent->children[(
uint_least8_t) kLeft] == position);
531 const Node* parent = position;
536 parent = position->parent;
538 }
while (parent && parent->children[(
uint_least8_t) kLeft] == position);
572 node.parent = parent;
622 ETL_DECLARE_DEBUG_COUNT;
629 template <
typename TKey,
typename TMapped,
typename TKeyCompare = etl::less<TKey> >
634 typedef ETL_OR_STD::pair<const TKey, TMapped> value_type;
635 typedef const TKey key_type;
638 typedef value_type& reference;
639 typedef const value_type& const_reference;
643 typedef value_type* pointer;
644 typedef const value_type* const_pointer;
645 typedef size_t size_type;
647 typedef const key_type& const_key_reference;
656 bool operator()(const_reference
lhs, const_reference
rhs)
const
658 return (kcompare(
lhs.first,
rhs.first));
663 key_compare kcompare;
686 return kcompare(
node1.value.first,
node2.value.first);
689 bool node_comp(
const Data_Node&
node, const_key_reference key)
const
691 return kcompare(
node.value.first, key);
694 bool node_comp(const_key_reference key,
const Data_Node&
node)
const
696 return kcompare(key,
node.value.first);
703 return kcompare(
node.value.first, key);
709 return kcompare(key,
node.value.first);
718 key_compare kcompare;
719 value_compare vcompare;
724 static Data_Node* data_cast(Node* p_node)
726 return static_cast<Data_Node*
>(p_node);
732 static Data_Node& data_cast(Node&
node)
734 return static_cast<Data_Node&
>(
node);
740 static const Data_Node* data_cast(
const Node* p_node)
742 return static_cast<const Data_Node*
>(p_node);
748 static const Data_Node& data_cast(
const Node&
node)
750 return static_cast<const Data_Node&
>(
node);
765 : p_multimap(ETL_NULLPTR)
766 , p_node(ETL_NULLPTR)
772 , p_node(ETL_NULLPTR)
783 : p_multimap(
other.p_multimap)
784 , p_node(
other.p_node)
820 p_multimap =
other.p_multimap;
821 p_node =
other.p_node;
825 reference operator *()
const
827 return imultimap::data_cast(p_node)->value;
830 pointer operator &()
const
832 return &(imultimap::data_cast(p_node)->value);
835 pointer operator ->()
const
837 return &(imultimap::data_cast(p_node)->value);
842 return lhs.p_multimap ==
rhs.p_multimap &&
lhs.p_node ==
rhs.p_node;
870 : p_multimap(ETL_NULLPTR)
871 , p_node(ETL_NULLPTR)
877 , p_node(ETL_NULLPTR)
888 : p_multimap(
other.p_multimap)
889 , p_node(
other.p_node)
894 : p_multimap(
other.p_multimap)
895 , p_node(
other.p_node)
931 p_multimap =
other.p_multimap;
932 p_node =
other.p_node;
936 const_reference operator *()
const
938 return imultimap::data_cast(p_node)->value;
941 const_pointer operator &()
const
943 return imultimap::data_cast(p_node)->value;
946 const_pointer operator ->()
const
948 return &(imultimap::data_cast(p_node)->value);
953 return lhs.p_multimap ==
rhs.p_multimap &&
lhs.p_node ==
rhs.p_node;
977 typedef typename etl::iterator_traits<iterator>::difference_type difference_type;
979 typedef ETL_OR_STD::reverse_iterator<iterator> reverse_iterator;
980 typedef ETL_OR_STD::reverse_iterator<const_iterator> const_reverse_iterator;
1035 return reverse_iterator(
iterator(*
this));
1057 const_reverse_iterator
rend()
const
1085 template <
typename TIterator>
1105 size_type
count(const_key_reference key)
const
1107 return count_nodes(key);
1113 size_type
count(
const K& key)
const
1115 return count_nodes(key);
1123 ETL_OR_STD::pair<iterator, iterator>
equal_range(const_key_reference key)
1125 return ETL_OR_STD::make_pair<iterator, iterator>(
iterator(*
this, find_lower_node(
root_node, key)),
1132 ETL_OR_STD::pair<iterator, iterator>
equal_range(
const K& key)
1134 return ETL_OR_STD::make_pair<iterator, iterator>(
iterator(*
this, find_lower_node(
root_node, key)),
1143 ETL_OR_STD::pair<const_iterator, const_iterator>
equal_range(const_key_reference key)
const
1145 return ETL_OR_STD::make_pair<const_iterator, const_iterator>(
const_iterator(*
this, find_lower_node(
root_node, key)),
1152 ETL_OR_STD::pair<const_iterator, const_iterator>
equal_range(
const K& key)
const
1154 return ETL_OR_STD::make_pair<const_iterator, const_iterator>(const_iterator(*
this, find_lower_node(
root_node, key)),
1155 const_iterator(*
this, find_upper_node(
root_node, key)));
1189 size_type
erase(const_key_reference key)
1234 while (first != last)
1236 first =
erase(first);
1239 return last.to_iterator();
1274 const_iterator
find(
const K&
k)
const
1276 return const_iterator(*
this, find_node(
root_node,
k));
1316 Data_Node&
node = allocate_data_node(etl::move(value));
1348 return insert(etl::move(value));
1359 template <
class TIterator>
1362 while (first != last)
1405 return const_iterator(*
this, find_lower_node(
root_node, key));
1445 return const_iterator(*
this, find_upper_node(
root_node, key));
1527 , p_node_pool(&node_pool)
1549 Data_Node& allocate_data_node(const_reference value)
1551 Data_Node*
node = allocate_data_node();
1553 ETL_INCREMENT_DEBUG_COUNT;
1563 Data_Node*
node = allocate_data_node();
1565 ETL_INCREMENT_DEBUG_COUNT;
1573 Data_Node* allocate_data_node()
1575 Data_Node* (
etl::ipool::*
func)() = &etl::ipool::allocate<Data_Node>;
1576 return (p_node_pool->*
func)();
1582 void destroy_data_node(Data_Node&
node)
1584 node.value.~value_type();
1585 p_node_pool->release(&
node);
1586 ETL_DECREMENT_DEBUG_COUNT;
1592 size_type count_nodes(const_key_reference key)
const
1595 size_type result = 0;
1624 size_type count_nodes(
const K& key)
const
1627 size_type result = 0;
1657 Node* find_node(Node* position, const_key_reference key)
1659 Node*
found = ETL_NULLPTR;
1663 Data_Node&
data_node = imultimap::data_cast(*position);
1690 Node* find_node(Node* position,
const K& key)
1692 Node*
found = ETL_NULLPTR;
1696 Data_Node&
data_node = imultimap::data_cast(*position);
1724 const Node* find_node(
const Node* position, const_key_reference key)
const
1726 const Node*
found = ETL_NULLPTR;
1730 const Data_Node&
data_node = imultimap::data_cast(*position);
1759 const Node* find_node(
const Node* position,
const K& key)
const
1761 const Node*
found = ETL_NULLPTR;
1765 const Data_Node&
data_node = imultimap::data_cast(*position);
1793 Node* find_lower_node(Node* position, const_key_reference key)
const
1800 Data_Node&
data_node = imultimap::data_cast(*position);
1834 Node* find_lower_node(Node* position,
const K& key)
const
1841 Data_Node&
data_node = imultimap::data_cast(*position);
1876 Node* find_upper_node(Node* position, const_key_reference key)
const
1885 Data_Node&
data_node = imultimap::data_cast(*position);
1919 Node* find_upper_node(Node* position,
const K& key)
const
1928 Data_Node&
data_node = imultimap::data_cast(*position);
1963 Node* insert_node(Node*& position, Data_Node&
node)
1966 Node*
found = position;
2069 void remove_node(Node*
node)
2124 (
node->weight == (1 -
node->dir) &&
2146 if (
node->children[
node->dir] == ETL_NULLPTR)
2157 (
node->weight == (1 -
node->dir) &&
2193 if (balance->children[balance->dir] == ETL_NULLPTR)
2202 balance->weight = 1 - balance->dir;
2206 else if (balance->weight == balance->dir)
2213 int weight = balance->children[1 - balance->dir]->weight;
2215 if (weight == balance->dir)
2218 if (balance->parent == ETL_NULLPTR)
2221 balance->children[1 - balance->dir]->children[balance->dir]->weight);
2225 rotate_3node(balance->parent->children[balance->parent->dir], 1 - balance->dir,
2226 balance->children[1 - balance->dir]->children[balance->dir]->weight);
2234 if (balance->parent == ETL_NULLPTR)
2245 rotate_2node(balance->parent->children[balance->parent->dir], 1 - balance->dir);
2249 balance->weight = 1 - balance->dir;
2255 if (balance->parent == ETL_NULLPTR)
2261 rotate_2node(balance->parent->children[balance->parent->dir], 1 - balance->dir);
2267 balance = balance->children[balance->dir];
2275 node->parent->children[
node->parent->dir]);
2306#if defined(ETL_POLYMORPHIC_MULTIMAP) || defined(ETL_POLYMORPHIC_CONTAINERS)
2322 template <
typename TKey,
typename TValue, const
size_t MAX_SIZE_,
typename TCompare = etl::less<TKey> >
2327 static ETL_CONSTANT
size_t MAX_SIZE = MAX_SIZE_;
2333 :
etl::
imultimap<TKey, TValue, TCompare>(node_pool, MAX_SIZE)
2342 :
etl::
imultimap<TKey, TValue, TCompare>(node_pool, MAX_SIZE)
2355 :
etl::
imultimap<TKey, TValue, TCompare>(node_pool, MAX_SIZE)
2361 while (from != other.end())
2366 this->insert(etl::move(*from));
2379 template <
typename TIterator>
2381 :
etl::
imultimap<TKey, TValue, TCompare>(node_pool, MAX_SIZE)
2383 this->assign(first, last);
2386#if ETL_HAS_INITIALIZER_LIST
2390 multimap(std::initializer_list<
typename etl::imultimap<TKey, TValue, TCompare>::value_type> init)
2391 :
etl::
imultimap<TKey, TValue, TCompare>(node_pool, MAX_SIZE)
2393 this->assign(init.begin(), init.end());
2429 while (from != rhs.end())
2434 this->insert(etl::move(*from));
2449 template <
typename TKey,
typename TValue, const
size_t MAX_SIZE_,
typename TCompare>
2450 ETL_CONSTANT
size_t multimap<TKey, TValue, MAX_SIZE_, TCompare>::MAX_SIZE;
2455#if ETL_USING_CPP17 && ETL_HAS_INITIALIZER_LIST
2456 template <
typename...
TPairs>
2465#if ETL_USING_CPP11 && ETL_HAS_INITIALIZER_LIST
2466 template <
typename TKey,
typename TMapped,
typename TKeyCompare = etl::less<TKey>,
typename... TPairs>
2480 template <
typename TKey,
typename TMapped,
typename TKeyCompare>
2483 return (
lhs.size() ==
rhs.size()) && etl::equal(
lhs.begin(),
lhs.end(),
rhs.begin());
2493 template <
typename TKey,
typename TMapped,
typename TKeyCompare>
2506 template <
typename TKey,
typename TMapped,
typename TKeyCompare>
2509 return etl::lexicographical_compare(
lhs.begin(),
lhs.end(),
2521 template <
typename TKey,
typename TMapped,
typename TKeyCompare>
2534 template <
typename TKey,
typename TMapped,
typename TKeyCompare>
2547 template <
typename TKey,
typename TMapped,
typename TKeyCompare>
const_iterator
Definition multimap.h:864
iterator.
Definition multimap.h:758
Definition multimap.h:653
A templated multimap implementation that uses a fixed size buffer.
Definition multimap.h:2324
multimap(TIterator first, TIterator last)
Definition multimap.h:2380
multimap()
Default constructor.
Definition multimap.h:2332
~multimap()
Destructor.
Definition multimap.h:2400
multimap(const multimap &other)
Copy constructor.
Definition multimap.h:2341
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
void assign(TIterator first, TIterator last)
Definition multimap.h:1086
bool contains(const TKey &key) const
Check if the map contains the key.
Definition multimap.h:1506
iterator find(const_key_reference key)
Definition multimap.h:1247
void attach_node(Node *parent, Node *&position, Node &node)
Attach the provided node to the position provided.
Definition multimap.h:566
reverse_iterator rend()
Gets the reverse end of the list.
Definition multimap.h:1049
reverse_iterator rbegin()
Gets the reverse beginning of the list.
Definition multimap.h:1033
size_type size() const
Gets the size of the map.
Definition multimap.h:132
size_type current_size
The number of the used nodes.
Definition multimap.h:619
void next_node(const Node *&position) const
Find the next node in sequence from the node provided.
Definition multimap.h:441
iterator lower_bound(const_key_reference key)
Definition multimap.h:1375
const_reverse_iterator rbegin() const
Gets the reverse beginning of the list.
Definition multimap.h:1041
const_iterator upper_bound(const_key_reference key) const
Definition multimap.h:1435
multimap_base(size_type max_size_)
The constructor that is called from derived classes.
Definition multimap.h:226
const_iterator find(const_key_reference key) const
Definition multimap.h:1266
imultimap & operator=(const imultimap &rhs)
Assignment operator.
Definition multimap.h:1452
iterator insert(const_reference value)
Definition multimap.h:1285
bool node_comp(const Data_Node &node1, const Data_Node &node2) const
How to compare node elements.
Definition multimap.h:684
iterator erase(const_iterator first, const_iterator last)
Erases a range of elements.
Definition multimap.h:1232
ETL_OR_STD::pair< iterator, iterator > equal_range(const_key_reference key)
Definition multimap.h:1123
~multimap_base()
The constructor that is called from derived classes.
Definition multimap.h:236
void prev_node(const Node *&position) const
Find the previous node in sequence from the node provided.
Definition multimap.h:511
size_t available() const
Definition multimap.h:174
iterator end()
Gets the end of the multimap.
Definition multimap.h:1001
void clear()
Clears the multimap.
Definition multimap.h:1095
void rotate_2node(Node *&position, uint_least8_t dir)
Rotate two nodes at the position provided the to balance the tree.
Definition multimap.h:312
iterator erase(iterator position)
Erases the value at the specified position.
Definition multimap.h:1162
const size_type CAPACITY
The maximum size of the map.
Definition multimap.h:620
void detach_node(Node *&position, Node *&replacement)
Detach the node at the position provided.
Definition multimap.h:584
const_reverse_iterator rend() const
Gets the reverse end of the list.
Definition multimap.h:1057
const_iterator end() const
Gets the end of the multimap.
Definition multimap.h:1009
key_compare key_comp() const
How to compare two key elements.
Definition multimap.h:1490
const_iterator cend() const
Gets the end of the multimap.
Definition multimap.h:1025
iterator insert(const_iterator, const_reference value)
Definition multimap.h:1332
bool empty() const
Checks to see if the map is empty.
Definition multimap.h:148
void next_node(Node *&position) const
Find the next node in sequence from the node provided.
Definition multimap.h:409
size_type capacity() const
Definition multimap.h:165
void prev_node(Node *&position) const
Find the previous node in sequence from the node provided.
Definition multimap.h:473
Node * root_node
The node that acts as the multimap root.
Definition multimap.h:621
size_t size_type
The type used for determining the size of map.
Definition multimap.h:127
const_reverse_iterator crbegin() const
Gets the reverse beginning of the list.
Definition multimap.h:1065
iterator begin()
Gets the beginning of the multimap.
Definition multimap.h:985
void insert(TIterator first, TIterator last)
Definition multimap.h:1360
const_iterator lower_bound(const_key_reference key) const
Definition multimap.h:1395
size_type max_size() const
Gets the maximum possible size of the map.
Definition multimap.h:140
ETL_OR_STD::pair< const_iterator, const_iterator > equal_range(const_key_reference key) const
Definition multimap.h:1143
const_iterator cbegin() const
Gets the beginning of the multimap.
Definition multimap.h:1017
iterator upper_bound(const_key_reference key)
Definition multimap.h:1415
size_type count(const_key_reference key) const
Definition multimap.h:1105
const_reverse_iterator crend() const
Gets the reverse end of the list.
Definition multimap.h:1073
void initialise()
Initialise the multimap.
Definition multimap.h:1534
imultimap(etl::ipool &node_pool, size_t max_size_)
Constructor.
Definition multimap.h:1525
value_compare value_comp() const
How to compare two value elements.
Definition multimap.h:1498
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 multimap.h:353
Node * find_limit_node(Node *position, const int8_t dir) const
Definition multimap.h:550
const_iterator begin() const
Gets the beginning of the multimap.
Definition multimap.h:993
bool full() const
Checks to see if the map is full.
Definition multimap.h:156
~imultimap()
Destructor.
Definition multimap.h:2313
iterator erase(const_iterator position)
Erases the value at the specified position.
Definition multimap.h:1171
void balance_node(Node *&critical_node)
Balance the critical node at the position provided as needed.
Definition multimap.h:243
Definition multimap.h:631
Definition multimap.h:124
Definition multimap.h:110
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 multimap.
Definition multimap.h:672
iterator
Definition iterator.h:399
The node element in the multimap.
Definition multimap.h:192
Node()
Constructor.
Definition multimap.h:196
void mark_as_leaf()
Marks the node as a leaf.
Definition multimap.h:208