60 template <
class Element >
64 if (addr.exists(from.
elt)) addr[from.
elt] =
this;
65 else addr.insert(from.
elt,
this);
90 template <
class Element >
97 if (addr.exists(
elt)) addr[
elt] =
this;
98 else addr.insert(
elt,
this);
106 template <
class Element >
117 template <
class Element >
130 template <
class Element >
134 GUM_ASSERT(
pere != 0);
149 if (
fd->fg) size_ +=
fd->fg->size;
151 if (
fd->fd) size_ +=
fd->fd->size;
156 if (
fg) size_ +=
fg->size;
171 GUM_ASSERT(
pere->fd ==
fd);
181 template <
class Element >
185 GUM_ASSERT(
pere != 0);
200 if (
fg->fg) size_ +=
fg->fg->size;
202 if (
fg->fd) size_ +=
fg->fd->size;
206 if (
fd) size_ +=
fd->size;
221 GUM_ASSERT(
pere->fd ==
fg);
231 template <
class Element >
240 if (
this ==
pere->fg) {
244 GUM_ASSERT(
this ==
pere->fd);
249 if (
this ==
pere->fg) {
254 GUM_ASSERT(
pere == gdp->
fd);
258 GUM_ASSERT(
this ==
pere->fd);
264 GUM_ASSERT(
pere == gdp->
fd);
276 template <
class Element >
284 for (; act->
fd; act = act->
fd)
306 template <
class Element >
310 if (
fg)
return fg->size + 1;
312 }
else if (
pere->fg ==
this) {
314 int pos =
pere->position() - 1;
316 if (
fd) pos -=
fd->size;
321 int pos =
pere->position() + 1;
323 if (
fg) pos +=
fg->size;
331 template <
class Element >
341 template <
class Element >
351 template <
class Element >
364 template <
class Element >
375 template <
class Element >
386 template <
class Element >
395 template <
class Element >
404 template <
class Element >
424 template <
class Element >
434 template <
class Element >
440 }
else if (val >=
root->size) {
446 int pos_act = val - 1;
450 if (!act->
fg) pos_act = 0;
451 else pos_act = act->
fg->
size;
455 }
else if (pos_act < val) {
457 val -= (pos_act + 1);
469 template <
class Element >
475 }
else if (val >=
root->size) {
481 int pos_act = val - 1;
485 if (!act->
fg) pos_act = 0;
486 else pos_act = act->
fg->
size;
490 }
else if (pos_act < val) {
492 val -= (pos_act + 1);
506 template <
class Element >
513 for (; act->
fg; act = act->
fg)
523 template <
class Element >
530 for (; act->
fd; act = act->
fd)
540 template <
class Element >
546 for (; act->
fg; act = act->
fg)
563 template <
class Element >
569 for (; act->
fd; act = act->
fd)
586 template <
class Element >
592 for (; act->
fg; act = act->
fg)
605 template <
class Element >
611 for (; act->
fd; act = act->
fd)
624 template <
class Element >
650 template <
class Element >
663 template <
class Element >
676 template <
class Element >
678 GUM_ASSERT(i >= 0 && i < root->
size);
679 GUM_ASSERT(
root != 0);
689 }
else if (i ==
root->size - 1) {
695 int pos =
root->position();
698 GUM_ASSERT(act != 0);
726 if (s.
root->fd) size_ += s.
root->fd->size;
728 s.
root->size = size_;
740 template <
typename Element >
742 GUM_ASSERT(
root != 0);
778 template <
class Element >
786 template <
class Element >
788 return addr.exists(e);
793 template <
typename Element >
795 if (e.
fg) out << *e.
fg <<
",";
799 if (e.
fd) out <<
"," << *e.
fd;
806 template <
typename Element >
The class for generic Hash Tables.
Exception : the element we looked for cannot be found.
SplayBinaryNode * fg
The left child.
SplayBinaryNode< Element > * zag()
A left rotation, the node must hava a father.
const Element & getElement() const
Returns the element in the node.
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.
int position() const
Position of the node.
SplayBinaryNode * pere
The father, nullptr for the root.
void copy_(const SplayBinaryNode< Element > &from, HashTable< Element, SplayBinaryNode< Element > * > &addr)
A function used to perform copies.
SplayBinaryNode * fd
The right child.
const SplayBinaryNode< Element > * getFg() const
Returns the left child.
~SplayBinaryNode()
Class destructor.
SplayBinaryNode< Element > * join(const SplayBinaryNode< Element > *e, HashTable< Element, SplayBinaryNode< Element > * > &addr)
Concatenation of two trees.
SplayBinaryNode< Element > * splay()
A splay rotation, the node will be the root of the tree.
const SplayBinaryNode< Element > * getFd() const
Returns the right child.
SplayBinaryNode< Element > * zig()
A right rotation, the node must have a father.
Size size
The size of the sub-tree.
Element & operator[](const unsigned int i)
Get the element at the position n.
Element & front()
Get the first element.
~SplayTree()
Class destructor.
void pushFront(const Element &e)
Add an element in the first position.
bool contains(const Element &e) const
Test if the tree contains the element.
SplayBinaryNode< Element > * root
Root of the tree.
SplayTree()
Basic constructor, make an empty splay tree.
void popBack()
Remove the last element.
void popFront()
Remove the first element.
Size size() const
The number of elements in the tree.
SplayTree< Element > & operator=(const SplayTree< Element > &from)
Assignment operator.
Element & back()
Get the last element.
void join(const SplayTree< Element > &s)
Concatenation of two trees.
HashTable< Element, SplayBinaryNode< Element > * > addr
The hash table to find quickly the position of a node.
SplayTree< Element > split(const int i)
Divide the tree at the position.
void copy_(const SplayTree< Element > &)
a function used to perform copies
void insert(const Element &e)
Add an element to the tree.
void pushBack(const Element &e)
Add an element in the last position.
SplayTree< Element > split_by_val(const Element &e)
Divide the tree at the position.
#define GUM_ERROR(type, msg)
std::size_t Size
In aGrUM, hashed values are unsigned long int.
gum is the global namespace for all aGrUM entities
std::ostream & operator<<(std::ostream &stream, const AVLTree< Val, Cmp > &tree)
display the content of a tree
static INLINE void removeInfo(const SplayBinaryNode< Element > *e, HashTable< Element, SplayBinaryNode< Element > * > &addr)