-
Notifications
You must be signed in to change notification settings - Fork 0
/
pdigraph.hpp.orig
234 lines (203 loc) · 9.72 KB
/
pdigraph.hpp.orig
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#ifndef __pdigraph__H
#define __pdigraph__H
#include "rand.h"
#include <map>
#include <vector>
#include <utility>
using namespace std;
//==============================================================================
#define PDIGRAPH_ template<class NKT,class NT,class AKT,class AT,class PKT,class PT>
#define _PDIGRAPH pdigraph<NKT,NT,AKT,AT,PKT,PT>
#define _1 first
#define _2 second
PDIGRAPH_ class pdigraph
{
public:
pdigraph(void);
pdigraph(_PDIGRAPH &);
virtual ~ pdigraph(void){}
void Clear();
bool DrivenNodes(const NKT &,vector<NKT> &);
bool DrivenNodes(const NKT &,vector<PKT> &,vector<AKT> &,
vector<PKT> &,vector<NKT> &);
bool DrivingNodes(const NKT &,vector<NKT> &);
bool DrivingNodes(const NKT &,vector<PKT> &,vector<AKT> &,
vector<PKT> &,vector<NKT> &);
void Dump();
void DumpChan(FILE * fp = stdout) { dfp = fp; }
AT * FindArc(const AKT &);
bool FindArcs(const NKT &,const PKT &,vector<AKT> &,vector<AKT> &);
bool FindArcs(const NKT &,vector<AKT> &,vector<AKT> &);
NT * FindNode(const NKT &);
bool FindNodes(const AKT &,NKT &,NKT &);
bool FindNodes(const NKT &,vector<NKT> &);
bool FindNodes(const NKT &,vector<PKT> &,vector<AKT> &,
vector<PKT> &,vector<NKT> &);
PT * FindPin(const NKT &,const PKT &);
bool FindPins(const AKT &,PKT &,PKT &);
bool FindPins(const NKT &,vector<PKT> &,vector<PKT> &);
bool FlipArc(const AKT &);
bool InsertArc(const AKT &,const NKT &,const NKT &,const AT & =AT(),
const PKT & =PKT(),const PT & =PT(),
const PKT & =PKT(),const PT & =PT());
bool InsertNode(const NKT &,const NT & =NT());
bool MoveArcFrom(const AKT &,const NKT &);
bool MoveArcTo(const AKT &,const NKT &);
void RandomNode(NKT &,NT &);
void RandomSeed(unsigned s) { RNG.seed(s); }
bool RemoveArc(const AKT &);
bool RemoveNode(const NKT &);
unsigned SizeArcs() { return index_a.size(); }
unsigned SizeNodes() { return index_n.size(); }
unsigned SizeInPins(const NKT &);
unsigned SizeOutPins(const NKT &);
struct arc; // Forward declare is public, so walking
struct node; // macros below work
struct pin;
typedef typename map<AKT,arc >::iterator TPa_it;
typedef typename map<NKT,node>::iterator TPn_it;
typedef typename multimap<PKT,pin >::iterator TPp_it;
// The guts of the thing. There appears to be no alternative to making the
// whole thing public or the walking macros won't work.
FILE * dfp; // Dumpfile channel
struct node {
node(){}
node(NT d):data(d),tag(0){} // Required for internal STL machinations
NT data; // Node data
multimap<PKT,pin> fani; // Fanin pins
multimap<PKT,pin> fano; // Fanout pins
void * tag; // For derived class use
NT operator*(void) {return data;} // Access the user data
};
struct arc {
arc(AT d):data(d),tag(0){} // Required for internal STL machinations
AT data; // Arc data
TPn_it fr_n; // Iterator to 'from' node
TPp_it fr_p; // Iterator to 'from' pin
TPn_it to_n; // Iterator to 'to' node
TPp_it to_p; // Iterator to 'to' pin
void * tag; // For the bits I forgot.....
AT operator*(void) {return data;} // Access the user data
};
struct pin {
pin(PT d):data(d),tag(0){} // Required for internal STL machinations
PT data; // Pin data
TPa_it iArc; // Iterator to connecting arc
void * tag;
PT operator*(void) {return data;} // Access the user data
};
map<NKT,node> index_n; // This is the data, the whole data, and
map<AKT,arc > index_a; // nothing but the data
inline TPa_it ArcKey2It(AKT key_a) { return index_a.find(key_a); }
inline TPn_it NodeKey2It(NKT key_n){ return index_n.find(key_n); }
inline TPp_it InPinKey2It(NKT key_n,PKT key_p)
{ return index_n[key_n].fani.find(key_p); }
inline TPp_it OutPinKey2It(NKT key_n,PKT key_p)
{ return index_n[key_n].fano.find(key_p); }
public: // Routines to do with dumping, pretty printing and walking in general
#define WALKPDIGRAPHNODES(NKT,NT,AKT,AT,PKT,PT,g,i) \
for (map<NKT,pdigraph<NKT,NT,AKT,AT,PKT,PT>::node>::iterator \
i = g.index_n.begin(); i!=g.index_n.end();i++)
#define WALKPDIGRAPHARCS(NKT,NT,AKT,AT,PKT,PT,g,i) \
for (map<AKT,pdigraph<NKT,NT,AKT,AT,PKT,PT>::arc>::iterator \
i = g.index_a.begin(); i!=g.index_a.end();i++)
#define WALKPDIGRAPHINPINS(NKT,NT,AKT,AT,PKT,PT,g,iNode,i) \
for(multimap<NKT,pdigraph<NKT,NT,AKT,AT,PKT,PT>::pin>::iterator \
i=g.index_n[iNode].fani.begin(); \
i!=g.index_n[iNode].fani.end();i++)
#define WALKPDIGRAPHOUTPINS(NKT,NT,AKT,AT,PKT,PT,g,iNode,i) \
for(multimap<NKT,pdigraph<NKT,NT,AKT,AT,PKT,PT>::pin>::iterator \
i=g.index_n[iNode].fano.begin(); \
i!=g.index_n[iNode].fano.end();i++)
#define PIN(i) (*i).second.data
TPa_it ArcBegin() { return index_a.begin(); }
AT ArcData(TPa_it i) { return *(*i)._2; }
TPa_it ArcEnd() { return index_a.end(); }
AKT ArcKey(TPa_it i) { return (*i)._1; }
TPn_it NodeBegin() { return index_n.begin(); }
NT NodeData(TPn_it i) { return *(*i)._2; }
TPn_it NodeEnd() { return index_n.end(); }
NKT NodeKey(TPn_it i) { return (*i)._1; }
//''''''''''''''''''''''''''''''''
//TPp_it InPinBegin(NKT n) { TPn_it iNode = index_n.find(n);
// if (iNode==index_n.end()) return iNode;
// return iNode.index_p.begin(); }
//PT InPinData(TPp_it i) { return *(*i)._2; }
//TPp_it InPinEnd(NKT n) { TPn_it iNode = index_n.find(n);
// if (iNode==index_n.end()) return iNode;
// return iNode.index_p.end(); }
//PKT InPinKey(TPp_it i) { return (*i)._1; }
//TPp_it OutPinBegin(NKT n) { TPn_it iNode = index_n.find(n);
// if (iNode==index_n.end()) return iNode;
// return iNode.index_p.begin(); }
//PT OutPinData(TPp_it i){ return *(*i)._2; }
//TPp_it OutPinEnd(NKT n) { TPn_it iNode = index_n.find(n);
// if (iNode==index_n.end()) return iNode;
// return iNode.index_p.end(); }
//PKT OutPinKey(TPp_it i) { return (*i)._1; }
//'''''''''''''''''''''''''''''''''
PT PinData(TPp_it i) { return *(*i)._2; }
PKT PinKey(TPp_it i) { return (*i)._1; }
void WALKARCS (void *, void(*)(void *,const AKT &,AT &));
void WALKNODES (void *, void(*)(void *,const NKT &,NT &));
bool WALKINPINS (void *,const NKT &,void(*)(void *,const PKT &,PT &));
bool WALKOUTPINS(void *,const NKT &,void(*)(void *,const PKT &,PT &));
// SETS the callback functions on the graph components
void SetAD_CB(void (* f)(const AT &)=0){cb.AD_cb=f;}
void SetAK_CB(void (* f)(const AKT &)=0){cb.AK_cb=f;}
void SetND_CB(void (* f)(const NT &)=0){cb.ND_cb=f;}
void SetNK_CB(void (* f)(const NKT &)=0){cb.NK_cb=f;}
void SetPD_CB(void (* f)(const PT &)=0){cb.PD_cb=f;}
void SetPK_CB(void (* f)(const PKT &)=0){cb.PK_cb=f;}
private: // Dumping and pretty printing
// INVOKES the callback functions on the graph elements
// Another BORLAND compiler bug: originally I had Setxx_CB and Doxx_CB both
// called xx_CB; the signatures differed only in the argument list. BUT this
// caused the arguments to pick up the 'const' modifier from - well, I know not
// where. Changing the names made the modifier go away.
void DoAD_CB( AT & x) {
if(cb.AD_cb!=0)cb.AD_cb(x);
else fprintf(dfp,"No arc data c/b");
}
void DoAK_CB(const AKT & x) {
if(cb.AK_cb!=0)cb.AK_cb(x);
else fprintf(dfp,"No arc key c/b");
}
void DoND_CB( NT & x) {
if(cb.ND_cb!=0)cb.ND_cb(x);
else fprintf(dfp,"No node data c/b");
}
void DoNK_CB(const NKT & x) {
if(cb.NK_cb!=0)cb.NK_cb(x);
else fprintf(dfp,"No node key c/b");
}
void DoPD_CB( PT & x) {
if(cb.PD_cb!=0)cb.PD_cb(x);
else fprintf(dfp,"No pin data c/b");
}
void DoPK_CB(const PKT & x) {
if(cb.PK_cb!=0)cb.PK_cb(x);
else fprintf(dfp,"No pin key c/b");
}
struct cb_struct { // Callbacks
void (* AD_cb)(const AT &); // Arc data
void (* AK_cb)(const AKT &); // Arc key
void (* ND_cb)(const NT &); // Node data
void (* NK_cb)(const NKT &); // Node key
void (* PD_cb)(const PT &); // Pin data
void (* PK_cb)(const PKT &); // Pin key
} cb;
// Random access to nodes. I initially tried to subclass this, but you'd think
// I'd have learned by now. Eventually I gave up.
vector<TPn_it> RandN; // Random access iterator vector
bool N_dirty; // Node map changed?
Urand RNG; // Rectangular RNG
void RConfig(); // Set up the random access structure
};
//==============================================================================
#include "pdigraph.tpp"
#undef PDIGRAPH_
#undef _PDIGRAPH
#undef _1
#undef _2
#endif