-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheqclass.cpp
executable file
·127 lines (105 loc) · 2.77 KB
/
eqclass.cpp
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
#include <stack>
#include "eqclass.h"
#include "treeminer.h"
Eqnode::Eqnode(int v, int p, int s):
val(v), pos(p), sup(s){}
Eqclass::Eqclass(){
}
Eqclass::~Eqclass(){
}
void Eqclass::add_node(int val, int pos, int sup)
{
Eqnode *eqn = new Eqnode(val,pos,sup);
_nodelist.push_back(*eqn);
}
int Eqclass::item(int n) {
int i,k;
//cout << "in item: " << n << " " << _prefix.size() << endl;
for (i=0,k=0; i < _prefix.size(); i++){
if (_prefix[i] != BranchIt){
if (k == n) return _prefix[i];
k++;
}
}
return -1;
}
void Eqclass::set_prefix(vector<int> &pref, Eqnode &node)
{
int i;
_prefix = pref;
int scope, scnt;
scnt = get_scope(node.pos, scope); //what is the scope of node.pos
while(scnt > scope){
_prefix.push_back(BranchIt);
scnt--;
}
_prefix.push_back(node.val);
}
//return the scope of the prefix
int Eqclass::get_scope(int pos, int &scope){
int scnt=0;
for (int i=0; i < _prefix.size(); i++){
if (_prefix[i] == BranchIt) scnt--;
else scnt++;
if (i == pos) scope = scnt;
}
return scnt;
}
//return the parent pos of the node at pos; pos must be within range
int Eqclass::child_of (int pos){
int i, k, retval;
static stack<int> stk;
for (i=0, k=0; i < pos; i++){
if (_prefix[i] == BranchIt) stk.pop();
else{
stk.push(k);
k++;
}
}
if (stk.empty()) retval = 0;
else retval = stk.top();
while (!stk.empty()) stk.pop();
return retval;
}
//print with items remapped to their original value
void Eqclass::print(Dbase_Ctrl_Blk *DCB){
list<Eqnode>::iterator ni = _nodelist.begin();
int st, en;
for (; ni != _nodelist.end(); ni++){
for (int i=0; i < _prefix.size(); i++){
if (_prefix[i] == BranchIt) cout << BranchIt << " ";
else cout << DCB->FreqIdx[_prefix[i]] << " ";
}
en = get_scope(ni->pos, st);
while (en > st){
st++;
cout << BranchIt << " ";
}
cout << DCB->FreqIdx[ni->val] << " - " << ni->sup << endl;
}
}
ostream& operator << (ostream& fout, Eqclass& eq)
{
int i;
//fout << "PREFIX:";
//for (i=0; i < eq._prefix.size(); i++)
// fout << " " << eq._prefix[i];
//fout << endl;
list<Eqnode>::iterator ni = eq._nodelist.begin();
//fout << "NODELIST:" << endl;
int st, en;
for (; ni != eq._nodelist.end(); ni++){
fout << eq.prefix();
//for (i=0; i < eq._prefix.size(); i++)
// if (eq._prefix[i] == BranchIt) fout << BranchIt << " ";
// else fout << Dbase_Ctrl_Blk::FreqIdx[eq._prefix[i]] << " ";
en = eq.get_scope(ni->pos, st);
while (en > st){
st++;
fout << " " << BranchIt;
}
//fout << Dbase_Ctrl_Blk::FreqIdx[ni->val] << " - " << ni->sup << endl;
fout << " " << ni->val << " - " << ni->sup << endl;
}
return fout;
}