46# ifndef TPL_SPLAY_TREE_H
47# define TPL_SPLAY_TREE_H
133template <
template <
class>
class NodeType,
typename Key,
class Compare>
174 else if (
cmp(
tk, key))
201 LLINK(t) = headNode.getR();
202 RLINK(t) = headNode.getL();
221 void splay(
const Key & key)
noexcept
235 std::swap(
root, tree.root);
236 std::swap(
cmp, tree.cmp);
245 const Key &
pk =
KEY(p);
271 assert(p != Node::NullPtr);
275 if (
root == Node::NullPtr)
278 const Key & key =
KEY(p);
290 assert(p != Node::NullPtr);
294 if (
root == Node::NullPtr)
311 if (
root == Node::NullPtr)
321 if (
root == Node::NullPtr)
324 const Key & key =
KEY(p);
343 if (
root == Node::NullPtr)
391template <
typename Key,
class Compare = Aleph::less<Key>>
399template <
typename Key,
class Compare = Aleph::less<Key>>
Inorder iterator on the nodes of a binary tree.
Top-down splay tree - Self-adjusting BST with amortized O(log n) operations.
static constexpr signed char CmpEqual
Key key_type
The key type stored in the node.
Compare & get_compare() noexcept
static constexpr signed char CmpLess
Node *& getRoot() noexcept
Get the top-down splay tree's root.
Compare & key_comp() noexcept
Returns a reference to the comparison criteria.
virtual ~GenTdSplayTree()=default
Destructor.
Node * insert_dup(Node *p) noexcept
GenTdSplayTree(Compare __cmp=Compare()) noexcept
Constructor.
static constexpr signed char CmpGreater
Node * remove(const Key &key) noexcept
Remove a key from a top down splay tree.
Node * insert(Node *p) noexcept
Inserts a node in a top-down splay tree.
Node * search(const Key &key) noexcept
Searches a key in a top-down splay tree.
Node * search_or_insert(Node *p) noexcept
signed char splay_impl(const Key &key) noexcept
void swap(GenTdSplayTree &tree) noexcept
Node * __insert(Node *p) noexcept
void splay(const Key &key) noexcept
search key within tree and splay that node, if not found it return Node::NullPtr
Node * rotate_to_left(Node *p) noexcept
Rotate to the left the tree with root p
Node * rotate_to_right(Node *p) noexcept
Rotate to the right the tree with root p
bool check_bst(Node *p, const Compare &cmp=Compare())
Return true if p is a binary search tree.
constexpr Node *& RLINK(Node *p) noexcept
Return the right tree of p.
constexpr Node *& LLINK(Node *p) noexcept
Return a pointer to left subtree.
Main namespace for Aleph-w library functions.
DynList< T > maps(const C &c, Op op)
Classic map operation.
Iterator() noexcept=default
Default constructor creates an "end" iterator.
Utility functions for binary tree operations.
Basic binary tree node definitions.