-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDependencySet.c
More file actions
164 lines (139 loc) · 3.88 KB
/
DependencySet.c
File metadata and controls
164 lines (139 loc) · 3.88 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
#include "DependencySet.h"
#include "ReazienerUtils.h"
DependencySet DEPENDENCYSET_EMPTY;
DependencySet DEPENDENCYSET_DUMMY;
DependencySet DEPENDENCYSET_INDEPENDENT;
extern int g_iCommentIndent;
void bitsetOr(dynamic_bitset* pSetTarget, dynamic_bitset* pSetSource)
{
if( pSetTarget->size() < pSetSource->size() )
{
int iDiff = pSetSource->size()-pSetTarget->size();
for(int i = 0; i < iDiff; i++)
pSetTarget->push_back(FALSE);
}
int iSize = pSetSource->size();
for(int i = 0; i < iSize; i++ )
{
bool b1 = pSetTarget->at(i);
bool b2 = pSetSource->at(i);
(*pSetTarget)[i] = b1|b2;
}
}
DependencySet::DependencySet(ExprNode* pExpr)
{
m_iBranch = NO_BRANCH;
if( pExpr )
m_setExplain.insert(pExpr);
}
DependencySet::DependencySet(ExprNodeSet* pExprSet)
{
m_iBranch = NO_BRANCH;
m_setExplain = (*pExprSet);
}
DependencySet::DependencySet(DependencySet* pDS)
{
m_iBranch = pDS->m_iBranch;
m_setExplain = pDS->m_setExplain;
m_bitsetDepends = pDS->m_bitsetDepends;
}
DependencySet::DependencySet(int iBranch)
{
m_iBranch = NO_BRANCH;
add(iBranch);
}
DependencySet* DependencySet::addExplain(ExprNodeSet* pExplain, bool bDoExplanation)
{
if( !bDoExplanation || pExplain->size() == 0 )
return this;
DependencySet* pNewDS = new DependencySet();
for(dynamic_bitset::iterator i = m_bitsetDepends.begin(); i != m_bitsetDepends.end();i++ )
pNewDS->m_bitsetDepends.push_back((bool)*i);
for(ExprNodeSet::iterator i = m_setExplain.begin(); i != m_setExplain.end(); i++ )
pNewDS->m_setExplain.insert((ExprNode*)*i);
for(ExprNodeSet::iterator i = pExplain->begin(); i != pExplain->end(); i++ )
pNewDS->m_setExplain.insert((ExprNode*)*i);
return pNewDS;
}
void DependencySet::removeExplain(ExprNode* pExplain)
{
if( m_setExplain.find(pExplain) != m_setExplain.end() )
m_setExplain.clear();
}
bool DependencySet::isIndependent()
{
return (getMax() <= 0);
}
/**
* Create a new DependencySet and all the elements of <code>this</code>
* and <code>ds</code> (Neither set is affected when the return the set is
* modified).
*/
DependencySet* DependencySet::unionNew(DependencySet* pDS, bool bDoExplanation)
{
DependencySet* pNewDS = new DependencySet();
pNewDS->m_iBranch = NO_BRANCH;
if( bDoExplanation )
{
pNewDS->m_setExplain = m_setExplain;
pNewDS->m_setExplain.insert(pDS->m_setExplain.begin(), pDS->m_setExplain.end());
}
pNewDS->m_bitsetDepends = m_bitsetDepends;
bitsetOr(&(pNewDS->m_bitsetDepends), &(pDS->m_bitsetDepends));
return pNewDS;
}
DependencySet* DependencySet::unionDS(DependencySet* pDS, bool bDoExplanation)
{
bitsetOr(&m_bitsetDepends, &(pDS->m_bitsetDepends));
if( bDoExplanation )
{
// UNION (TargetDS.Explainations, SourceDS.Explainations)
m_setExplain.insert(pDS->m_setExplain.begin(), pDS->m_setExplain.end());
}
else
{
m_setExplain.clear();
}
return this;
}
int DependencySet::getMax()
{
for(int i = m_bitsetDepends.size()-1; i >= 0; i-- )
{
if( m_bitsetDepends.at(i) == TRUE )
return i;
}
return -1;
}
bool DependencySet::contains(int b)
{
if( b < m_bitsetDepends.size() )
return (m_bitsetDepends.at(b)==TRUE);
return FALSE;
}
void DependencySet::add(int b)
{
START_DECOMMENT2("DependencySet::add");
DECOMMENT1("b=%d", b);
if( b >= m_bitsetDepends.size() )
{
int iNewSize = (b-m_bitsetDepends.size())+1;
for(int i = 0; i < iNewSize; i++ )
m_bitsetDepends.push_back(FALSE);
}
m_bitsetDepends[b] = TRUE;
END_DECOMMENT("DependencySet::add");
}
void DependencySet::remove(int b)
{
START_DECOMMENT2("DependencySet::remove");
DECOMMENT1("b=%d", b);
if( b >= m_bitsetDepends.size() )
{
int iNewSize = (b-m_bitsetDepends.size())+1;
for(int i = 0; i < iNewSize; i++ )
m_bitsetDepends.push_back(FALSE);
}
m_bitsetDepends[b] = FALSE;
END_DECOMMENT("DependencySet::remove");
}