|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Top-down splay tree - Self-adjusting BST with amortized O(log n) operations. More...
#include <tpl_splay_tree.H>
Classes | |
| struct | Iterator |
| Iterator over the nodes. More... | |
Public Types | |
| using | Node = NodeType< Key > |
| using | key_type = Key |
| The key type stored in the node. | |
Public Member Functions | |
| Compare & | key_comp () noexcept |
| Returns a reference to the comparison criteria. | |
| Compare & | get_compare () noexcept |
| void | splay (const Key &key) noexcept |
| search key within tree and splay that node, if not found it return Node::NullPtr | |
| GenTdSplayTree (Compare __cmp=Compare()) noexcept | |
| Constructor. | |
| void | swap (GenTdSplayTree &tree) noexcept |
| virtual | ~GenTdSplayTree ()=default |
| Destructor. | |
| Node * | insert (Node *p) noexcept |
| Inserts a node in a top-down splay tree. | |
| Node * | insert_dup (Node *p) noexcept |
| Node * | search (const Key &key) noexcept |
| Searches a key in a top-down splay tree. | |
| Node * | search_or_insert (Node *p) noexcept |
| Node * | remove (const Key &key) noexcept |
| Remove a key from a top down splay tree. | |
| Node *& | getRoot () noexcept |
| Get the top-down splay tree's root. | |
| bool | verify () const |
Private Member Functions | |
| signed char | splay_impl (const Key &key) noexcept |
| Node * | __insert (Node *p) noexcept |
Private Attributes | |
| Node | headnode |
| Node * | head |
| Node *& | root |
| Compare | cmp |
Static Private Attributes | |
| static constexpr signed char | CmpLess = -1 |
| static constexpr signed char | CmpEqual = 0 |
| static constexpr signed char | CmpGreater = 1 |
Top-down splay tree - Self-adjusting BST with amortized O(log n) operations.
GenTdSplayTree implements a splay tree, a self-adjusting binary search tree where every access operation (search, insert, delete) moves the accessed node to the root through a sequence of tree rotations called "splaying".
These rotations ensure amortized efficiency by reducing tree depth.
| NodeType | Node template (BinNode or BinNodeVtl). |
| Key | The type of keys stored in the tree. |
| Compare | Comparison functor for ordering keys. |
Definition at line 136 of file tpl_splay_tree.H.
| using GenTdSplayTree< NodeType, Key, Compare >::key_type = Key |
The key type stored in the node.
Definition at line 213 of file tpl_splay_tree.H.
| using GenTdSplayTree< NodeType, Key, Compare >::Node = NodeType<Key> |
Definition at line 139 of file tpl_splay_tree.H.
|
inlinenoexcept |
Constructor.
Definition at line 229 of file tpl_splay_tree.H.
|
virtualdefault |
Destructor.
|
inlineprivatenoexcept |
Definition at line 245 of file tpl_splay_tree.H.
References GenTdSplayTree< NodeType, Key, Compare >::cmp, Aleph::divide_and_conquer_partition_dp(), KEY, LLINK, RLINK, and GenTdSplayTree< NodeType, Key, Compare >::root.
Referenced by GenTdSplayTree< NodeType, Key, Compare >::insert(), GenTdSplayTree< NodeType, Key, Compare >::insert_dup(), and GenTdSplayTree< NodeType, Key, Compare >::search_or_insert().
|
inlinenoexcept |
Definition at line 219 of file tpl_splay_tree.H.
References GenTdSplayTree< NodeType, Key, Compare >::key_comp().
|
inlinenoexcept |
Get the top-down splay tree's root.
Definition at line 370 of file tpl_splay_tree.H.
References GenTdSplayTree< NodeType, Key, Compare >::root.
Referenced by main(), TEST(), and write_splay().
|
inlinenoexcept |
Inserts a node in a top-down splay tree.
| p | a pointer to the node to be inserted |
Definition at line 271 of file tpl_splay_tree.H.
References GenTdSplayTree< NodeType, Key, Compare >::__insert(), Aleph::and, GenTdSplayTree< NodeType, Key, Compare >::CmpEqual, Aleph::divide_and_conquer_partition_dp(), KEY, LLINK, RLINK, GenTdSplayTree< NodeType, Key, Compare >::root, and GenTdSplayTree< NodeType, Key, Compare >::splay_impl().
Referenced by main(), and write_splay().
|
inlinenoexcept |
Definition at line 290 of file tpl_splay_tree.H.
References GenTdSplayTree< NodeType, Key, Compare >::__insert(), Aleph::and, Aleph::divide_and_conquer_partition_dp(), KEY, LLINK, RLINK, GenTdSplayTree< NodeType, Key, Compare >::root, and GenTdSplayTree< NodeType, Key, Compare >::splay_impl().
|
inlinenoexcept |
Returns a reference to the comparison criteria.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Definition at line 216 of file tpl_splay_tree.H.
References GenTdSplayTree< NodeType, Key, Compare >::cmp.
Referenced by GenTdSplayTree< NodeType, Key, Compare >::get_compare().
|
inlinenoexcept |
Remove a key from a top down splay tree.
Searches a key in a top down splay tree and remove the containing the key if this is found.
| key | to search |
Definition at line 343 of file tpl_splay_tree.H.
References GenTdSplayTree< NodeType, Key, Compare >::CmpEqual, Aleph::divide_and_conquer_partition_dp(), LLINK, RLINK, GenTdSplayTree< NodeType, Key, Compare >::root, and GenTdSplayTree< NodeType, Key, Compare >::splay_impl().
|
inlinenoexcept |
Searches a key in a top-down splay tree.
| key | key to search |
Definition at line 311 of file tpl_splay_tree.H.
References GenTdSplayTree< NodeType, Key, Compare >::CmpEqual, Aleph::divide_and_conquer_partition_dp(), GenTdSplayTree< NodeType, Key, Compare >::root, and GenTdSplayTree< NodeType, Key, Compare >::splay_impl().
Referenced by main(), TEST(), and write_splay().
|
inlinenoexcept |
Definition at line 321 of file tpl_splay_tree.H.
References GenTdSplayTree< NodeType, Key, Compare >::__insert(), GenTdSplayTree< NodeType, Key, Compare >::CmpEqual, Aleph::divide_and_conquer_partition_dp(), KEY, GenTdSplayTree< NodeType, Key, Compare >::root, and GenTdSplayTree< NodeType, Key, Compare >::splay_impl().
|
inlinenoexcept |
search key within tree and splay that node, if not found it return Node::NullPtr
Definition at line 223 of file tpl_splay_tree.H.
References Aleph::divide_and_conquer_partition_dp(), and GenTdSplayTree< NodeType, Key, Compare >::splay_impl().
|
inlineprivatenoexcept |
Definition at line 149 of file tpl_splay_tree.H.
References GenTdSplayTree< NodeType, Key, Compare >::cmp, GenTdSplayTree< NodeType, Key, Compare >::CmpEqual, GenTdSplayTree< NodeType, Key, Compare >::CmpGreater, GenTdSplayTree< NodeType, Key, Compare >::CmpLess, Aleph::divide_and_conquer_partition_dp(), KEY, l, LLINK, r, RLINK, GenTdSplayTree< NodeType, Key, Compare >::root, Aleph::rotate_to_left(), and Aleph::rotate_to_right().
Referenced by GenTdSplayTree< NodeType, Key, Compare >::insert(), GenTdSplayTree< NodeType, Key, Compare >::insert_dup(), GenTdSplayTree< NodeType, Key, Compare >::remove(), GenTdSplayTree< NodeType, Key, Compare >::search(), GenTdSplayTree< NodeType, Key, Compare >::search_or_insert(), and GenTdSplayTree< NodeType, Key, Compare >::splay().
|
inlinenoexcept |
Definition at line 235 of file tpl_splay_tree.H.
References GenTdSplayTree< NodeType, Key, Compare >::cmp, and GenTdSplayTree< NodeType, Key, Compare >::root.
|
inline |
Definition at line 375 of file tpl_splay_tree.H.
References Aleph::check_bst(), GenTdSplayTree< NodeType, Key, Compare >::cmp, and GenTdSplayTree< NodeType, Key, Compare >::root.
Referenced by TEST().
|
private |
Definition at line 144 of file tpl_splay_tree.H.
Referenced by GenTdSplayTree< NodeType, Key, Compare >::__insert(), GenTdSplayTree< NodeType, Key, Compare >::key_comp(), GenTdSplayTree< NodeType, Key, Compare >::splay_impl(), GenTdSplayTree< NodeType, Key, Compare >::swap(), and GenTdSplayTree< NodeType, Key, Compare >::verify().
|
staticconstexprprivate |
Definition at line 146 of file tpl_splay_tree.H.
Referenced by GenTdSplayTree< NodeType, Key, Compare >::insert(), GenTdSplayTree< NodeType, Key, Compare >::remove(), GenTdSplayTree< NodeType, Key, Compare >::search(), GenTdSplayTree< NodeType, Key, Compare >::search_or_insert(), and GenTdSplayTree< NodeType, Key, Compare >::splay_impl().
|
staticconstexprprivate |
Definition at line 147 of file tpl_splay_tree.H.
Referenced by GenTdSplayTree< NodeType, Key, Compare >::splay_impl().
|
staticconstexprprivate |
Definition at line 145 of file tpl_splay_tree.H.
Referenced by GenTdSplayTree< NodeType, Key, Compare >::splay_impl().
|
private |
Definition at line 143 of file tpl_splay_tree.H.
|
private |
Definition at line 142 of file tpl_splay_tree.H.
|
private |
Definition at line 143 of file tpl_splay_tree.H.
Referenced by GenTdSplayTree< NodeType, Key, Compare >::__insert(), GenTdSplayTree< NodeType, Key, Compare >::getRoot(), GenTdSplayTree< NodeType, Key, Compare >::insert(), GenTdSplayTree< NodeType, Key, Compare >::insert_dup(), GenTdSplayTree< NodeType, Key, Compare >::remove(), GenTdSplayTree< NodeType, Key, Compare >::search(), GenTdSplayTree< NodeType, Key, Compare >::search_or_insert(), GenTdSplayTree< NodeType, Key, Compare >::splay_impl(), GenTdSplayTree< NodeType, Key, Compare >::swap(), and GenTdSplayTree< NodeType, Key, Compare >::verify().