aGrUM  0.16.0
splay.h
Go to the documentation of this file.
1 
30 #ifndef GUM_SPLAY_H
31 #define GUM_SPLAY_H
32 
33 #include <iostream>
34 //#include <stdlib.h>
35 
36 #include <agrum/agrum.h>
37 #include <agrum/core/hashTable.h>
38 
39 namespace gum {
40 
41  template < class Element >
43  template < class Element >
44  class SplayTree;
45 
47 
48  template < typename Element >
49  INLINE std::ostream& operator<<(std::ostream& out,
51 
53 
54  template < typename Element >
55  INLINE std::ostream& operator<<(std::ostream& out,
56  const SplayTree< Element >& s);
57 
58  // =========================================================================
59  // === NODE ===
60  // =========================================================================
72  template < class Element >
73  class SplayBinaryNode {
74  public:
75  // ============================================================================
77  // ============================================================================
79 
84  int position() const;
85 
90  const Element& getElement() const;
91 
97  const SplayBinaryNode< Element >* getFg() const;
98 
104  const SplayBinaryNode< Element >* getFd() const;
105 
107 
108  protected:
109  // ============================================================================
111  // ============================================================================
113 
123  SplayBinaryNode(const Element& e,
124  HashTable< Element, SplayBinaryNode< Element >* >& addr,
125  SplayBinaryNode* g = 0,
126  SplayBinaryNode* d = 0,
127  SplayBinaryNode* p = 0);
128 
135  HashTable< Element, SplayBinaryNode< Element >* >& addr);
136 
142  void _copy(const SplayBinaryNode< Element >& from,
143  HashTable< Element, SplayBinaryNode< Element >* >& addr);
144 
149 
151  // ============================================================================
153  // ============================================================================
155 
161 
167 
173 
182  HashTable< Element, SplayBinaryNode< Element >* >& addr);
183 
185  // ============================================================================
187  // ============================================================================
189 
191  Element elt;
192 
195 
198 
201 
204 
206 
208  friend class SplayTree< Element >;
209 
211  friend std::ostream& operator<<<>(std::ostream& out,
213  };
214 
215  // ============================================================================
216  // === SPLAY TREE ===
217  // ============================================================================
261  template < class Element >
262  class SplayTree {
263  public:
264  // ============================================================================
266  // ============================================================================
268 
272  SplayTree();
273 
278  SplayTree(const Element& e);
279 
284  SplayTree(const SplayTree& from);
285 
289  ~SplayTree();
290 
292  // ============================================================================
294  // ============================================================================
296 
302  SplayTree< Element >& operator=(const SplayTree< Element >& from);
303 
305  // ============================================================================
307  // ============================================================================
309 
316  Element& operator[](const unsigned int i);
317 
324  const Element& operator[](const unsigned int i) const;
325 
326 
331  Element& front();
332 
337  Element& back();
338 
342  void popFront();
343 
347  void popBack();
348 
353  void pushFront(const Element& e);
354 
359  void pushBack(const Element& e);
360 
365  void insert(const Element& e);
366 
371  void join(const SplayTree< Element >& s);
372 
373 
383  SplayTree< Element > split(const int i);
384 
385 
394  SplayTree< Element > split_by_val(const Element& e);
395 
400  Size size() const;
401 
407  bool contains(const Element& e) const;
408 
410 
411  protected:
412  // ============================================================================
414  // ============================================================================
416 
419 
422 
424 
426  void _copy(const SplayTree< Element >&);
427 
429  friend std::ostream& operator<<<>(std::ostream& out,
430  const SplayTree< Element >&);
431  };
432 
433 } /* namespace gum */
434 
435 // always include the _tpl.h as it contains only templates
436 #include <agrum/core/splay_tpl.h>
437 
438 #endif /* GUM_SPLAY_H */
SplayBinaryNode * pere
The father, nullptr for the root.
Definition: splay.h:203
SplayBinaryNode< Element > * zag()
A left rotation, the node must hava a father.
Definition: splay_tpl.h:168
const Element & getElement() const
Returns the element in the node.
Definition: splay_tpl.h:320
const SplayBinaryNode< Element > * getFg() const
Returns the left child.
Definition: splay_tpl.h:331
SplayBinaryNode< Element > * splay()
A splay rotation, the node will be the root of the tree.
Definition: splay_tpl.h:218
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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.
Definition: splay_tpl.h:73
~SplayBinaryNode()
Class destructor.
Definition: splay_tpl.h:104
void _copy(const SplayBinaryNode< Element > &from, HashTable< Element, SplayBinaryNode< Element > * > &addr)
A function used to perform copies.
Definition: splay_tpl.h:41
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
std::vector< std::string > split(const std::string &str, const std::string &delim)
Split str using the delimiter.
SplayBinaryNode< Element > * root
Root of the tree.
Definition: splay.h:418
the nodes of splay trees
Definition: splay.h:42
The class for generic Hash Tables.
Definition: hashTable.h:679
Size size
The size of the sub-tree.
Definition: splay.h:194
SplayBinaryNode * fg
The left child.
Definition: splay.h:197
Element elt
The content.
Definition: splay.h:191
std::ostream & operator<<(std::ostream &output, const BayesNet< GUM_SCALAR > &bn)
Prints map&#39;s DAG in output using the Graphviz-dot format.
Definition: BayesNet_tpl.h:605
A splay tree.
Definition: splay.h:44
const SplayBinaryNode< Element > * getFd() const
Returns the right child.
Definition: splay_tpl.h:342
SplayBinaryNode< Element > * join(const SplayBinaryNode< Element > *e, HashTable< Element, SplayBinaryNode< Element > * > &addr)
Concatenation of two trees.
Definition: splay_tpl.h:263
SplayBinaryNode * fd
The right child.
Definition: splay.h:200
SplayBinaryNode< Element > * zig()
A right rotation, the node must have a father.
Definition: splay_tpl.h:117
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
int position() const
Position of the node.
Definition: splay_tpl.h:293
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
HashTable< Element, SplayBinaryNode< Element > *> addr
The hash table to find quickly the position of a node.
Definition: splay.h:421