forked from snap-stanford/snap-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnapswig.h
255 lines (241 loc) · 11.9 KB
/
snapswig.h
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
class TNGraphNodeI {
private:
TNGraph::TNodeI NI;
public:
TNGraphNodeI() : NI() { }
TNGraphNodeI(const TNGraph::TNodeI& NodeI) : NI(NodeI) { }
TNGraphNodeI& operator = (const TNGraph::TNodeI& NodeI) { NI = NodeI; return *this; }
/// Increment iterator.
TNGraphNodeI& operator++ (int) { NI++; return *this; }
TNGraphNodeI& Next() { NI++; return *this; }
bool operator < (const TNGraphNodeI& NodeI) const { return NI < NodeI.NI; }
bool operator == (const TNGraphNodeI& NodeI) const { return NI == NodeI.NI; }
/// Returns C++ node iterator.
TNGraph::TNodeI GetNI() const { return NI; }
/// Returns ID of the current node.
int GetId() const { return NI.GetId(); }
/// Returns degree of the current node, the sum of in-degree and out-degree.
int GetDeg() const { return NI.GetDeg(); }
/// Returns in-degree of the current node.
int GetInDeg() const { return NI.GetInDeg(); }
/// Returns out-degree of the current node.
int GetOutDeg() const { return NI.GetOutDeg(); }
/// Returns ID of NodeN-th in-node (the node pointing to the current node). ##TNGraph::TNodeI::GetInNId
int GetInNId(const int& NodeN) const { return NI.GetInNId(NodeN); }
/// Returns ID of NodeN-th out-node (the node the current node points to). ##TNGraph::TNodeI::GetOutNId
int GetOutNId(const int& NodeN) const { return NI.GetOutNId(NodeN); }
/// Returns ID of NodeN-th neighboring node. ##TNGraph::TNodeI::GetNbrNId
int GetNbrNId(const int& NodeN) const { return NI.GetNbrNId(NodeN); }
/// Tests whether node with ID NId points to the current node.
bool IsInNId(const int& NId) const { return NI.IsInNId(NId); }
/// Tests whether the current node points to node with ID NId.
bool IsOutNId(const int& NId) const { return NI.IsOutNId(NId); }
/// Tests whether node with ID NId is a neighbor of the current node.
bool IsNbrNId(const int& NId) const { return NI.IsOutNId(NId) || NI.IsInNId(NId); }
};
/// Edge iterator. Only forward iteration (operator++) is supported.
class TNGraphEdgeI {
private:
TNGraph::TEdgeI EI;
public:
TNGraphEdgeI() : EI() { }
TNGraphEdgeI(const TNGraph::TEdgeI& EdgeI) : EI(EdgeI) { }
TNGraphEdgeI& operator = (const TNGraph::TEdgeI& EdgeI) { EI = EdgeI; return *this; }
/// Increment iterator.
TNGraphEdgeI& operator++ (int) { EI++; return *this; }
TNGraphEdgeI& Next() { EI++; return *this; }
bool operator < (const TNGraphEdgeI& EdgeI) const { return EI < EdgeI.EI; }
bool operator == (const TNGraphEdgeI& EdgeI) const { return EI == EdgeI.EI; }
/// Returns C++ edge iterator.
TNGraph::TEdgeI GetEI() const { return EI; }
/// Always returns -1, since edges do not have explicit IDs.
int GetId() const { return EI.GetId(); }
/// Returns the ID of the source node of the edge.
int GetSrcNId() const { return EI.GetSrcNId(); }
/// Returns the ID of the destination node of the edge.
int GetDstNId() const { return EI.GetDstNId(); }
};
class TUNGraphNodeI {
private:
TUNGraph::TNodeI NI;
public:
TUNGraphNodeI() : NI() { }
TUNGraphNodeI(const TUNGraph::TNodeI& NodeI) : NI(NodeI) { }
TUNGraphNodeI& operator = (const TUNGraph::TNodeI& NodeI) { NI = NodeI; return *this; }
/// Increment iterator.
TUNGraphNodeI& operator++ (int) { NI++; return *this; }
TUNGraphNodeI& Next() { NI++; return *this; }
bool operator < (const TUNGraphNodeI& NodeI) const { return NI < NodeI.NI; }
bool operator == (const TUNGraphNodeI& NodeI) const { return NI == NodeI.NI; }
/// Returns C++ node iterator.
TUNGraph::TNodeI GetNI() const { return NI; }
/// Returns ID of the current node.
int GetId() const { return NI.GetId(); }
/// Returns degree of the current node, the sum of in-degree and out-degree.
int GetDeg() const { return NI.GetDeg(); }
/// Returns in-degree of the current node.
int GetInDeg() const { return NI.GetInDeg(); }
/// Returns out-degree of the current node.
int GetOutDeg() const { return NI.GetOutDeg(); }
/// Returns ID of NodeN-th in-node (the node pointing to the current node). ##TUNGraph::TNodeI::GetInNId
int GetInNId(const int& NodeN) const { return NI.GetInNId(NodeN); }
/// Returns ID of NodeN-th out-node (the node the current node points to). ##TUNGraph::TNodeI::GetOutNId
int GetOutNId(const int& NodeN) const { return NI.GetOutNId(NodeN); }
/// Returns ID of NodeN-th neighboring node. ##TUNGraph::TNodeI::GetNbrNId
int GetNbrNId(const int& NodeN) const { return NI.GetNbrNId(NodeN); }
/// Tests whether node with ID NId points to the current node.
bool IsInNId(const int& NId) const { return NI.IsInNId(NId); }
/// Tests whether the current node points to node with ID NId.
bool IsOutNId(const int& NId) const { return NI.IsOutNId(NId); }
/// Tests whether node with ID NId is a neighbor of the current node.
bool IsNbrNId(const int& NId) const { return NI.IsOutNId(NId) || NI.IsInNId(NId); }
};
/// Edge iterator. Only forward iteration (operator++) is supported.
class TUNGraphEdgeI {
private:
TUNGraph::TEdgeI EI;
public:
TUNGraphEdgeI() : EI() { }
TUNGraphEdgeI(const TUNGraph::TEdgeI& EdgeI) : EI(EdgeI) { }
TUNGraphEdgeI& operator = (const TUNGraph::TEdgeI& EdgeI) { EI = EdgeI; return *this; }
/// Increment iterator.
TUNGraphEdgeI& operator++ (int) { EI++; return *this; }
TUNGraphEdgeI& Next() { EI++; return *this; }
bool operator < (const TUNGraphEdgeI& EdgeI) const { return EI < EdgeI.EI; }
bool operator == (const TUNGraphEdgeI& EdgeI) const { return EI == EdgeI.EI; }
/// Returns C++ edge iterator.
TUNGraph::TEdgeI GetEI() const { return EI; }
/// Always returns -1, since edges do not have explicit IDs.
int GetId() const { return EI.GetId(); }
/// Returns the ID of the source node of the edge. Since the graph is undirected this is the node with smaller ID of the edge endpoints.
int GetSrcNId() const { return EI.GetSrcNId(); }
/// Returns the ID of the destination node of the edge. Since the graph is undirected this is the node with greater ID of the edge endpoints.
int GetDstNId() const { return EI.GetDstNId(); }
};
class TNEANetNodeI {
private:
TNEANet::TNodeI NI;
public:
TNEANetNodeI() : NI() { }
TNEANetNodeI(const TNEANet::TNodeI& NodeI) : NI(NodeI) { }
TNEANetNodeI& operator = (const TNEANet::TNodeI& NodeI) { NI = NodeI; return *this; }
/// Increment iterator.
TNEANetNodeI& operator++ (int) { NI++; return *this; }
TNEANetNodeI& Next() { NI++; return *this; }
bool operator < (const TNEANetNodeI& NodeI) const { return NI < NodeI.NI; }
bool operator == (const TNEANetNodeI& NodeI) const { return NI == NodeI.NI; }
/// Returns C++ node iterator.
TNEANet::TNodeI GetNI() const { return NI; }
/// Returns ID of the current node.
int GetId() const { return NI.GetId(); }
/// Returns degree of the current node, the sum of in-degree and out-degree.
int GetDeg() const { return NI.GetDeg(); }
/// Returns in-degree of the current node.
int GetInDeg() const { return NI.GetInDeg(); }
/// Returns out-degree of the current node.
int GetOutDeg() const { return NI.GetOutDeg(); }
/// Returns ID of NodeN-th in-node (the node pointing to the current node). ##TNEANet::TNodeI::GetInNId
int GetInNId(const int& NodeN) const { return NI.GetInNId(NodeN); }
/// Returns ID of NodeN-th out-node (the node the current node points to). ##TNEANet::TNodeI::GetOutNId
int GetOutNId(const int& NodeN) const { return NI.GetOutNId(NodeN); }
/// Returns ID of NodeN-th neighboring node. ##TNEANet::TNodeI::GetNbrNId
int GetNbrNId(const int& NodeN) const { return NI.GetNbrNId(NodeN); }
/// Tests whether node with ID NId points to the current node.
bool IsInNId(const int& NId) const { return NI.IsInNId(NId); }
/// Tests whether the current node points to node with ID NId.
bool IsOutNId(const int& NId) const { return NI.IsOutNId(NId); }
/// Tests whether node with ID NId is a neighbor of the current node.
bool IsNbrNId(const int& NId) const { return NI.IsOutNId(NId) || NI.IsInNId(NId); }
};
/// Edge iterator. Only forward iteration (operator++) is supported.
class TNEANetEdgeI {
private:
TNEANet::TEdgeI EI;
public:
TNEANetEdgeI() : EI() { }
TNEANetEdgeI(const TNEANet::TEdgeI& EdgeI) : EI(EdgeI) { }
TNEANetEdgeI& operator = (const TNEANet::TEdgeI& EdgeI)
{ EI = EdgeI; return *this; }
/// Increment iterator.
TNEANetEdgeI& operator++ (int) { EI++; return *this; }
TNEANetEdgeI& Next() { EI++; return *this; }
bool operator < (const TNEANetEdgeI& EdgeI) const { return EI < EdgeI.EI; }
bool operator == (const TNEANetEdgeI& EdgeI) const { return EI == EdgeI.EI; }
/// Returns C++ edge iterator.
TNEANet::TEdgeI GetEI() const { return EI; }
/// Returns edge ID. Only multigraphs have explicit edge IDs.
int GetId() const { return EI.GetId(); }
/// Returns the ID of the source node of the edge.
int GetSrcNId() const { return EI.GetSrcNId(); }
/// Returns the ID of the destination node of the edge.
int GetDstNId() const { return EI.GetDstNId(); }
};
typedef TIntV::TIter TIntVecIter;
/// Node/edge integer attribute iterator. Iterates through all nodes/edges for one integer attribute.
class TNEANetAIntI {
private:
TNEANet::TAIntI IntAI;
public:
TNEANetAIntI() : IntAI() { }
TNEANetAIntI(const TIntVecIter& HIter, TStr attribute, bool isEdgeIter,
const TNEANet* GraphPt) :
IntAI(HIter, attribute, isEdgeIter, GraphPt) { }
TNEANetAIntI(const TNEANet::TAIntI& I) : IntAI(I) { }
TNEANetAIntI& operator = (const TNEANetAIntI& I)
{ IntAI = I.IntAI; return *this; }
TNEANetAIntI& Next() { IntAI++; return *this; }
bool operator < (const TNEANetAIntI& I) const { return IntAI < I.IntAI; }
bool operator == (const TNEANetAIntI& I) const { return IntAI == I.IntAI; }
/// Returns an attribute of the node.
int GetDat() const { return IntAI.GetDat().Val; }
/// Returns true if node or edge has been deleted.
bool IsDeleted() const { return IntAI.IsDeleted(); };
TNEANetAIntI& operator++(int) { IntAI++; return *this; }
// friend class TNEANet;
};
typedef TStrV::TIter TStrVecIter;
/// Node/edge string attribute iterator. Iterates through all nodes/edges for one string attribute.
class TNEANetAStrI {
private:
TNEANet::TAStrI StrAI;
public:
TNEANetAStrI() : StrAI() { }
TNEANetAStrI(const TStrVecIter& HIter, TStr attribute, bool isEdgeIter,
const TNEANet* GraphPt) :
StrAI(HIter, attribute, isEdgeIter, GraphPt) { }
TNEANetAStrI(const TNEANet::TAStrI& I) : StrAI(I) { }
TNEANetAStrI& operator = (const TNEANetAStrI& I)
{ StrAI = I.StrAI; return *this; }
TNEANetAStrI& Next() { StrAI++; return *this; }
bool operator < (const TNEANetAStrI& I) const { return StrAI < I.StrAI; }
bool operator == (const TNEANetAStrI& I) const { return StrAI == I.StrAI; }
/// Returns an attribute of the node.
char * GetDat() const { return StrAI.GetDat().CStr(); }
/// Returns true if node or edge has been deleted.
bool IsDeleted() const { return StrAI.IsDeleted(); };
TNEANetAStrI& operator++(int) { StrAI++; return *this; }
// friend class TNEANet;
};
typedef TFltV::TIter TFltVecIter;
/// Node/edge float attribute iterator. Iterates through all nodes/edges for one float attribute.
class TNEANetAFltI {
private:
TNEANet::TAFltI FltAI;
public:
TNEANetAFltI() : FltAI() { }
TNEANetAFltI(const TFltVecIter& HIter, TStr attribute, bool isEdgeIter,
const TNEANet* GraphPt) :
FltAI(HIter, attribute, isEdgeIter, GraphPt) { }
TNEANetAFltI(const TNEANet::TAFltI& I) : FltAI(I) { }
TNEANetAFltI& operator = (const TNEANetAFltI& I)
{ FltAI = I.FltAI; return *this; }
TNEANetAFltI& Next() { FltAI++; return *this; }
bool operator < (const TNEANetAFltI& I) const { return FltAI < I.FltAI; }
bool operator == (const TNEANetAFltI& I) const { return FltAI == I.FltAI; }
/// Returns an attribute of the node.
double GetDat() const { return FltAI.GetDat().Val; }
/// Returns true if node or edge has been deleted.
bool IsDeleted() const { return FltAI.IsDeleted(); };
TNEANetAFltI& operator++(int) { FltAI++; return *this; }
// friend class TNEANet;
};