aGrUM  0.13.2
indexedTree.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
26 #ifndef GUM_INDEXED_TREE_H
27 #define GUM_INDEXED_TREE_H
28 
29 #include <iostream>
30 
31 #include <agrum/agrum.h>
32 #include <agrum/core/hashTable.h>
33 
34 namespace gum {
35 
36  // =========================================================================
37  // === NODES FOR GENERIC TREE (DATA) STRUCTURE === */
38  // =========================================================================
39 
49  template < typename Key, typename Data >
50  class IndexedTree {
51  public:
52  // ============================================================================
54  // ============================================================================
56 
65  IndexedTree(Data* data = nullptr);
66 
80  IndexedTree(const Key& theKey, Data* data = nullptr);
81 
91  IndexedTree(const Key& theKey, const Data& data);
92 
98 
105 
109  ~IndexedTree();
110 
112  // ============================================================================
114  // ============================================================================
116 
126  void insertNode(const std::vector< Key >& index, const Data* data);
127 
137  void insertNode(const std::vector< Key >& index, const Data& data);
138 
146  void setNode(const std::vector< Key >& index, Data* data);
147 
155  void setNode(const std::vector< Key >& index, const Data& data);
156 
165  Data& getData(const std::vector< Key >& index) const;
166 
174  IndexedTree< Key, Data >& getNode(const std::vector< Key >& index) const;
175 
177 
178  private:
180  Key key;
181 
183  Data* data;
184 
187 
190  };
191 
193  template < typename Key, typename Data >
194  std::ostream& operator<<(std::ostream&, const IndexedTree< Key, Data >&);
195 
196 } /* namespace gum */
197 
198 // always include the templated implementations
200 
201 #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:50
IndexedTree< Key, Data > * parent
The parent of the node.
Definition: indexedTree.h:186
IndexedTree(Data *data=nullptr)
Creates a tree with one node with or without data.
Implementation of tree data structures.
HashTable< Key, IndexedTree< Key, Data > * > children
The list of children nodes of the current node.
Definition: indexedTree.h:189
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:183
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
The class for generic Hash Tables.
Definition: hashTable.h:676
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:180
IndexedTree< Key, Data > & getNode(const std::vector< Key > &index) const
Returns a given node of the tree.
Class hash tables iterators.
~IndexedTree()
Class destructor.