40 template <
class Element >
44 if (addr.exists(from.
elt))
45 addr[from.
elt] =
this;
47 addr.insert(from.
elt,
this);
72 template <
class Element >
80 size(1), fg(g), fd(d), pere(p) {
84 addr.insert(
elt,
this);
92 template <
class Element >
103 template <
class Element >
116 template <
class Element >
120 GUM_ASSERT(
pere != 0);
167 template <
class Element >
171 GUM_ASSERT(
pere != 0);
217 template <
class Element >
230 GUM_ASSERT(
this ==
pere->
fd);
240 GUM_ASSERT(
pere == gdp->
fd);
244 GUM_ASSERT(
this ==
pere->
fd);
250 GUM_ASSERT(
pere == gdp->
fd);
262 template <
class Element >
270 for (; act->
fd; act = act->
fd)
283 if (act->
fg) act->
size += act->
fg->size;
285 act->
size += act->
fd->size;
292 template <
class Element >
300 }
else if (
pere->
fg ==
this) {
319 template <
class Element >
329 template <
class Element >
340 template <
class Element >
354 template <
class Element >
365 template <
class Element >
376 template <
class Element >
385 template <
class Element >
394 template <
class Element >
415 template <
class Element >
425 template <
class Element >
431 }
else if (val >=
root->size) {
437 int pos_act = val - 1;
444 pos_act = act->
fg->size;
448 }
else if (pos_act < val) {
450 val -= (pos_act + 1);
462 template <
class Element >
468 }
else if (val >=
root->size) {
474 int pos_act = val - 1;
481 pos_act = act->
fg->size;
485 }
else if (pos_act < val) {
487 val -= (pos_act + 1);
501 template <
class Element >
508 for (; act->
fg; act = act->
fg)
518 template <
class Element >
525 for (; act->
fd; act = act->
fd)
535 template <
class Element >
541 for (; act->
fg; act = act->
fg)
558 template <
class Element >
564 for (; act->
fd; act = act->
fd)
581 template <
class Element >
587 for (; act->
fg; act = act->
fg)
600 template <
class Element >
606 for (; act->
fd; act = act->
fd)
619 template <
class Element >
645 template <
class Element >
658 template <
class Element >
672 template <
class Element >
674 GUM_ASSERT(i >= 0 && i < root->
size);
675 GUM_ASSERT(
root != 0);
685 }
else if (i ==
root->size - 1) {
691 int pos =
root->position();
694 GUM_ASSERT(act != 0);
722 if (s.
root->fd) _size += s.
root->fd->size;
724 s.
root->size = _size;
736 template <
typename Element >
739 GUM_ASSERT(
root != 0);
741 if (!
addr.exists(e)) {
777 template <
class Element >
787 template <
class Element >
789 return addr.exists(e);
794 template <
typename Element >
797 if (e.
fg) out << *e.
fg <<
",";
801 if (e.
fd) out <<
"," << *e.
fd;
808 template <
typename Element >
SplayBinaryNode * pere
The father, nullptr for the root.
SplayBinaryNode< Element > * zag()
A left rotation, the node must hava a father.
friend std::ostream & operator<<(std::ostream &out, const SplayTree< Element > &)
Friendly to display.
void _copy(const SplayTree< Element > &)
a function used to perform copies
const Element & getElement() const
Returns the element in the node.
const SplayBinaryNode< Element > * getFg() const
Returns the left child.
SplayBinaryNode< Element > * splay()
A splay rotation, the node will be the root of the tree.
SplayBinaryNode(const Element &e, HashTable< Element, SplayBinaryNode< Element > * > &addr, SplayBinaryNode *g=0, SplayBinaryNode *d=0, SplayBinaryNode *p=0)
Basic constructor: creates a node with a reference to the element.
SplayTree< Element > & operator=(const SplayTree< Element > &from)
Assignment operator.
~SplayBinaryNode()
Class destructor.
bool contains(const Element &e) const
Test if the tree contains the element.
void join(const SplayTree< Element > &s)
Concatenation of two trees.
Element & front()
Get the first element.
SplayTree< Element > split_by_val(const Element &e)
Divide the tree at the position.
void _copy(const SplayBinaryNode< Element > &from, HashTable< Element, SplayBinaryNode< Element > * > &addr)
A function used to perform copies.
void pushFront(const Element &e)
Add an element in the first position.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
SplayBinaryNode< Element > * root
Root of the tree.
SplayTree< Element > split(const int i)
Divide the tree at the position.
The class for generic Hash Tables.
Size size
The size of the sub-tree.
SplayTree()
Basic constructor, make an empty splay tree.
SplayBinaryNode * fg
The left child.
Element & operator[](const unsigned int i)
Get the element at the position n.
const SplayBinaryNode< Element > * getFd() const
Returns the right child.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
SplayBinaryNode< Element > * join(const SplayBinaryNode< Element > *e, HashTable< Element, SplayBinaryNode< Element > * > &addr)
Concatenation of two trees.
void insert(const Element &e)
Add an element to the tree.
void popFront()
Remove the first element.
SplayBinaryNode * fd
The right child.
Size size() const
The number of elements in the tree.
Element & back()
Get the last element.
~SplayTree()
Class destructor.
void popBack()
Remove the last element.
SplayBinaryNode< Element > * zig()
A right rotation, the node must have a father.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
void pushBack(const Element &e)
Add an element in the last position.
int position() const
Position of the node.
#define GUM_ERROR(type, msg)
static INLINE void removeInfo(const SplayBinaryNode< Element > *e, HashTable< Element, SplayBinaryNode< Element > * > &addr)
HashTable< Element, SplayBinaryNode< Element > *> addr
The hash table to find quickly the position of a node.