-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCLabelledTreeCount.cpp
More file actions
112 lines (105 loc) · 2.97 KB
/
CLabelledTreeCount.cpp
File metadata and controls
112 lines (105 loc) · 2.97 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
#include "CLabelledTreeCount.h"
#undef _CLABELLEDTREECOUNT_DEBUG_
CLabelledTreeCount::CLabelledTreeCount(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_2DArray = pMatrix->Get2DArray(*pLut);
}
map<int, int> CLabelledTreeCount::FilterSet(map<int, int> set, CRange range)
{
map<int, int> res;
if (!range.m_ucIsNull)
{
map<int, int>::iterator it = set.begin();
for (; it != set.end(); it++)
{
if ((*it).first <= range.m_iEnd && (*it).first >= range.m_iStart)
res.insert(pair<int, int>((*it).first, 0));
}
return res;
}
return res;
}
bool CLabelledTreeCount::Count(vector<string> pattern, int& iPatternCnt, map<int, int>& nodes)
{
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;
}