CMMTree v1.0
node.cpp
Go to the documentation of this file.
1#include "hpp/node.hpp"
2
3
4template <class X1>
5inline
6void node<X1>::data_on_path(std::vector< data_addr > & vec) const{
7 node<X1> const* ptr = this;
8 vec.clear();
9 while(ptr){
10 if( !isNULLit(ptr->d_iterator) ){
11 vec.push_back(ptr->d_iterator);
12 }
13 ptr = ptr->parent;
14 }
15}
16
17template <class X1>
18inline
20 #ifdef MAX_CMMTree_NODES
21 #ifdef NODE_COUNTER
22 if( n_count == MAX_CMMTree_NODES)
23 throw std::runtime_error( "node<X1>::add_new_node():\nThe number of nodes has reached an acceptable value of \"MAX_CMMTree_NODES = " + std::to_string(MAX_CMMTree_NODES) + "\".");
24 #else
25 throw std::runtime_error( "node<X1>::add_new_node():\nYou have decided to use the constant \"MAX_CMMTree_NODES = " + std::to_string(MAX_CMMTree_NODES) + "\".\nPlease uncomment the \"NODE_COUNTER\" directive and recompile the program.");
26 #endif
27 #endif
28
29 if(!children){
30 children = new std::vector< node<X1>* >(1);
31 (*children)[0] = new node<X1>(this, pos);
32 }
33 else{
34 children->emplace_back( new node<X1>( this, pos ) );
35 }
36}
37
38template <class X1>
40 if(children){
41 for(size_t i = 0; i< children->size(); ++i)
42 delete (*children)[i];
43 delete children;
44 }
45 #ifdef NODE_COUNTER
46 n_count--;
47 #endif
48}
49
50template <class X1>
51inline size_t node<X1>::node_level() const {
52 size_t lev(0); node<X1>* ptr(parent);
53 while(ptr){
54 lev++;
55 ptr=ptr->parent;
56 }
57 return lev;
58}
59
60template <class X1>
61void node<X1>::all_siblings_addresses(std::vector< const node<X1>* > & vec)const{
62 if(parent){
63 vec.resize(parent->children->size()) ;
64 for(size_t i=0; i< vec.size(); ++i)
65 vec[i] =parent->children->operator[](i);
66 }
67 else{
68 vec.resize(1);
69 vec[0] = this;
70 }
71}
72
73template <class X1>
74std::ostream& operator<<(std::ostream& out, node<X1> const& r) {
75 out << '<' << typeid(r).name() << '>';
76 out << '[' << r.this_node_address() << ']';
77
78 if (! r.parent_node_address() )
79 out << "(root,";
80 else
81 out << '(' << r.parent_node_address() << ',';
82
83 out << (! r.isNULLit( r.data_address() ) ) << ','
84 << r.children_number() << '|'
85 << r.node_level() << '|'
86 << r.siblings_number() << ')';
87
88 return out;
89}
90
The node class definition. This is a template of a class whose objects are used to build a tree of re...
Definition node.hpp:45
size_t node_level() const
This function returns the level of the CMMTree where a given node is located.
Definition node.cpp:51
node< X1 > *const & parent_node_address() const
This function returns the address of the parent node.
Definition node.hpp:173
typename std::vector< X1 >::const_iterator data_addr
Definition node.hpp:47
void data_on_path(std::vector< data_addr > &vec) const
This function allows you to find a set of elements on a path - starting from the current node to the ...
Definition node.cpp:6
size_t children_number() const
The function returns the number of children of a given node.
Definition node.hpp:188
void all_siblings_addresses(std::vector< const node< X1 > * > &vec) const
This function allows you to obtain the addresses of all children of a parent.
Definition node.cpp:61
void add_new_node(data_addr const &pos)
This function is used to create another CMMTree node.
Definition node.cpp:19
data_addr const & data_address() const
This function returns the const_iterator to a vector<X1> element (dataset element).
Definition node.hpp:150
bool isNULLit(data_addr const &r) const
This function is used when there is a need to check whether it is possible to use the data to which r...
Definition node.hpp:127
~node()
Destructor.
Definition node.cpp:39
size_t siblings_number() const
The function returns the number of children of the parent of a given node.
Definition node.hpp:195
node< X1 > const * this_node_address() const
The function returns the address of the node calling this function.
Definition node.hpp:180
std::ostream & operator<<(std::ostream &out, node< X1 > const &r)
Definition node.cpp:74