aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
indexedTree.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2025 by *
5 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
6 * - Christophe GONZALES(_at_AMU) *
7 * *
8 * The aGrUM/pyAgrum library is free software; you can redistribute it *
9 * and/or modify it under the terms of either : *
10 * *
11 * - the GNU Lesser General Public License as published by *
12 * the Free Software Foundation, either version 3 of the License, *
13 * or (at your option) any later version, *
14 * - the MIT license (MIT), *
15 * - or both in dual license, as here. *
16 * *
17 * (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18 * *
19 * This aGrUM/pyAgrum library is distributed in the hope that it will be *
20 * useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26 * OTHER DEALINGS IN THE SOFTWARE. *
27 * *
28 * See LICENCES for more details. *
29 * *
30 * SPDX-FileCopyrightText: Copyright 2005-2025 *
31 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
32 * - Christophe GONZALES(_at_AMU) *
33 * SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34 * *
35 * Contact : info_at_agrum_dot_org *
36 * homepage : http://agrum.gitlab.io *
37 * gitlab : https://gitlab.com/agrumery/agrum *
38 * *
39 ****************************************************************************/
40
41
48#ifndef GUM_INDEXED_TREE_H
49#define GUM_INDEXED_TREE_H
50
51#include <iostream>
52
53#include <agrum/agrum.h>
54
56
57namespace gum {
58
59 // =========================================================================
60 // === NODES FOR GENERIC TREE (DATA) STRUCTURE === */
61 // =========================================================================
62
72 template < typename Key, typename Data >
74 public:
75 // ============================================================================
77 // ============================================================================
79
88 IndexedTree(Data* data = nullptr);
89
103 IndexedTree(const Key& theKey, Data* data = nullptr);
104
114 IndexedTree(const Key& theKey, const Data& data);
115
121
128
132 ~IndexedTree();
133
135 // ============================================================================
137 // ============================================================================
139
149 void insertNode(const std::vector< Key >& index, const Data* data);
150
160 void insertNode(const std::vector< Key >& index, const Data& data);
161
169 void setNode(const std::vector< Key >& index, Data* data);
170
178 void setNode(const std::vector< Key >& index, const Data& data);
179
188 Data& getData(const std::vector< Key >& index) const;
189
197 IndexedTree< Key, Data >& getNode(const std::vector< Key >& index) const;
198
200
201 private:
203 Key key;
204
206 Data* data;
207
210
213 };
214
216 template < typename Key, typename Data >
217 std::ostream& operator<<(std::ostream&, const IndexedTree< Key, Data >&);
218
219} /* namespace gum */
220
221// always include the templated implementations
223
224#endif /* GUM_INDEXED_TREE_H */
The class for generic Hash Tables.
Definition hashTable.h:637
The class for storing the nodes of the Arborescence.
Definition indexedTree.h:73
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.
~IndexedTree()
Class destructor.
void setNode(const std::vector< Key > &index, Data *data)
Updates the value of a node (or adds it if it does not already exist).
Data & getData(const std::vector< Key > &index) const
Returns the value of a given node of the tree.
HashTable< Key, IndexedTree< Key, Data > * > children
The list of children nodes of the current node.
Key key
The key of the current node.
IndexedTree< Key, Data > * parent
The parent of the node.
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.
IndexedTree(Data *data=nullptr)
Creates a tree with one node with or without data.
Class hash tables iterators.
Implementation of tree data structures.
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
std::ostream & operator<<(std::ostream &stream, const AVLTree< Val, Cmp > &tree)
display the content of a tree
Definition AVLTree.h:913