aGrUM  0.16.0
indexedTree.h
Go to the documentation of this file.
1 
29 #ifndef GUM_INDEXED_TREE_H
30 #define GUM_INDEXED_TREE_H
31 
32 #include <iostream>
33 
34 #include <agrum/agrum.h>
35 #include <agrum/core/hashTable.h>
36 
37 namespace gum {
38 
39  // =========================================================================
40  // === NODES FOR GENERIC TREE (DATA) STRUCTURE === */
41  // =========================================================================
42 
52  template < typename Key, typename Data >
53  class IndexedTree {
54  public:
55  // ============================================================================
57  // ============================================================================
59 
68  IndexedTree(Data* data = nullptr);
69 
83  IndexedTree(const Key& theKey, Data* data = nullptr);
84 
94  IndexedTree(const Key& theKey, const Data& data);
95 
101 
108 
112  ~IndexedTree();
113 
115  // ============================================================================
117  // ============================================================================
119 
129  void insertNode(const std::vector< Key >& index, const Data* data);
130 
140  void insertNode(const std::vector< Key >& index, const Data& data);
141 
149  void setNode(const std::vector< Key >& index, Data* data);
150 
158  void setNode(const std::vector< Key >& index, const Data& data);
159 
168  Data& getData(const std::vector< Key >& index) const;
169 
177  IndexedTree< Key, Data >& getNode(const std::vector< Key >& index) const;
178 
180 
181  private:
183  Key key;
184 
186  Data* data;
187 
190 
193  };
194 
196  template < typename Key, typename Data >
197  std::ostream& operator<<(std::ostream&, const IndexedTree< Key, Data >&);
198 
199 } /* namespace gum */
200 
201 // always include the templated implementations
203 
204 #endif /* GUM_INDEXED_TREE_H */
Data & getData(const std::vector< Key > &index) const
Returns the value of a given node of the tree.
The class for storing the nodes of the Arborescence.
Definition: indexedTree.h:53
IndexedTree< Key, Data > * parent
The parent of the node.
Definition: indexedTree.h:189
IndexedTree(Data *data=nullptr)
Creates a tree with one node with or without data.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
HashTable< Key, IndexedTree< Key, Data > *> children
The list of children nodes of the current node.
Definition: indexedTree.h:192
void insertNode(const std::vector< Key > &index, const Data *data)
Adds a new node into the tree.
Data * data
The data stored into the node.
Definition: indexedTree.h:186
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
The class for generic Hash Tables.
Definition: hashTable.h:679
IndexedTree< Key, Data > & getNode(const std::vector< Key > &index) const
Returns a given node of the tree.
IndexedTree< Key, Data > & operator=(const IndexedTree< Key, Data > &from)
Copy operator.
void setNode(const std::vector< Key > &index, Data *data)
Updates the value of a node (or adds it if it does not already exist).
Key key
The key of the current node.
Definition: indexedTree.h:183
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
~IndexedTree()
Class destructor.