468 typedef TKey key_type;
469 typedef TKey value_type;
470 typedef TCompare key_compare;
471 typedef TCompare value_compare;
472 typedef value_type& reference;
473 typedef const value_type& const_reference;
475 typedef value_type&& rvalue_reference;
477 typedef value_type* pointer;
478 typedef const value_type* const_pointer;
479 typedef size_t size_type;
488 explicit Data_Node(value_type value_)
504 return compare(node1.value, node2.value);
509 return compare(node.value, key);
515 return compare(key, node.value);
519 template <typename K, typename KC = TCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
522 return compare(node.value, key);
525 template <typename K, typename KC = TCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
529 return compare(key, node.value);
536 etl::ipool* p_node_pool;
561 return static_cast<const Data_Node*
>(p_node);
569 return static_cast<const Data_Node&
>(node);
576 class iterator :
public etl::iterator<ETL_OR_STD::bidirectional_iterator_tag, value_type>
581 friend class const_iterator;
585 , p_node(ETL_NULLPTR)
591 , p_node(ETL_NULLPTR)
595 iterator(iset&
set,
Node* node)
601 iterator(
const iterator& other)
603 , p_node(other.p_node)
611 iterator& operator ++()
613 p_set->next_node(p_node);
617 iterator operator ++(
int)
619 iterator temp(*
this);
620 p_set->next_node(p_node);
624 iterator& operator --()
626 p_set->prev_node(p_node);
630 iterator operator --(
int)
632 iterator temp(*
this);
633 p_set->prev_node(p_node);
637 iterator& operator =(
const iterator& other)
640 p_node = other.p_node;
644 reference operator *()
const
646 return iset::data_cast(p_node)->value;
649 pointer operator &()
const
651 return &(iset::data_cast(p_node)->value);
654 pointer operator ->()
const
656 return &(iset::data_cast(p_node)->value);
659 friend bool operator == (
const iterator& lhs,
const iterator& rhs)
661 return lhs.p_set == rhs.p_set && lhs.p_node == rhs.p_node;
664 friend bool operator != (
const iterator& lhs,
const iterator& rhs)
666 return !(lhs == rhs);
682 class const_iterator :
public etl::iterator<ETL_OR_STD::bidirectional_iterator_tag, const value_type>
690 , p_node(ETL_NULLPTR)
694 const_iterator(
const iset&
set)
696 , p_node(ETL_NULLPTR)
700 const_iterator(
const iset&
set,
const Node* node)
708 , p_node(other.p_node)
712 const_iterator(
const const_iterator& other)
714 , p_node(other.p_node)
722 const_iterator& operator ++()
724 p_set->next_node(p_node);
728 const_iterator operator ++(
int)
730 const_iterator temp(*
this);
731 p_set->next_node(p_node);
735 const_iterator& operator --()
737 p_set->prev_node(p_node);
741 const_iterator operator --(
int)
743 const_iterator temp(*
this);
744 p_set->prev_node(p_node);
748 const_iterator& operator =(
const const_iterator& other)
751 p_node = other.p_node;
755 const_reference operator *()
const
757 return iset::data_cast(p_node)->value;
760 const_pointer operator &()
const
762 return iset::data_cast(p_node)->value;
765 const_pointer operator ->()
const
767 return &(iset::data_cast(p_node)->value);
770 friend bool operator == (
const const_iterator& lhs,
const const_iterator& rhs)
772 return lhs.p_set == rhs.p_set && lhs.p_node == rhs.p_node;
775 friend bool operator != (
const const_iterator& lhs,
const const_iterator& rhs)
777 return !(lhs == rhs);
796 typedef typename etl::iterator_traits<iterator>::difference_type difference_type;
798 typedef ETL_OR_STD::reverse_iterator<iterator> reverse_iterator;
799 typedef ETL_OR_STD::reverse_iterator<const_iterator> const_reverse_iterator;
828 while (from != rhs.end())
833 this->
insert(etl::move(*from));
895 return reverse_iterator(
iterator(*
this));
917 const_reverse_iterator
rend()
const
933 const_reverse_iterator
crend()
const
945 template <
typename TIterator>
946 void assign(TIterator first, TIterator last)
967 return find_node(
root_node, key) ? 1 : 0;
972 template <typename K, typename KC = TCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
975 return find_node(
root_node, key) ? 1 : 0;
985 return ETL_OR_STD::make_pair<iterator, iterator>(
iterator(*
this, find_lower_node(
root_node, key)),
991 template <typename K, typename KC = TCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
992 ETL_OR_STD::pair<iterator, iterator>
equal_range(
const K& key)
994 return ETL_OR_STD::make_pair<iterator, iterator>(
iterator(*
this, find_lower_node(
root_node, key)),
1005 return ETL_OR_STD::make_pair<const_iterator, const_iterator>(
const_iterator(*
this, find_lower_node(
root_node, key)),
1011 template <typename K, typename KC = TCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
1012 ETL_OR_STD::pair<const_iterator, const_iterator>
equal_range(
const K& key)
const
1014 return ETL_OR_STD::make_pair<const_iterator, const_iterator>(
const_iterator(*
this, find_lower_node(
root_node, key)),
1034 Node*& reference_node = find_node(
root_node, position.p_node);
1035 iterator next(*
this, reference_node);
1049 return remove_node(
root_node, key_value) ? 1 : 0;
1054 template <typename K, typename KC = TCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
1058 return remove_node(
root_node, etl::forward<K>(key_value)) ? 1 : 0;
1067 while (first != last)
1069 first =
erase(first);
1072 return last.to_iterator();
1087 template <typename K, typename KC = TCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
1106 template <typename K, typename KC = TCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
1118 ETL_OR_STD::pair<iterator, bool>
insert(const_reference value)
1121 Node* inserted_node = ETL_NULLPTR;
1122 bool inserted =
false;
1129 ETL_ASSERT_FAIL(ETL_ERROR(
set_full));
1133 return ETL_OR_STD::make_pair(iter,
false);
1138 Data_Node& node = allocate_data_node(value);
1141 inserted_node = insert_node(
root_node, node);
1142 inserted = inserted_node == &node;
1145 return ETL_OR_STD::make_pair(
iterator(*
this, inserted_node), inserted);
1154 ETL_OR_STD::pair<iterator, bool>
insert(rvalue_reference value)
1157 Node* inserted_node = ETL_NULLPTR;
1158 bool inserted =
false;
1165 ETL_ASSERT_FAIL(ETL_ERROR(
set_full));
1169 return ETL_OR_STD::make_pair(iter,
false);
1174 Data_Node& node = allocate_data_node(etl::move(value));
1177 inserted_node = insert_node(
root_node, node);
1178 inserted = inserted_node == &node;
1181 return ETL_OR_STD::make_pair(
iterator(*
this, inserted_node), inserted);
1194 Node* inserted_node = ETL_NULLPTR;
1201 ETL_ASSERT_FAIL(ETL_ERROR(
set_full));
1210 Data_Node& node = allocate_data_node(value);
1213 inserted_node = insert_node(
root_node, node);
1216 return iterator(*
this, inserted_node);
1229 Node* inserted_node = ETL_NULLPTR;
1236 ETL_ASSERT_FAIL(ETL_ERROR(
set_full));
1245 Data_Node& node = allocate_data_node(etl::move(value));
1248 inserted_node = insert_node(
root_node, node);
1251 return iterator(*
this, inserted_node);
1262 template <
class TIterator>
1265 while (first != last)
1285 template <typename K, typename KC = TCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
1305 template <typename K, typename KC = TCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
1325 template <typename K, typename KC = TCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
1345 template <typename K, typename KC = TCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
1378 template <typename K, typename KC = TCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
1392 , p_node_pool(&node_pool)
1403 while (item !=
end())
1414 Data_Node& allocate_data_node(const_reference value)
1416 Data_Node* node = allocate_data_node();
1417 ::new ((
void*)&node->value)
value_type(value);
1418 ETL_INCREMENT_DEBUG_COUNT;
1426 Data_Node& allocate_data_node(rvalue_reference value)
1428 Data_Node* node = allocate_data_node();
1429 ::new ((
void*)&node->value) value_type(etl::move(value));
1430 ETL_INCREMENT_DEBUG_COUNT;
1441 return (p_node_pool->*func)();
1449 node.value.~value_type();
1450 p_node_pool->release(&node);
1451 ETL_DECREMENT_DEBUG_COUNT;
1459 Node* found = position;
1463 Data_Node& found_data_node = iset::data_cast(*found);
1469 found = found->children[kLeft];
1471 else if (
node_comp(found_data_node, key))
1474 found = found->children[kRight];
1489 template <typename K, typename KC = TCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
1490 Node* find_node(
Node* position,
const K& key)
1492 Node* found = position;
1496 Data_Node& found_data_node = iset::data_cast(*found);
1502 found = found->children[kLeft];
1504 else if (
node_comp(found_data_node, key))
1507 found = found->children[kRight];
1526 const Node* found = position;
1530 const Data_Node& found_data_node = iset::data_cast(*found);
1536 found = found->children[kLeft];
1538 else if (
node_comp(found_data_node, key))
1541 found = found->children[kRight];
1556 template <typename K, typename KC = TCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
1557 const Node* find_node(
const Node* position,
const K& key)
const
1559 const Node* found = position;
1563 const Data_Node& found_data_node = iset::data_cast(*found);
1569 found = found->children[kLeft];
1571 else if (
node_comp(found_data_node, key))
1574 found = found->children[kRight];
1593 Node* found = position;
1596 if (found->children[kLeft] == node)
1598 return found->children[kLeft];
1600 else if (found->children[kRight] == node)
1602 return found->children[kRight];
1607 Data_Node& found_data_node = iset::data_cast(*found);
1608 const Data_Node& data_node = iset::data_cast(*node);
1611 if (
node_comp(data_node, found_data_node))
1614 found = found->children[kLeft];
1616 else if (
node_comp(found_data_node, data_node))
1619 found = found->children[kRight];
1637 Node* find_parent_node(
Node* position,
const Node* node)
1640 Node* found = ETL_NULLPTR;
1643 if (position && node && position != node)
1648 if (position->children[kLeft] != node &&
1649 position->children[kRight] != node)
1652 const Data_Node& node_data_node = iset::data_cast(*node);
1653 Data_Node& position_data_node = iset::data_cast(*position);
1655 if (
node_comp(node_data_node, position_data_node))
1658 position = position->children[kLeft];
1660 else if (
node_comp(position_data_node, node_data_node))
1663 position = position->children[kRight];
1685 const Node* find_parent_node(
const Node* position,
const Node* node)
const
1688 const Node* found = ETL_NULLPTR;
1691 if (position && node && position != node)
1696 if (position->children[kLeft] != node &&
1697 position->children[kRight] != node)
1700 const Data_Node& node_data_node = iset::data_cast(*node);
1701 const Data_Node& position_data_node = iset::data_cast(*position);
1703 if (
node_comp(node_data_node, position_data_node))
1706 position = position->children[kLeft];
1708 else if (
node_comp(position_data_node, node_data_node))
1711 position = position->children[kRight];
1735 Node* lower_node = ETL_NULLPTR;
1739 Data_Node& data_node = iset::data_cast(*position);
1743 lower_node = position;
1744 if (position->children[kLeft])
1746 position = position->children[kLeft];
1756 position = position->children[kRight];
1761 lower_node = position;
1762 position = position->children[kLeft];
1772 template <typename K, typename KC = TCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
1773 Node* find_lower_node(
Node* position,
const K& key)
const
1776 Node* lower_node = ETL_NULLPTR;
1780 Data_Node& data_node = iset::data_cast(*position);
1784 lower_node = position;
1785 if (position->children[kLeft])
1787 position = position->children[kLeft];
1797 position = position->children[kRight];
1802 lower_node = position;
1803 position = position->children[kLeft];
1818 Node* upper_node = ETL_NULLPTR;
1820 Node* node = position;
1824 Data_Node& data_node = iset::data_cast(*node);
1829 node = node->children[kLeft];
1833 node = node->children[kRight];
1835 else if (node->children[kRight])
1852 template <typename K, typename KC = TCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
1853 Node* find_upper_node(
Node* position,
const K& key)
const
1856 Node* upper_node = ETL_NULLPTR;
1858 Node* node = position;
1862 Data_Node& data_node = iset::data_cast(*node);
1867 node = node->children[kLeft];
1871 node = node->children[kRight];
1873 else if (node->children[kRight])
1895 Node* found = position;
1901 Node* critical_parent_node = ETL_NULLPTR;
1908 if (kNeither != found->weight)
1910 critical_node = found;
1914 Data_Node& found_data_node = iset::data_cast(*found);
1923 else if (
node_comp(found_data_node, node))
1926 found->dir = kRight;
1931 found->dir = kNeither;
1934 critical_node = ETL_NULLPTR;
1937 destroy_data_node(node);
1944 if (found->children[found->dir])
1948 if (kNeither != found->children[found->dir]->weight)
1950 critical_parent_node = found;
1954 found = found->children[found->dir];
1962 found = found->children[found->dir];
1972 if (critical_parent_node == ETL_NULLPTR && critical_node ==
root_node)
1976 else if (critical_parent_node == ETL_NULLPTR && critical_node == position)
1982 if (critical_parent_node != ETL_NULLPTR)
1984 balance_node(critical_parent_node->children[critical_parent_node->dir]);
2005 void next_node(
Node*&position)
2010 if (position->children[kRight])
2019 Node* parent = position;
2024 parent = find_parent_node(
root_node, position);
2026 }
while (parent && parent->children[kRight] == position);
2037 void next_node(
const Node*& position)
const
2042 if (position->children[kRight])
2051 const Node* parent = position;
2056 parent = find_parent_node(
root_node, position);
2058 }
while (parent && parent->children[kRight] == position);
2069 void prev_node(
Node*&position)
2080 if (position->children[kLeft])
2089 Node* parent = position;
2094 parent = find_parent_node(
root_node, position);
2096 }
while (parent && parent->children[kLeft] == position);
2107 void prev_node(
const Node*& position)
const
2118 if (position->children[kLeft])
2127 const Node* parent = position;
2132 parent = find_parent_node(
root_node, position);
2134 }
while (parent && parent->children[kLeft] == position);
2151 Node* found_parent = ETL_NULLPTR;
2152 Node* found = ETL_NULLPTR;
2153 Node* replace_parent = ETL_NULLPTR;
2154 Node* replace = position;
2155 Node* balance_parent = ETL_NULLPTR;
2160 Data_Node& replace_data_node = iset::data_cast(*replace);
2166 replace->dir = kLeft;
2168 else if (
node_comp(replace_data_node, key))
2171 replace->dir = kRight;
2176 replace->dir = replace->children[kLeft] ? kLeft : kRight;
2179 found_parent = replace_parent;
2184 if (replace->children[replace->dir] == ETL_NULLPTR)
2194 if ((replace->weight == kNeither) ||
2195 (replace->weight == (1 - replace->dir) &&
2196 replace->children[1 - replace->dir]->weight == kNeither))
2199 balance_parent = replace_parent;
2204 replace_parent = replace;
2205 replace = replace->children[replace->dir];
2214 if (balance->children[balance->dir] == ETL_NULLPTR)
2219 if (balance->weight == kNeither)
2221 balance->weight = 1 - balance->dir;
2223 else if (balance->weight == balance->dir)
2225 balance->weight = kNeither;
2229 int weight = balance->children[1 - balance->dir]->weight;
2231 if (weight == balance->dir)
2234 if (balance_parent == ETL_NULLPTR)
2237 balance->children[1 - balance->dir]->children[balance->dir]->weight);
2241 rotate_3node(balance_parent->children[balance_parent->dir], 1 - balance->dir,
2242 balance->children[1 - balance->dir]->children[balance->dir]->weight);
2247 else if (weight == kNeither)
2250 if (balance_parent == ETL_NULLPTR)
2257 rotate_2node(balance_parent->children[balance_parent->dir], 1 - balance->dir);
2258 balance_parent->children[balance_parent->dir]->weight = balance->dir;
2261 balance->weight = 1 - balance->dir;
2267 if (balance_parent == ETL_NULLPTR)
2273 rotate_2node(balance_parent->children[balance_parent->dir], 1 - balance->dir);
2279 if (balance == found)
2283 found_parent = balance_parent->children[balance_parent->dir];
2285 found_parent->dir = found_parent->children[kLeft] == found ? kLeft : kRight;
2296 balance_parent = balance;
2297 balance = balance->children[balance->dir];
2304 detach_node(found_parent->children[found_parent->dir],
2305 replace_parent->children[replace_parent->dir]);
2323 Data_Node& found_data_node = iset::data_cast(*found);
2329 destroy_data_node(found_data_node);
2338 template <typename K, typename KC = TCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
2339 Node* remove_node(
Node*& position,
const K& key)
2344 Node* found_parent = ETL_NULLPTR;
2345 Node* found = ETL_NULLPTR;
2346 Node* replace_parent = ETL_NULLPTR;
2347 Node* replace = position;
2348 Node* balance_parent = ETL_NULLPTR;
2353 Data_Node& replace_data_node = iset::data_cast(*replace);
2359 replace->dir = kLeft;
2361 else if (
node_comp(replace_data_node, key))
2364 replace->dir = kRight;
2369 replace->dir = replace->children[kLeft] ? kLeft : kRight;
2372 found_parent = replace_parent;
2377 if (replace->children[replace->dir] == ETL_NULLPTR)
2387 if ((replace->weight == kNeither) ||
2388 (replace->weight == (1 - replace->dir) &&
2389 replace->children[1 - replace->dir]->weight == kNeither))
2392 balance_parent = replace_parent;
2397 replace_parent = replace;
2398 replace = replace->children[replace->dir];
2407 if (balance->children[balance->dir] == ETL_NULLPTR)
2412 if (balance->weight == kNeither)
2414 balance->weight = 1 - balance->dir;
2416 else if (balance->weight == balance->dir)
2418 balance->weight = kNeither;
2422 int weight = balance->children[1 - balance->dir]->weight;
2424 if (weight == balance->dir)
2427 if (balance_parent == ETL_NULLPTR)
2430 balance->children[1 - balance->dir]->children[balance->dir]->weight);
2434 rotate_3node(balance_parent->children[balance_parent->dir], 1 - balance->dir,
2435 balance->children[1 - balance->dir]->children[balance->dir]->weight);
2440 else if (weight == kNeither)
2443 if (balance_parent == ETL_NULLPTR)
2450 rotate_2node(balance_parent->children[balance_parent->dir], 1 - balance->dir);
2451 balance_parent->children[balance_parent->dir]->weight = balance->dir;
2454 balance->weight = 1 - balance->dir;
2460 if (balance_parent == ETL_NULLPTR)
2466 rotate_2node(balance_parent->children[balance_parent->dir], 1 - balance->dir);
2472 if (balance == found)
2476 found_parent = balance_parent->children[balance_parent->dir];
2478 found_parent->dir = found_parent->children[kLeft] == found ? kLeft : kRight;
2489 balance_parent = balance;
2490 balance = balance->children[balance->dir];
2497 detach_node(found_parent->children[found_parent->dir],
2498 replace_parent->children[replace_parent->dir]);
2516 Data_Node& found_data_node = iset::data_cast(*found);
2522 destroy_data_node(found_data_node);
2536#if defined(ETL_POLYMORPHIC_SET) || defined(ETL_POLYMORPHIC_CONTAINERS)