aGrUM  0.16.0
binTreeNode.h
Go to the documentation of this file.
1 
29 #ifndef GUM_BIN_TREE_NODE_H
30 #define GUM_BIN_TREE_NODE_H
31 
32 #include <agrum/agrum.h>
33 
34 namespace gum {
35 
37  enum class BinTreeDir : char { LEFT_CHILD = 0, RIGHT_CHILD = 1, NO_PARENT = 2 };
38 
39  // ===========================================================================
40  // === GENERIC NODE FOR A BINARY TREE ===
41  // ===========================================================================
42 
99  template < typename Val >
100  class BinTreeNode {
101  public:
102  // ============================================================================
104  // ============================================================================
106 
111  BinTreeNode(const Val& v);
112 
122  BinTreeNode(const BinTreeNode< Val >& from);
123 
130  ~BinTreeNode();
131 
133  // ============================================================================
135  // ============================================================================
137 
147  BinTreeNode< Val >& operator=(const BinTreeNode< Val >& from);
148 
153  Val& operator*();
154 
156  // ============================================================================
158  // ============================================================================
160 
165  Val& value();
166 
173  BinTreeNode< Val >* child(BinTreeDir dir) const;
174 
180  BinTreeNode< Val >* leftChild() const;
181 
187  BinTreeNode< Val >* rightChild() const;
188 
194  BinTreeNode< Val >* parent() const;
195 
200  BinTreeDir parentDir() const;
201 
210  BinTreeNode< Val >* insertLeftChild(const Val& val);
211 
218  void insertLeftChild(BinTreeNode< Val >& new_child);
219 
228  BinTreeNode< Val >* insertRightChild(const Val& val);
229 
236  void insertRightChild(BinTreeNode< Val >& new_child);
237 
246  BinTreeNode< Val >* insertChild(const Val& val, BinTreeDir child_dir);
247 
255  void insertChild(BinTreeNode< Val >& new_child, BinTreeDir child_dir);
256 
265  void eraseLeftLink();
266 
275  void eraseRightLink();
276 
286  void eraseLink(BinTreeDir tree_dir);
287 
295  BinTreeNode< Val >* leftmostNode() const;
296 
304  BinTreeNode< Val >* rightmostNode() const;
305 
313  BinTreeNode< Val >* root() const;
314 
316 
317  protected:
319  Val _val;
320 
323 
326 
328  BinTreeNode< Val >* _children[2];
329  };
330 
331 } /* namespace gum */
332 
333 
334 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
335 extern template class gum::BinTreeNode< int >;
336 #endif
337 
338 
339 // always include the implementation of the templates
341 
342 #endif // GUM_BIN_TREE_NODE_H
Val _val
The value stored in a node of the tree.
Definition: binTreeNode.h:319
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
BinTreeDir
The direction of a given edge in a binary tree.
Definition: binTreeNode.h:37
BinTreeDir _parent_dir
the direction to follow from the parent to reach the current node.
Definition: binTreeNode.h:325
Formula operator*(const Formula &a, const Formula &b)
Definition: formula_inl.h:489
Nodes of a binary trees.
Definition: binTreeNode.h:100
BinTreeNode< Val > * _parent
The parent of the node.
Definition: binTreeNode.h:322
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.