-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCLabelledTreeCountII.cpp
More file actions
168 lines (162 loc) · 4.6 KB
/
CLabelledTreeCountII.cpp
File metadata and controls
168 lines (162 loc) · 4.6 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#include "CLabelledTreeCountII.h"
#undef _CLABELLEDTREECOUNT_DEBUG_
CLabelledTreeCountII::CLabelledTreeCountII(CBvMatrix* pMatrix, CBvLookupTable* pLut)
{
m_pMatrix = pMatrix;
m_pLut = pLut;
m_nAllNodes = pMatrix->GetMatrix().begin()->second.size();
cout << "node 1:" << pMatrix->GetMatrix().begin()->first << endl;
cout << "all nodes:" << m_nAllNodes << endl;
pMatrix->Output(cout);
m_pSDVec = pMatrix->GetSDBitVec();
sd_vector<>::select_0_type sel(m_pSDVec);
m_sdx_sel = sel;
}
bool CLabelledTreeCountII::Count(vector<string> pattern, int& iPatternCnt)
{
iPatternCnt = 0;
if (pattern.size() >= 2)
{
map<string, int> lut = m_pLut->GetLUT();
if (lut.find(pattern[0]) == lut.end())
return false;
CRange currentRange;
currentRange.m_iStart = lut[pattern[0]];
map<string, int>::iterator itLut = lut.find(pattern[0]);
itLut++;
if (itLut != lut.end())
currentRange.m_iEnd = itLut->second - 1;
else
currentRange.m_iEnd = m_nAllNodes - 1;
currentRange.m_ucIsNull = 0;
//cout << "-------------------" << currentRange.ToString() <<"-------------------" << endl;
const map<string, vector<int> >& mat = m_pMatrix->GetMatrix();
for (int i = 1; i < pattern.size(); i++)
{
int iCnt = 0;
bool found = false;
map<string, vector<int> >::const_iterator it = mat.begin();
//cout << "XXXX " << pattern[i] << endl;
for (; it != mat.end(); it++)
{
if (pattern[i] == it->first)
{
found = true;
break;
}
else
iCnt++;
}
if (!found)
{
iPatternCnt = 0;
return false;
}
int l = m_nAllNodes * iCnt + currentRange.m_iStart/*-1+1*/;
int r = m_nAllNodes * iCnt + currentRange.m_iEnd + 1;
int sell = m_sdx_sel(l);
int selr = m_sdx_sel(r);
int rank_l = sell - (l - 1);
int rank_r = selr - (r - 1);
currentRange.m_iStart = rank_l + 1;
currentRange.m_iEnd = rank_r;
//cout << "=============" << currentRange.ToString() <<"=============" << endl;
}
iPatternCnt = currentRange.m_iEnd - currentRange.m_iStart + 1;
return true;
}
else if (pattern.size() == 1)
{
map<string, int> lut = m_pLut->GetLUT();
if (lut.find(pattern[0]) == lut.end())
return false;
CRange currentRange;
currentRange.m_iStart = lut[pattern[0]];
map<string, int>::iterator itLut = lut.find(pattern[0]);
itLut++;
if (itLut != lut.end())
currentRange.m_iEnd = itLut->second - 1;
else
currentRange.m_iEnd = m_nAllNodes - 1;
currentRange.m_ucIsNull = 0;
iPatternCnt = currentRange.m_iEnd - currentRange.m_iStart + 1;
return true;
}
/*
if (pattern.size() >= 2)
{
map<string, int> lut = m_pLut->GetLUT();
map<int, int> set;
string lastString = pattern[pattern.size() - 1];
int iTmpStart = lut[lastString];
map<string, int>::iterator itLut = lut.find(lastString);
itLut++;
int iTmpEnd = -1;
if (itLut != lut.end())
iTmpEnd = (*itLut).second - 1;
else
iTmpEnd = m_nAllNodes - 1;
for (int i = iTmpStart; i <= iTmpEnd; i++)
{
set.insert(pair<int, int>(i, 0));
}
sd_vector<>::select_1_type* pSel1 = 0x00;
sd_vector<>::rank_0_type* pRanker = 0x00;
m_pMatrix->ParentSDPrepare(pSel1, pRanker);
for (int i = pattern.size() - 1; i >=1; i--)
{
string rowInd = pattern[i];
string colInd = pattern[i - 1];
#ifdef _CLABELLEDTREECOUNT_DEBUG_
cout << "row:" << rowInd << " col:" << colInd << endl;
#endif
CRange range = m_2DArray[rowInd][colInd];
#ifdef _CLABELLEDTREECOUNT_DEBUG_
cout << range.ToString() << endl;
#endif
map<int, int> filteredSet = FilterSet(set, range);
map<int, int>::iterator it = filteredSet.begin();
set.clear();
//cout << "ST0" << endl;
for (; it != filteredSet.end(); it++)
{
//int parent = m_pMatrix->ParentBV(it->first);
int parent = m_pMatrix->ParentSDRun( pSel1, pRanker, it->first);
if (set.find(parent) == set.end())
{
set.insert(pair<int, int>(parent, 0));
}
}
//cout << "Start2" << endl;
#ifdef _CLABELLEDTREECOUNT_DEBUG_
cout << "--------" << endl;
#endif
}
m_pMatrix->ParentSDDelete( pSel1, pRanker);
iPatternCnt = set.size();
nodes = set;
return true;
}
else if (pattern.size() == 1)
{
map<string, int> lut = m_pLut->GetLUT();
if (lut.find(pattern[0]) == lut.end())
return 0;
int iTmpStart = lut[pattern[0]];
map<string, int>::iterator itLut = lut.find(pattern[0]);
itLut++;
int iTmpEnd = -1;
if (itLut != lut.end())
iTmpEnd = (*itLut).second - 1;
else
iTmpEnd = m_nAllNodes - 1;
iPatternCnt = iTmpEnd - iTmpStart + 1;
map<int, int> set;
for (int i = iTmpStart; i <= iTmpEnd; i++)
set.insert(pair<int, int>(i, 0));
nodes = set;
return true;
}
*/
return false;
}