-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmultiTree.h
More file actions
153 lines (120 loc) · 3.78 KB
/
multiTree.h
File metadata and controls
153 lines (120 loc) · 3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
//
// Created by wang mengbo on 2019-09-03.
//
#ifndef PROGRAM_MULTITREE_H
#define PROGRAM_MULTITREE_H
#include <vector>
#include <set>
#include <iostream>
#include <string>
#include <sstream>
#include "params.h"
#include "data.h"
namespace SuperTAD::multi {
struct TreeNode {
int _val[2];
double _info=0, _g=0, _vol=0, _se=0;
int _index = 0;
std::vector<TreeNode*> _children;
TreeNode *_parent=NULL;
TreeNode(int start, int end) {
_val[0] = start;
_val[1] = end;
}
~TreeNode() {
if (! _children.empty()){
for (auto i : _children)
i = nullptr;
}
}
TreeNode& operator=(const TreeNode ©) {
_val[0] = copy._val[0];
_val[1] = copy._val[1];
_info = copy._info;
_g = copy._g;
_vol = copy._vol;
_children = copy._children;
_parent = copy._parent;
return *this;
}
bool operator==(const TreeNode &t) const {
return _val[0] == t._val[0] && _val[1] == t._val[1];
}
bool hasOverLapChild(const TreeNode &t) const {
for (auto i : _children)
{
if ((i->_val[0] - t._val[1]) * (i->_val[1] - t._val[0]) < 0)
return true;
}
return false;
}
bool hasBiggerChild(const TreeNode &t) const {
for (auto i : _children)
{
if (i->_val[0] <= t._val[0] && i->_val[1] >= t._val[0])
return true;
}
return false;
}
std::string verbose(int numHeadingSpace=0) const {
std::stringstream iss;
iss << "self=(" << _val[0] << ", " << _val[1] << ")";
iss << ", info=" << _info << ", len(children)=" << _children.size();
if (_parent) {
iss << ", parent=(" << _parent->_val[0] << ", " << _parent->_val[1] << ")";
}
else {
iss << ", no parent";
}
iss << ", vol=" << _vol;
iss << ", se=" << _se;
return iss.str();
}
void setG(Data &data)
{
_g = data.getG(_val[0], _val[1]);
}
void setVol(Data &data)
{
_vol = data.getVol(_val[0], _val[1]);
}
void setSE(Data &data)
{
_se = data.getSE(_val[0], _val[1], _parent->_val[0], _parent->_val[1]);
}
};
inline bool operator<(const TreeNode &t1, const TreeNode &t2)
{
return t1._val[1] < t2._val[0];
}
inline std::ostream& operator<<(std::ostream &os, const TreeNode &node)
{
os << node.verbose();
return os;
}
inline void treeNodeVerbose(multi::TreeNode &node, int numHeadingSpace=0)
{
for (int i=0; i<numHeadingSpace; i++)
std::cout << " ";
std::cout << node << "\n";
std::reverse(node._children.begin(), node._children.end());
}
class Tree {
private:
// std::vector<TreeNode*> _nodeList;
public:
Data *_data;
TreeNode *_root = NULL;
std::vector<TreeNode*> _nodeList; // Not containing root
Tree();
Tree(Data &d);
~Tree();
void setData(Data &d);
TreeNode *add(int start, int end);
bool insert(TreeNode &newNode, TreeNode &parent);
void preOrderTraversal(TreeNode &node);
void getPreOrder();
// std::vector<TreeNode*> &nodeList() { return _nodeList; }
};
}
#endif //PROGRAM_MULTITREE_H