|
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 134 of file tpl_splay_tree.H.
| using GenTdSplayTree< NodeType, Key, Compare >::key_type = Key |
The key type stored in the node.
Definition at line 211 of file tpl_splay_tree.H.
| using GenTdSplayTree< NodeType, Key, Compare >::Node = NodeType<Key> |
Definition at line 137 of file tpl_splay_tree.H.
|
inlinenoexcept |
Constructor.
Definition at line 227 of file tpl_splay_tree.H.
|
virtualdefault |
Destructor.
|
inlineprivatenoexcept |
Definition at line 243 of file tpl_splay_tree.H.
References GenTdSplayTree< NodeType, Key, Compare >::cmp, KEY, Aleph::LLINK(), Aleph::maps(), Aleph::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 217 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 368 of file tpl_splay_tree.H.
References GenTdSplayTree< NodeType, Key, Compare >::root.
Referenced by 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 269 of file tpl_splay_tree.H.
References GenTdSplayTree< NodeType, Key, Compare >::__insert(), GenTdSplayTree< NodeType, Key, Compare >::CmpEqual, KEY, Aleph::LLINK(), Aleph::maps(), Aleph::RLINK(), GenTdSplayTree< NodeType, Key, Compare >::root, and GenTdSplayTree< NodeType, Key, Compare >::splay_impl().
Referenced by write_splay().
|
inlinenoexcept |
Definition at line 288 of file tpl_splay_tree.H.
References GenTdSplayTree< NodeType, Key, Compare >::__insert(), KEY, Aleph::LLINK(), Aleph::maps(), Aleph::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 214 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 341 of file tpl_splay_tree.H.
References GenTdSplayTree< NodeType, Key, Compare >::CmpEqual, Aleph::LLINK(), Aleph::maps(), Aleph::HTList::reset(), Aleph::RLINK(), GenTdSplayTree< NodeType, Key, Compare >::root, and GenTdSplayTree< NodeType, Key, Compare >::splay_impl().
Referenced by TEST().
|
inlinenoexcept |
Searches a key in a top-down splay tree.
| key | key to search |
Definition at line 309 of file tpl_splay_tree.H.
References GenTdSplayTree< NodeType, Key, Compare >::CmpEqual, Aleph::maps(), GenTdSplayTree< NodeType, Key, Compare >::root, and GenTdSplayTree< NodeType, Key, Compare >::splay_impl().
Referenced by TEST(), and write_splay().
|
inlinenoexcept |
|
inlinenoexcept |
search key within tree and splay that node, if not found it return Node::NullPtr
Definition at line 221 of file tpl_splay_tree.H.
References Aleph::maps(), and GenTdSplayTree< NodeType, Key, Compare >::splay_impl().
|
inlineprivatenoexcept |
Definition at line 147 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, KEY, l, Aleph::LLINK(), Aleph::maps(), Aleph::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 233 of file tpl_splay_tree.H.
References GenTdSplayTree< NodeType, Key, Compare >::cmp, and GenTdSplayTree< NodeType, Key, Compare >::root.
|
inline |
Definition at line 373 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 142 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 144 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 145 of file tpl_splay_tree.H.
Referenced by GenTdSplayTree< NodeType, Key, Compare >::splay_impl().
|
staticconstexprprivate |
Definition at line 143 of file tpl_splay_tree.H.
Referenced by GenTdSplayTree< NodeType, Key, Compare >::splay_impl().
|
private |
Definition at line 141 of file tpl_splay_tree.H.
|
private |
Definition at line 140 of file tpl_splay_tree.H.
|
private |
Definition at line 141 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().