11 # ifndef TPL_SPLAY_TREE_H
12 # define TPL_SPLAY_TREE_H
15 # include <tpl_binNodeUtils.H>
17 using namespace Aleph;
20 template <
template <
class>
class NodeType,
typename Key,
class Compare>
25 typedef NodeType<Key> Node;
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)
92 LLINK(t) = headNode.getR();
93 RLINK(t) = headNode.getL();
100 : head(&headnode), root(headnode.getR()), cmp(__cmp)
106 : head(&headnode), root(headnode.getR()), cmp(__cmp)
113 std::swap(root, tree.root);
114 std::swap(cmp, tree.cmp);
122 Node * __insert(Node * p)
124 if (cmp(
KEY(p),
KEY(root)))
128 LLINK(root) = Node::NullPtr;
134 RLINK(root) = Node::NullPtr;
149 I(p != Node::NullPtr);
150 I(
LLINK(p) == Node::NullPtr and
RLINK(p) == Node::NullPtr);
153 if (root == Node::NullPtr)
156 const Key & key =
KEY(p);
160 if (are_equals<Key, Compare>(
KEY(root), key, cmp))
166 Node * insert_dup(Node * p)
168 I(p != Node::NullPtr);
169 I(
LLINK(p) == Node::NullPtr and
RLINK(p) == Node::NullPtr);
172 if (root == Node::NullPtr)
189 if (root == Node::NullPtr)
194 return are_equals<Key, Compare>(
KEY(root), key) ? root : NULL;
197 Node * search_or_insert(Node * p)
199 if (root == Node::NullPtr)
202 const Key & key =
KEY(p);
204 if (are_equals<Key, Compare>(key,
KEY(root), cmp))
219 Node *
remove(
const Key & key)
221 if (root == Node::NullPtr)
226 if (no_equals<Key, Compare>(
KEY(root), key, cmp))
229 Node * ret_val = root;
231 if (
LLINK(root) == Node::NullPtr)
235 Node * p =
RLINK(root);
252 bool verify()
const {
return true; }
256 template <
typename Key,
class Compare = Aleph::less<Key>>
275 template <
typename Key,
class Compare = Aleph::less<Key>>
Node * rotate_to_left(Node *p)
Definition: tpl_binNodeUtils.H:2422
void splay(const Key &key)
Definition: tpl_splay_tree.H:46
#define LLINK(p)
Definition: tpl_binNode.H:196
Node *& getRoot()
Get the top down splay tree's root.
Definition: tpl_splay_tree.H:247
#define RLINK(p)
Definition: tpl_binNode.H:201
Definition: tpl_splay_tree.H:257
Node * insert(Node *p)
Definition: tpl_splay_tree.H:147
Definition: tpl_splay_tree.H:21
Node * rotate_to_right(Node *p)
Definition: tpl_binNodeUtils.H:2375
Compare & key_comp()
Retorna una referencia al criterio de comparación.
Definition: tpl_splay_tree.H:39
Key key_type
El tipo de clave que contiene el nodo.
Definition: tpl_splay_tree.H:36
Definition: tpl_splay_tree.H:276
Node * search(const Key &key)
Definition: tpl_splay_tree.H:187
#define KEY(p)
Definition: tpl_binNode.H:206
virtual ~GenTdSplayTree()
Destructor.
Definition: tpl_splay_tree.H:118
Compare & get_compare()
Definition: tpl_splay_tree.H:42
GenTdSplayTree(Compare &__cmp)
Constructor.
Definition: tpl_splay_tree.H:99