![]() |
aGrUM
0.16.0
|
A splay tree. More...
#include <agrum/core/splay.h>
Public Member Functions | |
Constructors / Destructors | |
SplayTree () | |
Basic constructor, make an empty splay tree. More... | |
SplayTree (const Element &e) | |
Basic constructor, make a splay tree with one element. More... | |
SplayTree (const SplayTree &from) | |
Copy constructor. More... | |
~SplayTree () | |
Class destructor. More... | |
Operators | |
SplayTree< Element > & | operator= (const SplayTree< Element > &from) |
Assignment operator. More... | |
Methods | |
Element & | operator[] (const unsigned int i) |
Get the element at the position n. More... | |
const Element & | operator[] (const unsigned int i) const |
Get the element at the position n. More... | |
Element & | front () |
Get the first element. More... | |
Element & | back () |
Get the last element. More... | |
void | popFront () |
Remove the first element. More... | |
void | popBack () |
Remove the last element. More... | |
void | pushFront (const Element &e) |
Add an element in the first position. More... | |
void | pushBack (const Element &e) |
Add an element in the last position. More... | |
void | insert (const Element &e) |
Add an element to the tree. More... | |
void | join (const SplayTree< Element > &s) |
Concatenation of two trees. More... | |
SplayTree< Element > | split (const int i) |
Divide the tree at the position. More... | |
SplayTree< Element > | split_by_val (const Element &e) |
Divide the tree at the position. More... | |
Size | size () const |
The number of elements in the tree. More... | |
bool | contains (const Element &e) const |
Test if the tree contains the element. More... | |
Protected Attributes | |
Data Menbers | |
SplayBinaryNode< Element > * | root |
Root of the tree. More... | |
HashTable< Element, SplayBinaryNode< Element > *> | addr |
The hash table to find quickly the position of a node. More... | |
Protected Member Functions | |
void | _copy (const SplayTree< Element > &) |
a function used to perform copies More... | |
Friends | |
std::ostream & | operator<< (std::ostream &out, const SplayTree< Element > &) |
Friendly to display. More... | |
A splay tree.
Element | The elements type. |
INLINE gum::SplayTree< Element >::SplayTree | ( | ) |
Basic constructor, make an empty splay tree.
Definition at line 366 of file splay_tpl.h.
INLINE gum::SplayTree< Element >::SplayTree | ( | const Element & | e | ) |
Basic constructor, make a splay tree with one element.
e | The element of the tree. |
Definition at line 377 of file splay_tpl.h.
References gum::SplayTree< Element >::addr, and gum::SplayTree< Element >::root.
INLINE gum::SplayTree< Element >::SplayTree | ( | const SplayTree< Element > & | from | ) |
Copy constructor.
from | The gum::SplayTree to copy. |
Definition at line 386 of file splay_tpl.h.
References gum::SplayTree< Element >::_copy(), and gum::SplayTree< Element >::operator=().
INLINE gum::SplayTree< Element >::~SplayTree | ( | ) |
Class destructor.
Definition at line 416 of file splay_tpl.h.
References gum::SplayTree< Element >::root.
|
protected |
a function used to perform copies
Definition at line 355 of file splay_tpl.h.
References gum::SplayTree< Element >::root.
Referenced by gum::SplayTree< Element >::operator=(), and gum::SplayTree< Element >::SplayTree().
INLINE Element & gum::SplayTree< Element >::back | ( | ) |
Get the last element.
NotFound | Raised if the splay tree is empty. |
Definition at line 519 of file splay_tpl.h.
References gum::SplayBinaryNode< Element >::fd, GUM_ERROR, gum::SplayTree< Element >::root, and gum::SplayBinaryNode< Element >::splay().
INLINE bool gum::SplayTree< Element >::contains | ( | const Element & | e | ) | const |
Test if the tree contains the element.
e | The element to test if it is in the splay tree. |
Definition at line 788 of file splay_tpl.h.
References gum::SplayTree< Element >::addr.
INLINE Element & gum::SplayTree< Element >::front | ( | ) |
Get the first element.
NotFound | Raised if the splay tree is empty. |
Definition at line 502 of file splay_tpl.h.
References gum::SplayBinaryNode< Element >::fg, GUM_ERROR, gum::SplayTree< Element >::root, and gum::SplayBinaryNode< Element >::splay().
INLINE void gum::SplayTree< Element >::insert | ( | const Element & | e | ) |
Add an element to the tree.
e | The element to add. |
Definition at line 620 of file splay_tpl.h.
References gum::SplayTree< Element >::addr, gum::SplayBinaryNode< Element >::fd, gum::SplayTree< Element >::root, and gum::SplayBinaryNode< Element >::size.
INLINE void gum::SplayTree< Element >::join | ( | const SplayTree< Element > & | s | ) |
Concatenation of two trees.
s | The tree to add. |
Definition at line 646 of file splay_tpl.h.
References gum::SplayTree< Element >::addr, and gum::SplayTree< Element >::root.
INLINE SplayTree< Element > & gum::SplayTree< Element >::operator= | ( | const SplayTree< Element > & | from | ) |
Assignment operator.
from | The gum::SplayTree to copy. |
Definition at line 396 of file splay_tpl.h.
References gum::SplayTree< Element >::_copy(), gum::SplayTree< Element >::addr, and gum::SplayTree< Element >::root.
Referenced by gum::SplayTree< Element >::SplayTree().
Element & gum::SplayTree< Element >::operator[] | ( | const unsigned int | i | ) |
Get the element at the position n.
i | The position of the element to return. |
NotFound | Raised if no element was found. |
Definition at line 426 of file splay_tpl.h.
References gum::SplayBinaryNode< Element >::fd, gum::SplayBinaryNode< Element >::fg, GUM_ERROR, gum::SplayTree< Element >::root, and gum::SplayBinaryNode< Element >::splay().
const Element & gum::SplayTree< Element >::operator[] | ( | const unsigned int | i | ) | const |
Get the element at the position n.
i | The position of the element to return. |
NotFound | Raised if no element was found. |
Definition at line 463 of file splay_tpl.h.
References gum::SplayBinaryNode< Element >::fd, gum::SplayBinaryNode< Element >::fg, GUM_ERROR, gum::SplayTree< Element >::root, and gum::SplayBinaryNode< Element >::splay().
INLINE void gum::SplayTree< Element >::popBack | ( | ) |
Remove the last element.
Definition at line 559 of file splay_tpl.h.
References gum::SplayBinaryNode< Element >::fd, gum::SplayBinaryNode< Element >::fg, gum::SplayTree< Element >::root, and gum::SplayBinaryNode< Element >::splay().
INLINE void gum::SplayTree< Element >::popFront | ( | ) |
Remove the first element.
Definition at line 536 of file splay_tpl.h.
References gum::SplayBinaryNode< Element >::fd, gum::SplayBinaryNode< Element >::fg, gum::SplayTree< Element >::root, and gum::SplayBinaryNode< Element >::splay().
INLINE void gum::SplayTree< Element >::pushBack | ( | const Element & | e | ) |
Add an element in the last position.
e | The element to push. |
Definition at line 601 of file splay_tpl.h.
References gum::SplayTree< Element >::addr, gum::SplayBinaryNode< Element >::fd, gum::SplayTree< Element >::root, and gum::SplayBinaryNode< Element >::splay().
INLINE void gum::SplayTree< Element >::pushFront | ( | const Element & | e | ) |
Add an element in the first position.
e | The element to push. |
Definition at line 582 of file splay_tpl.h.
References gum::SplayTree< Element >::addr, gum::SplayBinaryNode< Element >::fg, gum::SplayTree< Element >::root, and gum::SplayBinaryNode< Element >::splay().
INLINE Size gum::SplayTree< Element >::size | ( | ) | const |
The number of elements in the tree.
Definition at line 778 of file splay_tpl.h.
References gum::SplayTree< Element >::root.
Referenced by gum::SplayTree< Element >::split().
INLINE SplayTree< Element > gum::SplayTree< Element >::split | ( | const int | i | ) |
Divide the tree at the position.
i | The position of the element (e) for split. |
Definition at line 673 of file splay_tpl.h.
References gum::SplayTree< Element >::addr, gum::SplayBinaryNode< Element >::fd, gum::SplayBinaryNode< Element >::fg, gum::SplayBinaryNode< Element >::position(), gum::removeInfo(), gum::SplayTree< Element >::root, gum::SplayTree< Element >::size(), and gum::SplayBinaryNode< Element >::splay().
INLINE SplayTree< Element > gum::SplayTree< Element >::split_by_val | ( | const Element & | e | ) |
Divide the tree at the position.
e | the element for split |
Definition at line 738 of file splay_tpl.h.
References gum::SplayTree< Element >::addr, gum::SplayBinaryNode< Element >::fd, gum::SplayBinaryNode< Element >::fg, GUM_ERROR, gum::removeInfo(), gum::SplayTree< Element >::root, and gum::SplayBinaryNode< Element >::splay().
|
friend |
Friendly to display.
Definition at line 809 of file splay_tpl.h.
|
protected |
The hash table to find quickly the position of a node.
Definition at line 421 of file splay.h.
Referenced by gum::SplayTree< Element >::contains(), gum::SplayTree< Element >::insert(), gum::SplayTree< Element >::join(), gum::SplayTree< Element >::operator=(), gum::SplayTree< Element >::pushBack(), gum::SplayTree< Element >::pushFront(), gum::removeInfo(), gum::SplayTree< Element >::SplayTree(), gum::SplayTree< Element >::split(), and gum::SplayTree< Element >::split_by_val().
|
protected |
Root of the tree.
Definition at line 418 of file splay.h.
Referenced by gum::SplayTree< Element >::_copy(), gum::SplayTree< Element >::back(), gum::SplayTree< Element >::front(), gum::SplayTree< Element >::insert(), gum::SplayTree< Element >::join(), gum::operator<<(), gum::SplayTree< Element >::operator=(), gum::SplayTree< Element >::operator[](), gum::SplayTree< Element >::popBack(), gum::SplayTree< Element >::popFront(), gum::SplayTree< Element >::pushBack(), gum::SplayTree< Element >::pushFront(), gum::SplayTree< Element >::size(), gum::SplayTree< Element >::SplayTree(), gum::SplayTree< Element >::split(), gum::SplayTree< Element >::split_by_val(), and gum::SplayTree< Element >::~SplayTree().