11 # ifndef TPL_SPLAY_TREE_H
12 # define TPL_SPLAY_TREE_H
14 # include <tpl_binNodeXt.H>
17 using namespace Aleph;
20 template <
template <
class>
class NodeType,
typename Key,
class Compare>
25 typedef NodeType<Key> Node;
47 Node header(sentinelCtor);
48 Node * head_ptr = &header;
56 if (
LLINK(t) == Node::NullPtr)
62 if (
LLINK(t) == Node::NullPtr)
70 else if (cmp(
KEY(t), key))
72 if (
RLINK(t) == Node::NullPtr)
78 if (
RLINK(t) == Node::NullPtr)
114 : root(Node::NullPtr), cmp(__cmp)
120 : root(Node::NullPtr), cmp(__cmp)
127 std::swap(root, tree.root);
128 std::swap(cmp, tree.cmp);
136 Node * __insert(Node * p)
139 if (cmp(
KEY(p),
KEY(root)))
144 LLINK(root) = Node::NullPtr;
151 RLINK(root) = Node::NullPtr;
167 I(p != Node::NullPtr);
169 I(
LLINK(p) == Node::NullPtr and
RLINK(p) == Node::NullPtr);
172 if (root == Node::NullPtr)
175 const Key & key =
KEY(p);
179 if (are_equals<Key, Compare>(
KEY(root), key, cmp))
185 Node * insert_dup(Node * p)
187 I(p != Node::NullPtr);
188 I(
LLINK(p) == Node::NullPtr and
RLINK(p) == Node::NullPtr);
191 if (root == Node::NullPtr)
208 if (root == Node::NullPtr)
213 return are_equals<Key, Compare>(
KEY(root), key) ? root : NULL;
216 Node * search_or_insert(Node * p)
218 if (root == Node::NullPtr)
221 const Key & key =
KEY(p);
223 if (are_equals<Key, Compare>(key,
KEY(root), cmp))
238 Node *
remove(
const Key & key)
240 if (root == Node::NullPtr)
245 if (no_equals<Key, Compare>(
KEY(root), key, cmp))
248 Node * ret_val = root;
250 if (
LLINK(root) == Node::NullPtr)
254 Node * p =
RLINK(root);
271 bool verify()
const {
return check_rank_tree(root); }
282 return root == Node::NullPtr;
299 std::pair<int, Node*> ret_val;
303 if (are_equals<Key, Compare>(key,
KEY(root), cmp))
306 ret_val.second = root;
346 std::pair<int, Node*> r(-2, NULL);
348 r.first =
COUNT(Splay(key));
371 template <
typename Key,
class Compare = Aleph::less<Key>>
390 template <
typename Key,
class Compare = Aleph::less<Key>>
Key key_type
El tipo de clave que contiene el nodo.
Definition: tpl_splay_treeRk.H:35
Definition: tpl_splay_treeRk.H:391
#define LLINK(p)
Definition: tpl_binNode.H:196
#define RLINK(p)
Definition: tpl_binNode.H:201
Node * insert(Node *p)
Definition: tpl_splay_treeRk.H:165
bool is_empty() const
Retorna true si el treap está vacío.
Definition: tpl_splay_treeRk.H:280
#define COUNT(p)
Definition: tpl_binNodeXt.H:34
Node * rotate_to_right_xt(Node *p)
Definition: tpl_binNodeXt.H:757
void splay(const Key &key)
Definition: tpl_splay_treeRk.H:45
Definition: tpl_splay_treeRk.H:372
virtual ~GenTdSplayTreeRk()
Destructor.
Definition: tpl_splay_treeRk.H:132
Compare & get_compare()
Definition: tpl_splay_treeRk.H:41
size_t size() const
Retorna la cantidad de nodos que contiene el treap.
Definition: tpl_splay_treeRk.H:274
GenTdSplayTreeRk(Compare &__cmp)
Constructor.
Definition: tpl_splay_treeRk.H:113
Node * select(Node *r, const size_t &pos)
Definition: tpl_binNodeXt.H:89
Compare & key_comp()
Retorna una referencia al criterio de comparación.
Definition: tpl_splay_treeRk.H:38
std::pair< int, Node * > find_position(const Key &key)
Definition: tpl_splay_treeRk.H:344
Node * rotate_to_left_xt(Node *p)
Definition: tpl_binNodeXt.H:776
Node *& getRoot()
Get the top down splay tree's root.
Definition: tpl_splay_treeRk.H:266
#define KEY(p)
Definition: tpl_binNode.H:206
Node * select(const size_t &i)
Definition: tpl_splay_treeRk.H:364
Node * search(const Key &key)
Definition: tpl_splay_treeRk.H:206
Definition: tpl_splay_treeRk.H:21
std::pair< int, Node * > position(const Key &key)
Definition: tpl_splay_treeRk.H:297