CMMTree v1.0
cmmtree.hpp
Go to the documentation of this file.
1#ifndef _cmmtree_hpp_
2#define _cmmtree_hpp_
3//---------------------------------------------
4
5#include <functional>
6#include <chrono>
7#include <iomanip>
8
9#include "predicates.hpp"
10
19template <class X1, template<typename> class predicate >
21{
22 using firstborns = std::vector < node<X1>* > ;
23 using generations = std::vector < firstborns > ;
24
25 node<X1>* root ;
26 std::vector < X1 >const* p_dataset ;
27 predicate<X1> condition ;
28 generations MTree ;
29
30 void add_next_firstborn(size_t generation, node<X1>* const& node_adr);
31 void jagged_table_reconstruction(size_t lev);
32 void find_new_generation( size_t generation );
33
34 public:
43 CMMTree(): root( new node<X1>() ), p_dataset(nullptr){
44 MTree.push_back( firstborns( 1, root ) );
45 }
46
57 CMMTree( std::vector < X1 >const* const& adr ): root( new node<X1>() ), p_dataset(adr){
58 MTree.push_back( firstborns( 1, root ) );
59 }
60
72 CMMTree( std::vector < X1 >const* const& adr, typename std::vector<X1>::const_iterator const& pos ): root( new node<X1>() ), p_dataset(adr){
73 root->data_address()=pos;
74 MTree.push_back( firstborns( 1, root ) );
75 }
76
82
88
94 CMMTree(CMMTree&& other) noexcept
95 : root{std::move(other.root)}, p_dataset{std::move(other.p_dataset)}, condition{other.condition}, MTree{std::move(other.MTree)}
96 {
97 other.root = new node<X1>();
98 other.p_dataset = nullptr;
99 other.MTree.emplace_back( firstborns( 1, other.root ) );
100 }
101
108 auto operator=(CMMTree&& other) noexcept ->CMMTree<X1, predicate>& {
109 if(this != &other){
110 delete root;
111 root = std::move(other.root);
112 p_dataset = std::move(other.p_dataset);
113 condition = other.condition;
114 MTree = std::move(other.MTree);
115
116 other.root = new node<X1>();
117 other.p_dataset = nullptr;
118 other.MTree.emplace_back( firstborns( 1, other.root ) );
119 }
120 return *this;
121 }
122
128 delete root;
129 }
130
137 void create_subtrees_roots( std::vector < X1 > const& roots_data );
138
148 void join_data(std::vector < X1 >const* const& adr);
149
160 void join_data(std::vector < X1 >const* const& adr, typename std::vector<X1>::const_iterator const& pos);
161
168 long long tree_create();
169
175 predicate<X1>& pred_value(){ return condition; }
176
181 predicate<X1>const& pred_value()const{ return condition; }
182
190 X1 const& firstborn_value(size_t i, size_t j)const {
191 return firstborn_address(i, j)->node_value();
192 }
193
198 size_t all_nodes_number()const{
199 size_t an(0);
200 for(size_t i=0; i<MTree.size(); ++i)
201 an+=generation_size(i);
202
203 return an;
204 }
205
211 size_t firstborns_number(size_t i)const;
212
218 size_t leaves_number(size_t i)const;
219
225 size_t generation_size(size_t i)const;
226
231 size_t tree_height()const { return MTree.size() - 1; }
232
240 void generation_addresses(size_t i, std::vector< const node<X1>* > & vec)const;
241
249 void generation_addresses(size_t i, std::vector< node<X1>* > & vec)const;
250
257 void leaves_addresses(size_t i, std::vector< const node<X1>* > & vec)const; //leaves addresses - at the level passed by the first argument
258
266 const node<X1>* brother_address( const node<X1>* ptr, size_t i)const;
267
275 node<X1>const* const& firstborn_address(size_t i, size_t j)const;
276
281 std::vector < X1 >const* const& P_dataset()const { return p_dataset; }
282
292 void delete_one_node( node<X1>* &to_del );
293
306 void delete_nodes( std::vector< node<X1>* > & to_del, size_t lev );
307
317 void tree_clear();
318
326 void tree_shape(std::ostream& out)const;
327
338 template <class T1, template<typename> class T2>
339 friend
340 std::ostream& operator<<(std::ostream& out, CMMTree<T1, T2> const& ref) ;
341};
342
343//---------------------------------------------
344#endif
The Conditional Multiway Mapped Tree (CMMTree) class definition.
Definition cmmtree.hpp:21
size_t firstborns_number(size_t i) const
This function returns the number of firstborn nodes of one generation of the CMMTree - at the level p...
Definition cmmtree.cpp:87
X1 const & firstborn_value(size_t i, size_t j) const
A function that allows you to read the value of [i,j]-th firstborn node.
Definition cmmtree.hpp:190
friend std::ostream & operator<<(std::ostream &out, CMMTree< T1, T2 > const &ref)
Overloaded output operator to the stream.
size_t generation_size(size_t i) const
This function returns the total number of nodes one generation of the CMMTree - at the level passed b...
Definition cmmtree.cpp:110
void generation_addresses(size_t i, std::vector< const node< X1 > * > &vec) const
This function allows you to get all the addresses of the i-th generation firstborn nodes....
Definition cmmtree.cpp:122
void tree_shape(std::ostream &out) const
This function allows you to represent a tree in a parametric form.
Definition cmmtree.cpp:283
void join_data(std::vector< X1 >const *const &adr)
This function is used to connect the CMMTree object to the input data vector.
Definition cmmtree.cpp:6
CMMTree(const CMMTree< X1, predicate > &)=delete
Copy constructor. Construct of copies of CMMTree object is prohibited.
~CMMTree()
Destructor. The allocated memory for all nodes in the tree is released.
Definition cmmtree.hpp:127
auto operator=(CMMTree &&other) noexcept -> CMMTree< X1, predicate > &
Move assignment operator.
Definition cmmtree.hpp:108
predicate< X1 > const & pred_value() const
A function that allows you to read the value of a predicate object.
Definition cmmtree.hpp:181
void tree_clear()
This function clears the entire CMMTree object.
Definition cmmtree.cpp:270
long long tree_create()
A function that starts the process of the CMMTree construction.
Definition cmmtree.cpp:74
void delete_one_node(node< X1 > *&to_del)
This function deletes the node whose address is passed as an argument.
Definition cmmtree.cpp:223
CMMTree(CMMTree &&other) noexcept
Move constructor.
Definition cmmtree.hpp:94
const node< X1 > * brother_address(const node< X1 > *ptr, size_t i) const
This function allows you to obtain the address of the i-th brother of the firstborn node.
Definition cmmtree.cpp:180
void create_subtrees_roots(std::vector< X1 > const &roots_data)
This function allows you to initialize the creation of a forest using a separate data set - different...
Definition cmmtree.cpp:59
CMMTree(std::vector< X1 >const *const &adr)
Single-argument constructor.
Definition cmmtree.hpp:57
predicate< X1 > & pred_value()
A function that allows you to modify the value of a predicate object.
Definition cmmtree.hpp:175
CMMTree()
Dfefault constructor.
Definition cmmtree.hpp:43
node< X1 > const *const & firstborn_address(size_t i, size_t j) const
The function returns the address of the j-th firstborn of the i-th generation.
Definition cmmtree.cpp:188
size_t all_nodes_number() const
This function returns the number of all nodes in the CMMTree.
Definition cmmtree.hpp:198
size_t tree_height() const
This function returns the CMMTree height.
Definition cmmtree.hpp:231
CMMTree(std::vector< X1 >const *const &adr, typename std::vector< X1 >::const_iterator const &pos)
Two arguments constructor.
Definition cmmtree.hpp:72
void delete_nodes(std::vector< node< X1 > * > &to_del, size_t lev)
Using this function you can delete more than one node from a specified node generation at once.
Definition cmmtree.cpp:246
std::vector< X1 > const *const & P_dataset() const
The function returns the address of the input data vector.
Definition cmmtree.hpp:281
void leaves_addresses(size_t i, std::vector< const node< X1 > * > &vec) const
This function allows you to get all the addresses of the i-th generation leaves.
Definition cmmtree.cpp:158
CMMTree< X1, predicate > & operator=(const CMMTree< X1, predicate > &)=delete
Copy assignment operator. Copying a CMMTree object using the assignment operator is not allowed.
size_t leaves_number(size_t i) const
This function returns the number of leaves one generation of the CMMTree - at the level passed by the...
Definition cmmtree.cpp:94
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
data_addr const & data_address() const
This function returns the const_iterator to a vector<X1> element (dataset element).
Definition node.hpp:150