1#ifndef COMMA_PROJECT_TREE_H
2#define COMMA_PROJECT_TREE_H
33 typename CoMMAIndexType,
34 typename CoMMAWeightType,
35 typename CoMMAIntType>
38 Node(CoMMAIndexType index, CoMMAWeightType volume) :
65 typename CoMMAIndexType,
66 typename CoMMAWeightType,
67 typename CoMMAIntType>
76 explicit Tree(std::shared_ptr<NodeType> &root) :
83 std::shared_ptr<NodeType>
_root;
92 const CoMMAIndexType &father_index,
93 const CoMMAIndexType &index,
94 const CoMMAWeightType &volume,
95 const CoMMAIntType &root
97 std::shared_ptr<NodeType> insertion =
98 std::make_shared<NodeType>(index, volume);
101 assert(u_p_father !=
nullptr);
102 insertion->_father = u_p_father;
103 auto left_idx =
transverse(u_p_father->_left_son_idx);
104 if (left_idx ==
nullptr) {
105 u_p_father->_left_son_idx = insertion;
107 insertion->_left_idx = left_idx;
108 left_idx->_right_idx = insertion;
110 u_p_father->_sonc = u_p_father->_sonc + 1;
120 std::shared_ptr<NodeType> &node,
const CoMMAIndexType &value
122 if (node->_index == value && node->_father !=
nullptr) {
125 if (node ==
nullptr || node->_right_idx ==
nullptr) {
128 return (
search(node->_right_idx, value));
135 std::shared_ptr<NodeType>
transverse(std::shared_ptr<NodeType> &node) {
136 if (node ==
nullptr || node->_right_idx ==
nullptr) {
154 std::shared_ptr<NodeType> &searched_node,
const CoMMAIndexType &value
156 if (searched_node ==
nullptr) {
159 if (searched_node->_index == value) {
161 if (searched_node->_left_idx ==
nullptr) {
162 searched_node->_father->_sonc--;
163 searched_node->_father->_left_son_idx = searched_node->_right_idx;
164 searched_node->_right_idx->_left_idx =
nullptr;
167 else if (searched_node->_right_idx ==
nullptr) {
168 searched_node->_father->_sonc = searched_node->_father->_sonc - 1;
169 searched_node->_left_idx->_right_idx.reset();
171 searched_node->_father->_sonc--;
172 searched_node->_left_idx->_right_idx = searched_node->_right_idx;
173 searched_node->_right_idx->_left_idx = searched_node->_left_idx;
187 if (node ==
nullptr) {
Node data structure that represent a node of the tree.
Definition: Tree.h:36
std::shared_ptr< Node > _right_idx
Shared pointer to the right element.
Definition: Tree.h:51
std::shared_ptr< Node > _left_son_idx
Shared pointer to the left element.
Definition: Tree.h:53
std::shared_ptr< Node > _father
Shared pointer to the father node.
Definition: Tree.h:47
CoMMAWeightType _volume
Volume.
Definition: Tree.h:43
std::shared_ptr< Node > _left_idx
Shared pointer to the left element.
Definition: Tree.h:49
CoMMAIntType _sonc
Number of son.
Definition: Tree.h:45
Node(CoMMAIndexType index, CoMMAWeightType volume)
Definition: Tree.h:38
CoMMAIndexType _index
Index of the cell.
Definition: Tree.h:41
Tree structure that represent a coarse cell, the fine cell and the neighbours to them.
Definition: Tree.h:68
void print_nodes(std::shared_ptr< NodeType > &node)
Print the branches starting from a given node.
Definition: Tree.h:186
std::shared_ptr< NodeType > _root
The Node at the root of the tree.
Definition: Tree.h:83
void deleteNode(const CoMMAIndexType &value)
Delete a node.
Definition: Tree.h:145
void insertSon(const CoMMAIndexType &father_index, const CoMMAIndexType &index, const CoMMAWeightType &volume, const CoMMAIntType &root)
Insert a node as child of a given node.
Definition: Tree.h:91
std::shared_ptr< NodeType > transverse(std::shared_ptr< NodeType > &node)
Traverse the tree.
Definition: Tree.h:135
void print()
Print the tree.
Definition: Tree.h:181
std::shared_ptr< NodeType > search(std::shared_ptr< NodeType > &node, const CoMMAIndexType &value)
Look for a node.
Definition: Tree.h:119
void delete_node(std::shared_ptr< NodeType > &searched_node, const CoMMAIndexType &value)
Delete a node.
Definition: Tree.h:153
~Tree()=default
Destructor.
Tree(std::shared_ptr< NodeType > &root)
Constructor.
Definition: Tree.h:76
Definition: Agglomerator.h:37