37 template <
class Element >
41 if (addr.exists(from.
elt))
42 addr[from.
elt] =
this;
44 addr.insert(from.
elt,
this);
69 template <
class Element >
77 size(1), fg(g), fd(d), pere(p) {
81 addr.insert(
elt,
this);
89 template <
class Element >
100 template <
class Element >
113 template <
class Element >
117 GUM_ASSERT(
pere != 0);
164 template <
class Element >
168 GUM_ASSERT(
pere != 0);
214 template <
class Element >
227 GUM_ASSERT(
this ==
pere->
fd);
237 GUM_ASSERT(
pere == gdp->
fd);
241 GUM_ASSERT(
this ==
pere->
fd);
247 GUM_ASSERT(
pere == gdp->
fd);
259 template <
class Element >
267 for (; act->
fd; act = act->
fd)
280 if (act->
fg) act->
size += act->
fg->size;
282 act->
size += act->
fd->size;
289 template <
class Element >
297 }
else if (
pere->
fg ==
this) {
316 template <
class Element >
326 template <
class Element >
337 template <
class Element >
351 template <
class Element >
362 template <
class Element >
373 template <
class Element >
382 template <
class Element >
391 template <
class Element >
412 template <
class Element >
422 template <
class Element >
428 }
else if (val >=
root->size) {
434 int pos_act = val - 1;
441 pos_act = act->
fg->size;
445 }
else if (pos_act < val) {
447 val -= (pos_act + 1);
459 template <
class Element >
465 }
else if (val >=
root->size) {
471 int pos_act = val - 1;
478 pos_act = act->
fg->size;
482 }
else if (pos_act < val) {
484 val -= (pos_act + 1);
498 template <
class Element >
505 for (; act->
fg; act = act->
fg)
515 template <
class Element >
522 for (; act->
fd; act = act->
fd)
532 template <
class Element >
538 for (; act->
fg; act = act->
fg)
555 template <
class Element >
561 for (; act->
fd; act = act->
fd)
578 template <
class Element >
584 for (; act->
fg; act = act->
fg)
597 template <
class Element >
603 for (; act->
fd; act = act->
fd)
616 template <
class Element >
642 template <
class Element >
655 template <
class Element >
669 template <
class Element >
671 GUM_ASSERT(i >= 0 && i < root->
size);
672 GUM_ASSERT(
root != 0);
682 }
else if (i ==
root->size - 1) {
688 int pos =
root->position();
691 GUM_ASSERT(act != 0);
719 if (s.
root->fd) _size += s.
root->fd->size;
721 s.
root->size = _size;
733 template <
typename Element >
736 GUM_ASSERT(
root != 0);
738 if (!
addr.exists(e)) {
774 template <
class Element >
784 template <
class Element >
786 return addr.exists(e);
791 template <
typename Element >
794 if (e.
fg) out << *e.
fg <<
",";
798 if (e.
fd) out <<
"," << *e.
fd;
805 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.
gum is the global namespace for all aGrUM entities
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.
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.