aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
binTreeNode.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
47
48#ifndef GUM_BIN_TREE_NODE_H
49#define GUM_BIN_TREE_NODE_H
50
51#include <agrum/agrum.h>
52
53namespace gum {
54
56 enum class BinTreeDir : char { LEFT_CHILD = 0, RIGHT_CHILD = 1, NO_PARENT = 2 };
57
58 // ===========================================================================
59 // === GENERIC NODE FOR A BINARY TREE ===
60 // ===========================================================================
61
118 template < typename Val >
120 public:
121 // ============================================================================
123 // ============================================================================
125
130 BinTreeNode(const Val& v);
131
142
150
152 // ============================================================================
154 // ============================================================================
156
167
172 Val& operator*();
173
175 // ============================================================================
177 // ============================================================================
179
184 Val& value();
185
193
200
207
214
220
230
238
248
256
265 BinTreeNode< Val >* insertChild(const Val& val, BinTreeDir child_dir);
266
274 void insertChild(BinTreeNode< Val >& new_child, BinTreeDir child_dir);
275
285
295
305 void eraseLink(BinTreeDir tree_dir);
306
315
324
333
335
336 protected:
338 Val val_;
339
342
345
348 };
349
350} /* namespace gum */
351
352
353#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
354extern template class gum::BinTreeNode< int >;
355#endif
356
357
358// always include the implementation of the templates
360
361#endif // GUM_BIN_TREE_NODE_H
Node class for various binary search trees.
Nodes of a binary trees.
BinTreeNode< Val > * insertChild(const Val &val, BinTreeDir child_dir)
Adds a new child to the current node.
~BinTreeNode()
Class destructor.
BinTreeDir parentDir() const
Returns the direction of the edge parent->current node, if any.
BinTreeNode< Val > & operator=(const BinTreeNode< Val > &from)
Copy operator: copy the value of from into this.
void insertChild(BinTreeNode< Val > &new_child, BinTreeDir child_dir)
Adds a new child to the current node.
void eraseLeftLink()
Remove the link between the current node and its left child.
BinTreeNode< Val > * parent_
The parent of the node.
BinTreeNode< Val > * rightmostNode() const
Returns the rightmost node of the current tree.
BinTreeNode< Val > * leftmostNode() const
Returns the leftmost node of the current tree.
BinTreeNode< Val > * rightChild() const
Returns the given child of a node.
BinTreeNode< Val > * children_[2]
The children of the current node.
Val val_
The value stored in a node of the tree.
BinTreeDir parent_dir_
the direction to follow from the parent to reach the current node.
void eraseRightLink()
Remove the link between the current node and its right child.
BinTreeNode< Val > * insertRightChild(const Val &val)
Adds a new left child to the current node.
BinTreeNode< Val > * leftChild() const
Returns the given child of a node.
BinTreeNode(const BinTreeNode< Val > &from)
copy constructor: creates a new disconnected node with the same value as "from".
void insertRightChild(BinTreeNode< Val > &new_child)
Adds a new right child to the current node.
Val & value()
Returns the value stored in a node of the binary search tree.
void insertLeftChild(BinTreeNode< Val > &new_child)
Adds a new left child to the current node.
BinTreeNode< Val > * insertLeftChild(const Val &val)
Adds a new left child to the current node.
BinTreeNode< Val > * root() const
Returns the top ancestor of the current tree.
BinTreeNode< Val > * child(BinTreeDir dir) const
Returns the given child of a node.
BinTreeNode< Val > * parent() const
Returns the parent of a node.
void eraseLink(BinTreeDir tree_dir)
Remove the link between the current node and one of its children.
Val & operator*()
Alias for method value.
BinTreeNode(const Val &v)
Basic constructor: a node without parent nor children.
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
BinTreeDir
The direction of a given edge in a binary tree.
Definition binTreeNode.h:56