463 typedef TKey key_type;
464 typedef TKey value_type;
465 typedef TCompare key_compare;
466 typedef TCompare value_compare;
467 typedef value_type& reference;
468 typedef const value_type& const_reference;
470 typedef value_type&& rvalue_reference;
472 typedef value_type* pointer;
473 typedef const value_type* const_pointer;
474 typedef size_t size_type;
483 explicit Data_Node(value_type value_)
499 return compare(node1.value, node2.value);
504 return compare(node.value, key);
510 return compare(key, node.value);
514 template <typename K, typename KC = TCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
517 return compare(node.value, key);
520 template <typename K, typename KC = TCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
524 return compare(key, node.value);
531 etl::ipool* p_node_pool;
556 return static_cast<const Data_Node*
>(p_node);
564 return static_cast<const Data_Node&
>(node);
572 class iterator :
public etl::iterator<ETL_OR_STD::bidirectional_iterator_tag, value_type>
577 friend class const_iterator;
581 , p_node(ETL_NULLPTR)
587 , p_node(ETL_NULLPTR)
591 iterator(iset&
set,
Node* node)
597 iterator(
const iterator& other)
599 , p_node(other.p_node)
605 iterator& operator++()
607 p_set->next_node(p_node);
611 iterator operator++(
int)
613 iterator temp(*
this);
614 p_set->next_node(p_node);
618 iterator& operator--()
620 p_set->prev_node(p_node);
624 iterator operator--(
int)
626 iterator temp(*
this);
627 p_set->prev_node(p_node);
631 iterator& operator=(
const iterator& other)
634 p_node = other.p_node;
638 reference operator*()
const
640 return iset::data_cast(p_node)->value;
643 pointer operator&()
const
645 return &(iset::data_cast(p_node)->value);
648 pointer operator->()
const
650 return &(iset::data_cast(p_node)->value);
653 friend bool operator==(
const iterator& lhs,
const iterator& rhs)
655 return lhs.p_set == rhs.p_set && lhs.p_node == rhs.p_node;
658 friend bool operator!=(
const iterator& lhs,
const iterator& rhs)
660 return !(lhs == rhs);
676 class const_iterator :
public etl::iterator<ETL_OR_STD::bidirectional_iterator_tag, const value_type>
684 , p_node(ETL_NULLPTR)
688 const_iterator(
const iset&
set)
690 , p_node(ETL_NULLPTR)
694 const_iterator(
const iset&
set,
const Node* node)
702 , p_node(other.p_node)
706 const_iterator(
const const_iterator& other)
708 , p_node(other.p_node)
714 const_iterator& operator++()
716 p_set->next_node(p_node);
720 const_iterator operator++(
int)
722 const_iterator temp(*
this);
723 p_set->next_node(p_node);
727 const_iterator& operator--()
729 p_set->prev_node(p_node);
733 const_iterator operator--(
int)
735 const_iterator temp(*
this);
736 p_set->prev_node(p_node);
740 const_iterator& operator=(
const const_iterator& other)
743 p_node = other.p_node;
747 const_reference operator*()
const
749 return iset::data_cast(p_node)->value;
752 const_pointer operator&()
const
754 return iset::data_cast(p_node)->value;
757 const_pointer operator->()
const
759 return &(iset::data_cast(p_node)->value);
762 friend bool operator==(
const const_iterator& lhs,
const const_iterator& rhs)
764 return lhs.p_set == rhs.p_set && lhs.p_node == rhs.p_node;
767 friend bool operator!=(
const const_iterator& lhs,
const const_iterator& rhs)
769 return !(lhs == rhs);
788 typedef typename etl::iterator_traits<iterator>::difference_type difference_type;
790 typedef ETL_OR_STD::reverse_iterator<iterator> reverse_iterator;
791 typedef ETL_OR_STD::reverse_iterator<const_iterator> const_reverse_iterator;
820 while (from != rhs.end())
825 this->
insert(etl::move(*from));
887 return reverse_iterator(
iterator(*
this));
909 const_reverse_iterator
rend()
const
925 const_reverse_iterator
crend()
const
938 template <
typename TIterator>
939 void assign(TIterator first, TIterator last)
960 return find_node(
root_node, key) ? 1 : 0;
965 template <typename K, typename KC = TCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
968 return find_node(
root_node, key) ? 1 : 0;
978 return ETL_OR_STD::make_pair<iterator, iterator>(
iterator(*
this, find_lower_node(
root_node, key)),
984 template <typename K, typename KC = TCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
985 ETL_OR_STD::pair<iterator, iterator>
equal_range(
const K& key)
987 return ETL_OR_STD::make_pair<iterator, iterator>(
iterator(*
this, find_lower_node(
root_node, key)),
998 return ETL_OR_STD::make_pair<const_iterator, const_iterator>(
const_iterator(*
this, find_lower_node(
root_node, key)),
1004 template <typename K, typename KC = TCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
1005 ETL_OR_STD::pair<const_iterator, const_iterator>
equal_range(
const K& key)
const
1007 return ETL_OR_STD::make_pair<const_iterator, const_iterator>(
const_iterator(*
this, find_lower_node(
root_node, key)),
1027 Node*& reference_node = find_node(
root_node, position.p_node);
1028 iterator next(*
this, reference_node);
1042 return remove_node(
root_node, key_value) ? 1 : 0;
1047 template <typename K, typename KC = TCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
1051 return remove_node(
root_node, etl::forward<K>(key_value)) ? 1 : 0;
1060 while (first != last)
1062 first =
erase(first);
1065 return last.to_iterator();
1080 template <typename K, typename KC = TCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
1099 template <typename K, typename KC = TCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
1112 ETL_OR_STD::pair<iterator, bool>
insert(const_reference value)
1115 Node* inserted_node = ETL_NULLPTR;
1116 bool inserted =
false;
1123 ETL_ASSERT_FAIL(ETL_ERROR(
set_full));
1127 return ETL_OR_STD::make_pair(iter,
false);
1132 Data_Node& node = allocate_data_node(value);
1135 inserted_node = insert_node(
root_node, node);
1136 inserted = inserted_node == &node;
1139 return ETL_OR_STD::make_pair(
iterator(*
this, inserted_node), inserted);
1149 ETL_OR_STD::pair<iterator, bool>
insert(rvalue_reference value)
1152 Node* inserted_node = ETL_NULLPTR;
1153 bool inserted =
false;
1160 ETL_ASSERT_FAIL(ETL_ERROR(
set_full));
1164 return ETL_OR_STD::make_pair(iter,
false);
1169 Data_Node& node = allocate_data_node(etl::move(value));
1172 inserted_node = insert_node(
root_node, node);
1173 inserted = inserted_node == &node;
1176 return ETL_OR_STD::make_pair(
iterator(*
this, inserted_node), inserted);
1190 Node* inserted_node = ETL_NULLPTR;
1197 ETL_ASSERT_FAIL(ETL_ERROR(
set_full));
1206 Data_Node& node = allocate_data_node(value);
1209 inserted_node = insert_node(
root_node, node);
1212 return iterator(*
this, inserted_node);
1226 Node* inserted_node = ETL_NULLPTR;
1233 ETL_ASSERT_FAIL(ETL_ERROR(
set_full));
1242 Data_Node& node = allocate_data_node(etl::move(value));
1245 inserted_node = insert_node(
root_node, node);
1248 return iterator(*
this, inserted_node);
1260 template <
class TIterator>
1263 while (first != last)
1270#if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT
1274 template <
typename... Args>
1275 ETL_OR_STD::pair<iterator, bool>
emplace(Args&&... args)
1283 value_type temp_value(etl::forward<Args>(args)...);
1286 if (position ==
end())
1288 ETL_ASSERT_FAIL(ETL_ERROR(
set_full));
1289 return ETL_OR_STD::make_pair(
end(),
false);
1292 return ETL_OR_STD::make_pair(position,
false);
1296 Data_Node* p_node = allocate_data_node();
1297 ::new ((
void*)&p_node->value) value_type(etl::forward<Args>(args)...);
1298 ETL_INCREMENT_DEBUG_COUNT;
1302 bool inserted = inserted_node == p_node;
1304 return ETL_OR_STD::make_pair(
iterator(*
this, inserted_node), inserted);
1310 ETL_OR_STD::pair<iterator, bool>
emplace(const_reference value)
1318 template <
typename T1>
1319 ETL_OR_STD::pair<iterator, bool>
emplace(
const T1& value1)
1327 value_type temp_value(value1);
1330 if (position ==
end())
1332 ETL_ASSERT_FAIL(ETL_ERROR(
set_full));
1333 return ETL_OR_STD::make_pair(
end(),
false);
1336 return ETL_OR_STD::make_pair(position,
false);
1339 Data_Node* p_node = allocate_data_node();
1340 ::new ((
void*)&p_node->value) value_type(value1);
1341 ETL_INCREMENT_DEBUG_COUNT;
1344 bool inserted = inserted_node == p_node;
1346 return ETL_OR_STD::make_pair(
iterator(*
this, inserted_node), inserted);
1363 template <typename K, typename KC = TCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
1383 template <typename K, typename KC = TCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
1403 template <typename K, typename KC = TCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
1423 template <typename K, typename KC = TCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
1456 template <typename K, typename KC = TCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
1470 , p_node_pool(&node_pool)
1481 while (item !=
end())
1492 Data_Node& allocate_data_node(const_reference value)
1494 Data_Node* node = allocate_data_node();
1495 ::new ((
void*)&node->value)
value_type(value);
1496 ETL_INCREMENT_DEBUG_COUNT;
1504 Data_Node& allocate_data_node(rvalue_reference value)
1506 Data_Node* node = allocate_data_node();
1507 ::new ((
void*)&node->value) value_type(etl::move(value));
1508 ETL_INCREMENT_DEBUG_COUNT;
1519 return (p_node_pool->*func)();
1527 node.value.~value_type();
1528 p_node_pool->release(&node);
1529 ETL_DECREMENT_DEBUG_COUNT;
1537 Node* found = position;
1541 Data_Node& found_data_node = iset::data_cast(*found);
1547 found = found->children[kLeft];
1549 else if (
node_comp(found_data_node, key))
1552 found = found->children[kRight];
1567 template <typename K, typename KC = TCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
1568 Node* find_node(
Node* position,
const K& key)
1570 Node* found = position;
1574 Data_Node& found_data_node = iset::data_cast(*found);
1580 found = found->children[kLeft];
1582 else if (
node_comp(found_data_node, key))
1585 found = found->children[kRight];
1604 const Node* found = position;
1608 const Data_Node& found_data_node = iset::data_cast(*found);
1614 found = found->children[kLeft];
1616 else if (
node_comp(found_data_node, key))
1619 found = found->children[kRight];
1634 template <typename K, typename KC = TCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
1635 const Node* find_node(
const Node* position,
const K& key)
const
1637 const Node* found = position;
1641 const Data_Node& found_data_node = iset::data_cast(*found);
1647 found = found->children[kLeft];
1649 else if (
node_comp(found_data_node, key))
1652 found = found->children[kRight];
1671 Node* found = position;
1674 if (found->children[kLeft] == node)
1676 return found->children[kLeft];
1678 else if (found->children[kRight] == node)
1680 return found->children[kRight];
1686 Data_Node& found_data_node = iset::data_cast(*found);
1687 const Data_Node& data_node = iset::data_cast(*node);
1690 if (
node_comp(data_node, found_data_node))
1693 found = found->children[kLeft];
1695 else if (
node_comp(found_data_node, data_node))
1698 found = found->children[kRight];
1716 Node* find_parent_node(
Node* position,
const Node* node)
1719 Node* found = ETL_NULLPTR;
1723 if (position && node && position != node)
1728 if (position->children[kLeft] != node && position->children[kRight] != node)
1732 const Data_Node& node_data_node = iset::data_cast(*node);
1733 Data_Node& position_data_node = iset::data_cast(*position);
1735 if (
node_comp(node_data_node, position_data_node))
1738 position = position->children[kLeft];
1740 else if (
node_comp(position_data_node, node_data_node))
1743 position = position->children[kRight];
1765 const Node* find_parent_node(
const Node* position,
const Node* node)
const
1768 const Node* found = ETL_NULLPTR;
1772 if (position && node && position != node)
1777 if (position->children[kLeft] != node && position->children[kRight] != node)
1781 const Data_Node& node_data_node = iset::data_cast(*node);
1782 const Data_Node& position_data_node = iset::data_cast(*position);
1784 if (
node_comp(node_data_node, position_data_node))
1787 position = position->children[kLeft];
1789 else if (
node_comp(position_data_node, node_data_node))
1792 position = position->children[kRight];
1816 Node* lower_node = ETL_NULLPTR;
1820 Data_Node& data_node = iset::data_cast(*position);
1824 lower_node = position;
1825 if (position->children[kLeft])
1827 position = position->children[kLeft];
1837 position = position->children[kRight];
1842 lower_node = position;
1843 position = position->children[kLeft];
1853 template <typename K, typename KC = TCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
1854 Node* find_lower_node(
Node* position,
const K& key)
const
1857 Node* lower_node = ETL_NULLPTR;
1861 Data_Node& data_node = iset::data_cast(*position);
1865 lower_node = position;
1866 if (position->children[kLeft])
1868 position = position->children[kLeft];
1878 position = position->children[kRight];
1883 lower_node = position;
1884 position = position->children[kLeft];
1899 Node* upper_node = ETL_NULLPTR;
1901 Node* node = position;
1905 Data_Node& data_node = iset::data_cast(*node);
1910 node = node->children[kLeft];
1914 node = node->children[kRight];
1916 else if (node->children[kRight])
1933 template <typename K, typename KC = TCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
1934 Node* find_upper_node(
Node* position,
const K& key)
const
1937 Node* upper_node = ETL_NULLPTR;
1939 Node* node = position;
1943 Data_Node& data_node = iset::data_cast(*node);
1948 node = node->children[kLeft];
1952 node = node->children[kRight];
1954 else if (node->children[kRight])
1976 Node* found = position;
1982 Node* critical_parent_node = ETL_NULLPTR;
1989 if (kNeither != found->weight)
1991 critical_node = found;
1996 Data_Node& found_data_node = iset::data_cast(*found);
2005 else if (
node_comp(found_data_node, node))
2008 found->dir = kRight;
2013 found->dir = kNeither;
2016 critical_node = ETL_NULLPTR;
2019 destroy_data_node(node);
2026 if (found->children[found->dir])
2030 if (kNeither != found->children[found->dir]->weight)
2032 critical_parent_node = found;
2036 found = found->children[found->dir];
2044 found = found->children[found->dir];
2054 if (critical_parent_node == ETL_NULLPTR && critical_node ==
root_node)
2058 else if (critical_parent_node == ETL_NULLPTR && critical_node == position)
2064 if (critical_parent_node != ETL_NULLPTR)
2066 balance_node(critical_parent_node->children[critical_parent_node->dir]);
2087 void next_node(
Node*& position)
2092 if (position->children[kRight])
2101 Node* parent = position;
2106 parent = find_parent_node(
root_node, position);
2108 }
while (parent && parent->children[kRight] == position);
2119 void next_node(
const Node*& position)
const
2124 if (position->children[kRight])
2133 const Node* parent = position;
2138 parent = find_parent_node(
root_node, position);
2140 }
while (parent && parent->children[kRight] == position);
2151 void prev_node(
Node*& position)
2162 if (position->children[kLeft])
2171 Node* parent = position;
2176 parent = find_parent_node(
root_node, position);
2178 }
while (parent && parent->children[kLeft] == position);
2189 void prev_node(
const Node*& position)
const
2200 if (position->children[kLeft])
2209 const Node* parent = position;
2214 parent = find_parent_node(
root_node, position);
2216 }
while (parent && parent->children[kLeft] == position);
2233 Node* found_parent = ETL_NULLPTR;
2234 Node* found = ETL_NULLPTR;
2235 Node* replace_parent = ETL_NULLPTR;
2236 Node* replace = position;
2237 Node* balance_parent = ETL_NULLPTR;
2242 Data_Node& replace_data_node = iset::data_cast(*replace);
2248 replace->dir = kLeft;
2250 else if (
node_comp(replace_data_node, key))
2253 replace->dir = kRight;
2258 replace->dir = replace->children[kLeft] ? kLeft : kRight;
2261 found_parent = replace_parent;
2266 if (replace->children[replace->dir] == ETL_NULLPTR)
2276 if ((replace->weight == kNeither) || (replace->weight == (1 - replace->dir) && replace->children[1 - replace->dir]->weight == kNeither))
2279 balance_parent = replace_parent;
2284 replace_parent = replace;
2285 replace = replace->children[replace->dir];
2294 if (balance->children[balance->dir] == ETL_NULLPTR)
2299 if (balance->weight == kNeither)
2301 balance->weight = 1 - balance->dir;
2303 else if (balance->weight == balance->dir)
2305 balance->weight = kNeither;
2309 int weight = balance->children[1 - balance->dir]->weight;
2311 if (weight == balance->dir)
2314 if (balance_parent == ETL_NULLPTR)
2316 rotate_3node(
root_node, 1 - balance->dir, balance->children[1 - balance->dir]->children[balance->dir]->weight);
2320 rotate_3node(balance_parent->children[balance_parent->dir], 1 - balance->dir,
2321 balance->children[1 - balance->dir]->children[balance->dir]->weight);
2326 else if (weight == kNeither)
2329 if (balance_parent == ETL_NULLPTR)
2336 rotate_2node(balance_parent->children[balance_parent->dir], 1 - balance->dir);
2337 balance_parent->children[balance_parent->dir]->weight = balance->dir;
2341 balance->weight = 1 - balance->dir;
2347 if (balance_parent == ETL_NULLPTR)
2353 rotate_2node(balance_parent->children[balance_parent->dir], 1 - balance->dir);
2359 if (balance == found)
2363 found_parent = balance_parent->children[balance_parent->dir];
2365 found_parent->dir = found_parent->children[kLeft] == found ? kLeft : kRight;
2376 balance_parent = balance;
2377 balance = balance->children[balance->dir];
2384 detach_node(found_parent->children[found_parent->dir], replace_parent->children[replace_parent->dir]);
2402 Data_Node& found_data_node = iset::data_cast(*found);
2408 destroy_data_node(found_data_node);
2417 template <typename K, typename KC = TCompare, etl::enable_if_t<comparator_is_transparent<KC>::value,
int> = 0>
2418 Node* remove_node(
Node*& position,
const K& key)
2423 Node* found_parent = ETL_NULLPTR;
2424 Node* found = ETL_NULLPTR;
2425 Node* replace_parent = ETL_NULLPTR;
2426 Node* replace = position;
2427 Node* balance_parent = ETL_NULLPTR;
2432 Data_Node& replace_data_node = iset::data_cast(*replace);
2438 replace->dir = kLeft;
2440 else if (
node_comp(replace_data_node, key))
2443 replace->dir = kRight;
2448 replace->dir = replace->children[kLeft] ? kLeft : kRight;
2451 found_parent = replace_parent;
2456 if (replace->children[replace->dir] == ETL_NULLPTR)
2466 if ((replace->weight == kNeither) || (replace->weight == (1 - replace->dir) && replace->children[1 - replace->dir]->weight == kNeither))
2469 balance_parent = replace_parent;
2474 replace_parent = replace;
2475 replace = replace->children[replace->dir];
2484 if (balance->children[balance->dir] == ETL_NULLPTR)
2489 if (balance->weight == kNeither)
2491 balance->weight = 1 - balance->dir;
2493 else if (balance->weight == balance->dir)
2495 balance->weight = kNeither;
2499 int weight = balance->children[1 - balance->dir]->weight;
2501 if (weight == balance->dir)
2504 if (balance_parent == ETL_NULLPTR)
2506 rotate_3node(
root_node, 1 - balance->dir, balance->children[1 - balance->dir]->children[balance->dir]->weight);
2510 rotate_3node(balance_parent->children[balance_parent->dir], 1 - balance->dir,
2511 balance->children[1 - balance->dir]->children[balance->dir]->weight);
2516 else if (weight == kNeither)
2519 if (balance_parent == ETL_NULLPTR)
2526 rotate_2node(balance_parent->children[balance_parent->dir], 1 - balance->dir);
2527 balance_parent->children[balance_parent->dir]->weight = balance->dir;
2531 balance->weight = 1 - balance->dir;
2537 if (balance_parent == ETL_NULLPTR)
2543 rotate_2node(balance_parent->children[balance_parent->dir], 1 - balance->dir);
2549 if (balance == found)
2553 found_parent = balance_parent->children[balance_parent->dir];
2555 found_parent->dir = found_parent->children[kLeft] == found ? kLeft : kRight;
2566 balance_parent = balance;
2567 balance = balance->children[balance->dir];
2574 detach_node(found_parent->children[found_parent->dir], replace_parent->children[replace_parent->dir]);
2592 Data_Node& found_data_node = iset::data_cast(*found);
2598 destroy_data_node(found_data_node);
2612#if defined(ETL_POLYMORPHIC_SET) || defined(ETL_POLYMORPHIC_CONTAINERS)