Cytnx v0.7.6
Loading...
Searching...
No Matches
search_tree.hpp
Go to the documentation of this file.
1#ifndef _H_search_tree_
2#define _H_search_tree_
3
4#include "Type.hpp"
5#include "UniTensor.hpp"
6#include "cytnx_error.hpp"
7#include "utils/utils.hpp"
8#include <vector>
9#include <map>
10#include <string>
11
12namespace cytnx{
14 class PsudoUniTensor{
15 public:
16 //UniTensor utensor; //don't worry about copy, because everything are references in cytnx!
17 std::vector<cytnx_int64> labels;
18 std::vector<cytnx_uint64> shape;
19 bool is_assigned;
20 PsudoUniTensor *left;
21 PsudoUniTensor *right;
22 PsudoUniTensor *root;
23 cytnx_float cost;
24 cytnx_uint64 ID;
25
26 std::string accu_str;
27
28 PsudoUniTensor():is_assigned(false), left(nullptr), right(nullptr), root(nullptr), cost(0),ID(0){
29 };
30 PsudoUniTensor(const PsudoUniTensor &rhs){
31 this->left = rhs.left;
32 this->right = rhs.right;
33 this->root = rhs.root;
34 this->labels = rhs.labels;
35 this->shape = rhs.shape;
36 this->is_assigned = rhs.is_assigned;
37 this->cost = rhs.cost;
38 this->accu_str = rhs.accu_str;
39 this->ID = rhs.ID;
40 }
41 PsudoUniTensor& operator==(const PsudoUniTensor &rhs){
42 this->left = rhs.left;
43 this->right = rhs.right;
44 this->root = rhs.root;
45 this->labels = rhs.labels;
46 this->shape = rhs.shape;
47 this->is_assigned = rhs.is_assigned;
48 this->cost = rhs.cost;
49 this->accu_str = rhs.accu_str;
50 this->ID = rhs.ID;
51 return *this;
52 }
53 void from_utensor(const UniTensor &in_uten){
54 this->labels = in_uten.labels();
55 this->shape = in_uten.shape();
56 this->is_assigned = true;
57 }
58 void clear_utensor(){
59 this->is_assigned = false;
60 this->labels.clear();
61 this->shape.clear();
62 this->ID = 0;
63 this->cost = 0;
64 this->accu_str = "";
65 }
66 void set_ID(const cytnx_int64 &ID){
67 this->ID = ID;
68 }
69
70 };
71
72 class SearchTree{
73 public:
74 std::vector< std::vector<PsudoUniTensor> > nodes_container;
75 //std::vector<PsudoUniTensor> nodes_container; // this contains intermediate layer.
76 std::vector<PsudoUniTensor> base_nodes; // this is the button layer.
77
78 SearchTree(){};
79 SearchTree(const SearchTree &rhs){
80 this->nodes_container = rhs.nodes_container;
81 this->base_nodes = rhs.base_nodes;
82 }
83 SearchTree& operator==(const SearchTree &rhs){
84 this->nodes_container = rhs.nodes_container;
85 this->base_nodes = rhs.base_nodes;
86 return *this;
87 }
88
89 // clear all the elements in the whole tree.
90 void clear(){
91 nodes_container.clear();
92 base_nodes.clear();
93 //nodes_container.reserve(1024);
94 }
95 // clear all the intermediate layer, leave all the base_nodes intact.
96 // and reset the root pointer on the base ondes
97 void reset_search_order(){
98 nodes_container.clear();
99 }
100 void search_order();
101 };
103}//namespace
104#endif
Definition Accessor.hpp:12
float cytnx_float
Definition Type.hpp:21
Tensor operator==(const Tensor &Lt, const Tensor &Rt)
uint64_t cytnx_uint64
Definition Type.hpp:22