48# ifndef TPL_SPLAY_TREE_RK_H
49# define TPL_SPLAY_TREE_RK_H
106template <
template <
class>
class NodeType,
typename Key,
class Compare>
123 Node * head_ptr = &header;
152 else if (
cmp(
tk, key))
220 void splay(
const Key & key)
noexcept
247 const Key &
pk =
KEY(p);
276 assert(p != Node::NullPtr);
281 if (
root == Node::NullPtr)
284 const Key & key =
KEY(p);
295 assert(p != Node::NullPtr);
299 if (
root == Node::NullPtr)
316 if (
root == Node::NullPtr)
326 if (
root == Node::NullPtr)
329 const Key & key =
KEY(p);
350 if (r == Node::NullPtr ||
RLINK(r) == Node::NullPtr)
354 Node * head_ptr = &header;
361 while (
RLINK(t) != Node::NullPtr)
367 if (
RLINK(t) == Node::NullPtr)
407 if (
root == Node::NullPtr)
458 return root == Node::NullPtr;
474 if (
root == Node::NullPtr)
475 return {-1,
nullptr};
481 return {-1,
nullptr};
513 if (
root == Node::NullPtr)
514 return {-1,
nullptr};
567 <<
"Iterator is at end";
576 <<
"Iterator is at end";
595 curr = Node::NullPtr;
601 while (
LLINK(r) != Node::NullPtr)
611 while (
curr != Node::NullPtr)
628template <
typename Key,
class Compare = Aleph::less<Key>>
636template <
typename Key,
class Compare = Aleph::less<Key>>
Exception handling system with formatted messages for Aleph-w.
#define ah_overflow_error_if(C)
Throws std::overflow_error if condition holds.
Inorder iterator over the extended splay tree.
GenTdSplayTreeRk * tree_ptr
size_t get_pos() const noexcept
Node * get_curr_ne() const noexcept
static Node * find_min(Node *r) noexcept
void reset_first() noexcept
Iterator(GenTdSplayTreeRk &tree) noexcept
bool has_curr() const noexcept
static Node * inorder_successor(Node *root, const Key &key) noexcept
Top-down splay tree with rank support.
std::pair< long, Node * > position(const Key &key)
Returns the inorder (sorted) position of key.
Node * splay_max(Node *r) noexcept
Splay the maximum element to the root.
GenTdSplayTreeRk(Compare __cmp=Compare())
Constructor.
void splay(const Key &key) noexcept
search key within tree and splay that node.
static constexpr signed char CmpGreater
void swap(GenTdSplayTreeRk &tree)
std::pair< long, Node * > find_position(const Key &key)
Returns the inorder (sorted) position of key.
Node * insert(Node *p)
Inserts a node in a top down splay tree.
Compare & key_comp()
Returns a reference to the comparison functor.
Node * remove(const Key &key)
Remove a key from a top-down splay tree.
Node * search_or_insert(Node *p)
bool is_empty() const
Returns true if the tree is empty.
signed char splay_impl(const Key &key) noexcept
Node * search(const Key &key)
Searches a key in a top down splay tree.
static constexpr signed char CmpEqual
Key key_type
The key type stored in the node.
Node * select(const size_t &i)
Returns the node whose inorder position in the extended tree is i.
Node * insert_dup(Node *p)
virtual ~GenTdSplayTreeRk()
Destructor.
static constexpr signed char CmpLess
size_t size() const
Returns the number of nodes stored in the tree.
Node *& getRoot()
Get the top-down splay tree's root.
bool check_rank_tree(Node *root) noexcept
Return true if root is a valid extended binary tree.
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.
auto & COUNT(Node *p) noexcept
Return the number of nodes of the tree fron p is root.
Node * rotate_to_left_xt(Node *p) noexcept
Rotate to left the extended binary tree with root p.
Node * select(Node *r, const size_t pos)
Iterative selection of a node according to inorder position.
constexpr Node *& LLINK(Node *p) noexcept
Return a pointer to left subtree.
Node * rotate_to_right_xt(Node *p) noexcept
Rotate to right the extended bianry tree with root p
Main namespace for Aleph-w library functions.
DynList< T > maps(const C &c, Op op)
Classic map operation.
Extended binary node with subtree count.