48# ifndef TPL_SPLAY_TREE_RK_H
49# define TPL_SPLAY_TREE_RK_H
107template <
template <
class>
class NodeType,
typename Key,
class Compare>
125 Node * head_ptr = &header;
154 else if (
cmp(
tk, key))
222 void splay(
const Key & key)
noexcept
249 const Key &
pk =
KEY(p);
278 assert(p != Node::NullPtr);
283 if (
root == Node::NullPtr)
286 const Key & key =
KEY(p);
297 assert(p != Node::NullPtr);
301 if (
root == Node::NullPtr)
318 if (
root == Node::NullPtr)
328 if (
root == Node::NullPtr)
331 const Key & key =
KEY(p);
352 if (
r == Node::NullPtr ||
RLINK(
r) == Node::NullPtr)
356 Node * head_ptr = &header;
363 while (
RLINK(t) != Node::NullPtr)
369 if (
RLINK(t) == Node::NullPtr)
409 if (
root == Node::NullPtr)
460 return root == Node::NullPtr;
476 if (
root == Node::NullPtr)
477 return {-1,
nullptr};
483 return {-1,
nullptr};
515 if (
root == Node::NullPtr)
516 return {-1,
nullptr};
569 <<
"Iterator is at end";
578 <<
"Iterator is at end";
597 curr = Node::NullPtr;
603 while (
LLINK(
r) != Node::NullPtr)
610 Node *successor = Node::NullPtr;
613 while (
curr != Node::NullPtr)
630template <
typename Key,
class Compare = Aleph::less<Key>>
639template <
typename Key,
class Compare = Aleph::less<Key>>
C++20 concepts for constraining comparison functors.
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.
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.
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.
and
Check uniqueness with explicit hash + equality functors.
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
Extended binary node with subtree count.