SNAP Library 3.0, User Reference  2016-07-20 17:56:49
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
network.h
Go to the documentation of this file.
1 #ifndef NETWORK_H
2 #define NETWORK_H
3 
5 // Node Data
6 // TNodeData has to implement the following methods:
7 // class TNodeData {
8 // public:
9 // TNodeData() { }
10 // TNodeData(TSIn& SIn) { }
11 // void Save(TSOut& SOut) const { }
12 // };
13 
14 //#//////////////////////////////////////////////
16 template <class TNodeData>
17 class TNodeNet {
18 public:
19  typedef TNodeData TNodeDat;
21  typedef TPt<TNet> PNet;
22 public:
23  class TNode {
24  private:
26  TNodeData NodeDat;
28  public:
29  TNode() : Id(-1), NodeDat(), InNIdV(), OutNIdV() { }
30  TNode(const int& NId) : Id(NId), NodeDat(), InNIdV(), OutNIdV() { }
31  TNode(const int& NId, const TNodeData& NodeData) : Id(NId), NodeDat(NodeData), InNIdV(), OutNIdV() { }
32  TNode(const TNode& Node) : Id(Node.Id), NodeDat(Node.NodeDat), InNIdV(Node.InNIdV), OutNIdV(Node.OutNIdV) { }
33  TNode(TSIn& SIn) : Id(SIn), NodeDat(SIn), InNIdV(SIn), OutNIdV(SIn) { }
34  void Save(TSOut& SOut) const { Id.Save(SOut); NodeDat.Save(SOut); InNIdV.Save(SOut); OutNIdV.Save(SOut); }
35  int GetId() const { return Id; }
36  int GetDeg() const { return GetInDeg() + GetOutDeg(); }
37  int GetInDeg() const { return InNIdV.Len(); }
38  int GetOutDeg() const { return OutNIdV.Len(); }
39  const TNodeData& GetDat() const { return NodeDat; }
40  TNodeData& GetDat() { return NodeDat; }
41  int GetInNId(const int& NodeN) const { return InNIdV[NodeN]; }
42  int GetOutNId(const int& NodeN) const { return OutNIdV[NodeN]; }
43  int GetNbrNId(const int& NodeN) const { return NodeN<GetOutDeg() ? GetOutNId(NodeN):GetInNId(NodeN-GetOutDeg()); }
44  bool IsInNId(const int& NId) const { return InNIdV.SearchBin(NId) != -1; }
45  bool IsOutNId(const int& NId) const { return OutNIdV.SearchBin(NId) != -1; }
46  bool IsNbrNId(const int& NId) const { return IsOutNId(NId) || IsInNId(NId); }
47  bool operator < (const TNode& Node) const { return NodeDat < Node.NodeDat; }
48  friend class TNodeNet<TNodeData>;
49  };
50 
52  class TNodeI {
53  private:
57  public:
58  TNodeI() : NodeHI(), Net(NULL) { }
59  TNodeI(const THashIter& NodeHIter, const TNodeNet* NetPt) : NodeHI(NodeHIter), Net((TNodeNet *) NetPt) { }
60  TNodeI(const TNodeI& NodeI) : NodeHI(NodeI.NodeHI), Net(NodeI.Net) { }
61  TNodeI& operator = (const TNodeI& NodeI) { NodeHI=NodeI.NodeHI; Net=NodeI.Net; return *this; }
63  TNodeI& operator++ (int) { NodeHI++; return *this; }
64  bool operator < (const TNodeI& NodeI) const { return NodeHI < NodeI.NodeHI; }
65  bool operator == (const TNodeI& NodeI) const { return NodeHI == NodeI.NodeHI; }
66 
68  int GetId() const { return NodeHI.GetDat().GetId(); }
70  int GetDeg() const { return NodeHI.GetDat().GetDeg(); }
72  int GetInDeg() const { return NodeHI.GetDat().GetInDeg(); }
74  int GetOutDeg() const { return NodeHI.GetDat().GetOutDeg(); }
76 
78  int GetInNId(const int& NodeN) const { return NodeHI.GetDat().GetInNId(NodeN); }
80 
82  int GetOutNId(const int& NodeN) const { return NodeHI.GetDat().GetOutNId(NodeN); }
84 
86  int GetNbrNId(const int& NodeN) const { return NodeHI.GetDat().GetNbrNId(NodeN); }
88  bool IsInNId(const int& NId) const { return NodeHI.GetDat().IsInNId(NId); }
90  bool IsOutNId(const int& NId) const { return NodeHI.GetDat().IsOutNId(NId); }
92  bool IsNbrNId(const int& NId) const { return IsOutNId(NId) || IsInNId(NId); }
93  const TNodeData& operator () () const { return NodeHI.GetDat().NodeDat; }
94  TNodeData& operator () () { return NodeHI.GetDat().GetDat(); }
95  const TNodeData& GetDat() const { return NodeHI.GetDat().GetDat(); }
96  TNodeData& GetDat() { return NodeHI.GetDat().GetDat(); }
97  const TNodeData& GetInNDat(const int& NodeN) const { return Net->GetNDat(GetInNId(NodeN)); }
98  TNodeData& GetInNDat(const int& NodeN) { return Net->GetNDat(GetInNId(NodeN)); }
99  const TNodeData& GetOutNDat(const int& NodeN) const { return Net->GetNDat(GetOutNId(NodeN)); }
100  TNodeData& GetOutNDat(const int& NodeN) { return Net->GetNDat(GetOutNId(NodeN)); }
101  const TNodeData& GetNbrNDat(const int& NodeN) const { return Net->GetNDat(GetNbrNId(NodeN)); }
102  TNodeData& GetNbrNDat(const int& NodeN) { return Net->GetNDat(GetNbrNId(NodeN)); }
103  friend class TNodeNet<TNodeData>;
104  };
105 
107  class TEdgeI {
108  private:
110  int CurEdge;
111  public:
112  TEdgeI() : CurNode(), EndNode(), CurEdge(0) { }
113  TEdgeI(const TNodeI& NodeI, const TNodeI& EndNodeI, const int& EdgeN=0) : CurNode(NodeI), EndNode(EndNodeI), CurEdge(EdgeN) { }
114  TEdgeI(const TEdgeI& EdgeI) : CurNode(EdgeI.CurNode), EndNode(EdgeI.EndNode), CurEdge(EdgeI.CurEdge) { }
115  TEdgeI& operator = (const TEdgeI& EdgeI) { if (this!=&EdgeI) { CurNode=EdgeI.CurNode; EndNode=EdgeI.EndNode; CurEdge=EdgeI.CurEdge; } return *this; }
118  while (CurNode < EndNode && CurNode.GetOutDeg()==0) { CurNode++; } } return *this; }
119  bool operator < (const TEdgeI& EdgeI) const { return CurNode<EdgeI.CurNode || (CurNode==EdgeI.CurNode && CurEdge<EdgeI.CurEdge); }
120  bool operator == (const TEdgeI& EdgeI) const { return CurNode == EdgeI.CurNode && CurEdge == EdgeI.CurEdge; }
122  int GetId() const { return -1; }
124  int GetSrcNId() const { return CurNode.GetId(); }
126  int GetDstNId() const { return CurNode.GetOutNId(CurEdge); }
127  const TNodeData& GetSrcNDat() const { return CurNode.GetDat(); }
128  TNodeData& GetDstNDat() { return CurNode.GetOutNDat(CurEdge); }
129  friend class TNodeNet<TNodeData>;
130  };
131 
132 protected:
133  TNode& GetNode(const int& NId) { return NodeH.GetDat(NId); }
134 
135 protected:
139 
140 public:
141  TNodeNet() : CRef(), MxNId(0), NodeH() { }
143  explicit TNodeNet(const int& Nodes, const int& Edges) : MxNId(0) { Reserve(Nodes, Edges); }
144  TNodeNet(const TNodeNet& NodeNet) : MxNId(NodeNet.MxNId), NodeH(NodeNet.NodeH) { }
146  TNodeNet(TSIn& SIn) : MxNId(SIn), NodeH(SIn) { }
147  virtual ~TNodeNet() { }
149  virtual void Save(TSOut& SOut) const { MxNId.Save(SOut); NodeH.Save(SOut); }
151  static PNet New() { return PNet(new TNodeNet()); }
153  static PNet Load(TSIn& SIn) { return PNet(new TNodeNet(SIn)); }
155  bool HasFlag(const TGraphFlag& Flag) const;
156  TNodeNet& operator = (const TNodeNet& NodeNet) {
157  if (this!=&NodeNet) { NodeH=NodeNet.NodeH; MxNId=NodeNet.MxNId; } return *this; }
158  // nodes
160  int GetNodes() const { return NodeH.Len(); }
162 
166  int AddNode(int NId = -1);
168 
172  int AddNode(int NId, const TNodeData& NodeDat);
174  int AddNode(const TNodeI& NodeI) { return AddNode(NodeI.GetId(), NodeI.GetDat()); }
176 
178  virtual void DelNode(const int& NId);
180  void DelNode(const TNode& NodeI) { DelNode(NodeI.GetId()); }
182  bool IsNode(const int& NId) const { return NodeH.IsKey(NId); }
184  TNodeI BegNI() const { return TNodeI(NodeH.BegI(), this); }
186  TNodeI EndNI() const { return TNodeI(NodeH.EndI(), this); }
188  TNodeI GetNI(const int& NId) const { return TNodeI(NodeH.GetI(NId), this); }
190  const TNode& GetNode(const int& NId) const { return NodeH.GetDat(NId); }
192  void SetNDat(const int& NId, const TNodeData& NodeDat);
194  TNodeData& GetNDat(const int& NId) { return NodeH.GetDat(NId).NodeDat; }
196  const TNodeData& GetNDat(const int& NId) const { return NodeH.GetDat(NId).NodeDat; }
198  int GetMxNId() const { return MxNId; }
199 
200  // edges
202  int GetEdges() const;
204 
210  int AddEdge(const int& SrcNId, const int& DstNId);
212  int AddEdge(const TEdgeI& EdgeI) { return AddEdge(EdgeI.GetSrcNId(), EdgeI.GetDstNId()); }
214 
218  void DelEdge(const int& SrcNId, const int& DstNId, const bool& IsDir = true);
220  bool IsEdge(const int& SrcNId, const int& DstNId, const bool& IsDir = true) const;
222  TEdgeI BegEI() const { TNodeI NI=BegNI(); while(NI<EndNI() && NI.GetOutDeg()==0) NI++; return TEdgeI(NI, EndNI()); }
224  TEdgeI EndEI() const { return TEdgeI(EndNI(), EndNI()); }
226  TEdgeI GetEI(const int& EId) const;
228  TEdgeI GetEI(const int& SrcNId, const int& DstNId) const;
229 
231  int GetRndNId(TRnd& Rnd=TInt::Rnd) { return NodeH.GetKey(NodeH.GetRndKeyId(Rnd, 0.8)); }
233  TNodeI GetRndNI(TRnd& Rnd=TInt::Rnd) { return GetNI(GetRndNId(Rnd)); }
235  void GetNIdV(TIntV& NIdV) const;
236 
238  bool Empty() const { return GetNodes()==0; }
240  void Clr(const bool& DoDel=true, const bool& ResetDat=true) {
241  MxNId = 0; NodeH.Clr(DoDel, -1, ResetDat); }
243  void Reserve(const int& Nodes, const int& Edges) { if (Nodes>0) { NodeH.Gen(Nodes/2); } }
245  void SortNIdById(const bool& Asc=true) { NodeH.SortByKey(Asc); }
247  void SortNIdByDat(const bool& Asc=true) { NodeH.SortByDat(Asc); }
249 
254  void Defrag(const bool& OnlyNodeLinks=false);
256 
259  bool IsOk(const bool& ThrowExcept=true) const;
260 
261  friend class TPt<TNodeNet<TNodeData> >;
262 };
263 
264 // set flags
265 namespace TSnap {
266 template <class TNodeData> struct IsDirected<TNodeNet<TNodeData> > { enum { Val = 1 }; };
267 template <class TNodeData> struct IsNodeDat<TNodeNet<TNodeData> > { enum { Val = 1 }; };
268 }
269 
270 template <class TNodeData>
271 bool TNodeNet<TNodeData>::HasFlag(const TGraphFlag& Flag) const {
272  return HasGraphFlag(typename TNet, Flag);
273 }
274 
275 template <class TNodeData>
277  if (NId == -1) {
278  NId = MxNId; MxNId++;
279  } else {
280  IAssertR(!IsNode(NId), TStr::Fmt("NodeId %d already exists", NId));
281  MxNId = TMath::Mx(NId+1, MxNId());
282  }
283  NodeH.AddDat(NId, TNode(NId));
284  return NId;
285 }
286 
287 template <class TNodeData>
288 int TNodeNet<TNodeData>::AddNode(int NId, const TNodeData& NodeDat) {
289  if (NId == -1) {
290  NId = MxNId; MxNId++;
291  } else {
292  IAssertR(!IsNode(NId), TStr::Fmt("NodeId %d already exists", NId));
293  MxNId = TMath::Mx(NId+1, MxNId());
294  }
295  NodeH.AddDat(NId, TNode(NId, NodeDat));
296  return NId;
297 }
298 
299 template <class TNodeData>
300 void TNodeNet<TNodeData>::DelNode(const int& NId) {
301  { TNode& Node = GetNode(NId);
302  for (int e = 0; e < Node.GetOutDeg(); e++) {
303  const int nbr = Node.GetOutNId(e);
304  if (nbr == NId) { continue; }
305  TNode& N = GetNode(nbr);
306  int n = N.InNIdV.SearchBin(NId);
307  if (n!= -1) { N.InNIdV.Del(n); }
308  }
309  for (int e = 0; e < Node.GetInDeg(); e++) {
310  const int nbr = Node.GetInNId(e);
311  if (nbr == NId) { continue; }
312  TNode& N = GetNode(nbr);
313  int n = N.OutNIdV.SearchBin(NId);
314  if (n!= -1) { N.OutNIdV.Del(n); }
315  } }
316  NodeH.DelKey(NId);
317 }
318 
319 template <class TNodeData>
320 void TNodeNet<TNodeData>::SetNDat(const int& NId, const TNodeData& NodeDat) {
321  IAssertR(IsNode(NId), TStr::Fmt("NodeId %d does not exist.", NId).CStr());
322  NodeH.GetDat(NId).NodeDat = NodeDat;
323 }
324 
325 template <class TNodeData>
327  int edges=0;
328  for (int N=NodeH.FFirstKeyId(); NodeH.FNextKeyId(N);) {
329  edges+=NodeH[N].GetOutDeg(); }
330  return edges;
331 }
332 
333 template <class TNodeData>
334 int TNodeNet<TNodeData>::AddEdge(const int& SrcNId, const int& DstNId) {
335  IAssertR(IsNode(SrcNId) && IsNode(DstNId), TStr::Fmt("%d or %d not a node.", SrcNId, DstNId).CStr());
336  if (IsEdge(SrcNId, DstNId)) { return -2; }
337  GetNode(SrcNId).OutNIdV.AddSorted(DstNId);
338  GetNode(DstNId).InNIdV.AddSorted(SrcNId);
339  return -1; // edge id
340 }
341 
342 template <class TNodeData>
343 void TNodeNet<TNodeData>::DelEdge(const int& SrcNId, const int& DstNId, const bool& IsDir) {
344  IAssertR(IsNode(SrcNId) && IsNode(DstNId), TStr::Fmt("%d or %d not a node.", SrcNId, DstNId).CStr());
345  GetNode(SrcNId).OutNIdV.DelIfIn(DstNId);
346  GetNode(DstNId).InNIdV.DelIfIn(SrcNId);
347  if (! IsDir) {
348  GetNode(DstNId).OutNIdV.DelIfIn(SrcNId);
349  GetNode(SrcNId).InNIdV.DelIfIn(DstNId);
350  }
351 }
352 
353 template <class TNodeData>
354 bool TNodeNet<TNodeData>::IsEdge(const int& SrcNId, const int& DstNId, const bool& IsDir) const {
355  if (! IsNode(SrcNId) || ! IsNode(DstNId)) { return false; }
356  if (IsDir) { return GetNode(SrcNId).IsOutNId(DstNId); }
357  else { return GetNode(SrcNId).IsOutNId(DstNId) || GetNode(DstNId).IsOutNId(SrcNId); }
358 }
359 
360 template <class TNodeData>
362  NIdV.Reserve(GetNodes(), 0);
363  for (int N=NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
364  NIdV.Add(NodeH.GetKey(N)); }
365 }
366 
367 template <class TNodeData>
368 typename TNodeNet<TNodeData>::TEdgeI TNodeNet<TNodeData>::GetEI(const int& SrcNId, const int& DstNId) const {
369  const TNodeI SrcNI = GetNI(SrcNId);
370  const int NodeN = SrcNI.NodeHI.GetDat().OutNIdV.SearchBin(DstNId);
371  if (NodeN == -1) { return EndEI(); }
372  return TEdgeI(SrcNI, EndNI(), NodeN);
373 }
374 
375 template <class TNodeData>
376 void TNodeNet<TNodeData>::Defrag(const bool& OnlyNodeLinks) {
377  for (int n = NodeH.FFirstKeyId(); NodeH.FNextKeyId(n); ) {
378  TNode& Node = NodeH[n];
379  Node.InNIdV.Pack(); Node.OutNIdV.Pack();
380  }
381  if (! OnlyNodeLinks && ! NodeH.IsKeyIdEqKeyN()) {
382  NodeH.Defrag(); }
383 }
384 
385 template <class TNodeData>
386 bool TNodeNet<TNodeData>::IsOk(const bool& ThrowExcept) const {
387  bool RetVal = true;
388  for (int N = NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
389  const TNode& Node = NodeH[N];
390  if (! Node.OutNIdV.IsSorted()) {
391  const TStr Msg = TStr::Fmt("Out-neighbor list of node %d is not sorted.", Node.GetId());
392  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
393  }
394  if (! Node.InNIdV.IsSorted()) {
395  const TStr Msg = TStr::Fmt("In-neighbor list of node %d is not sorted.", Node.GetId());
396  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
397  }
398  // check out-edges
399  int prevNId = -1;
400  for (int e = 0; e < Node.GetOutDeg(); e++) {
401  if (! IsNode(Node.GetOutNId(e))) {
402  const TStr Msg = TStr::Fmt("Out-edge %d --> %d: node %d does not exist.",
403  Node.GetId(), Node.GetOutNId(e), Node.GetOutNId(e));
404  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
405  }
406  if (e > 0 && prevNId == Node.GetOutNId(e)) {
407  const TStr Msg = TStr::Fmt("Node %d has duplidate out-edge %d --> %d.",
408  Node.GetId(), Node.GetId(), Node.GetOutNId(e));
409  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
410  }
411  prevNId = Node.GetOutNId(e);
412  }
413  // check in-edges
414  prevNId = -1;
415  for (int e = 0; e < Node.GetInDeg(); e++) {
416  if (! IsNode(Node.GetInNId(e))) {
417  const TStr Msg = TStr::Fmt("In-edge %d <-- %d: node %d does not exist.",
418  Node.GetId(), Node.GetInNId(e), Node.GetInNId(e));
419  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
420  }
421  if (e > 0 && prevNId == Node.GetInNId(e)) {
422  const TStr Msg = TStr::Fmt("Node %d has duplidate in-edge %d <-- %d.",
423  Node.GetId(), Node.GetId(), Node.GetInNId(e));
424  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
425  }
426  prevNId = Node.GetInNId(e);
427  }
428  }
429  return RetVal;
430 }
431 
433 // Common network types
440 
441 //#//////////////////////////////////////////////
443 template <class TNodeData, class TEdgeData>
445 public:
446  typedef TNodeData TNodeDat;
447  typedef TEdgeData TEdgeDat;
449  typedef TPt<TNet> PNet;
451 public:
452  class TNode {
453  private:
455  TNodeData NodeDat;
458  public:
459  TNode() : Id(-1), NodeDat(), InNIdV(), OutNIdV() { }
460  TNode(const int& NId) : Id(NId), NodeDat(), InNIdV(), OutNIdV() { }
461  TNode(const int& NId, const TNodeData& NodeData) : Id(NId), NodeDat(NodeData), InNIdV(), OutNIdV() { }
462  TNode(const TNode& Node) : Id(Node.Id), NodeDat(Node.NodeDat), InNIdV(Node.InNIdV), OutNIdV(Node.OutNIdV) { }
463  TNode(TSIn& SIn) : Id(SIn), NodeDat(SIn), InNIdV(SIn), OutNIdV(SIn) { }
464  void Save(TSOut& SOut) const { Id.Save(SOut); NodeDat.Save(SOut); InNIdV.Save(SOut); OutNIdV.Save(SOut); }
465  int GetId() const { return Id; }
466  int GetDeg() const { return GetInDeg() + GetOutDeg(); }
467  int GetInDeg() const { return InNIdV.Len(); }
468  int GetOutDeg() const { return OutNIdV.Len(); }
469  const TNodeData& GetDat() const { return NodeDat; }
470  TNodeData& GetDat() { return NodeDat; }
471  int GetInNId(const int& EdgeN) const { return InNIdV[EdgeN]; }
472  int GetOutNId(const int& EdgeN) const { return OutNIdV[EdgeN].Val1; }
473  int GetNbrNId(const int& EdgeN) const { return EdgeN<GetOutDeg() ? GetOutNId(EdgeN):GetInNId(EdgeN-GetOutDeg()); }
474  TEdgeData& GetOutEDat(const int& EdgeN) { return OutNIdV[EdgeN].Val2; }
475  const TEdgeData& GetOutEDat(const int& EdgeN) const { return OutNIdV[EdgeN].Val2; }
476  bool IsInNId(const int& NId) const { return InNIdV.SearchBin(NId)!=-1; }
477  bool IsOutNId(const int& NId) const { return TNodeEDatNet::GetNIdPos(OutNIdV, NId)!=-1; }
478  bool IsNbrNId(const int& NId) const { return IsOutNId(NId) || IsInNId(NId); }
479  bool operator < (const TNode& Node) const { return NodeDat < Node.NodeDat; }
480  friend class TNodeEDatNet<TNodeData, TEdgeData>;
481  };
482 
484  class TNodeI {
485  private:
489  public:
490  TNodeI() : NodeHI(), Net(NULL) { }
491  TNodeI(const THashIter& NodeHIter, const TNodeEDatNet* NetPt) : NodeHI(NodeHIter), Net((TNodeEDatNet *) NetPt) { }
492  TNodeI(const TNodeI& NodeI) : NodeHI(NodeI.NodeHI), Net(NodeI.Net) { }
493  TNodeI& operator = (const TNodeI& NodeI) { NodeHI=NodeI.NodeHI; Net=NodeI.Net; return *this; }
495  TNodeI& operator++ (int) { NodeHI++; return *this; }
496  bool operator < (const TNodeI& NodeI) const { return NodeHI < NodeI.NodeHI; }
497  bool operator == (const TNodeI& NodeI) const { return NodeHI == NodeI.NodeHI; }
498 
500  int GetId() const { return NodeHI.GetDat().GetId(); }
502  int GetDeg() const { return NodeHI.GetDat().GetDeg(); }
504  int GetInDeg() const { return NodeHI.GetDat().GetInDeg(); }
506  int GetOutDeg() const { return NodeHI.GetDat().GetOutDeg(); }
508 
510  int GetInNId(const int& NodeN) const { return NodeHI.GetDat().GetInNId(NodeN); }
512 
514  int GetOutNId(const int& NodeN) const { return NodeHI.GetDat().GetOutNId(NodeN); }
516 
518  int GetNbrNId(const int& NodeN) const { return NodeHI.GetDat().GetNbrNId(NodeN); }
520  bool IsInNId(const int& NId) const { return NodeHI.GetDat().IsInNId(NId); }
522  bool IsOutNId(const int& NId) const { return NodeHI.GetDat().IsOutNId(NId); }
524  bool IsNbrNId(const int& NId) const { return IsOutNId(NId) || IsInNId(NId); }
525  // node data
526  const TNodeData& operator () () const { return NodeHI.GetDat().NodeDat; }
527  TNodeData& operator () () { return NodeHI.GetDat().GetDat(); }
528  const TNodeData& GetDat() const { return NodeHI.GetDat().GetDat(); }
529  TNodeData& GetDat() { return NodeHI.GetDat().GetDat(); }
530  const TNodeData& GetOutNDat(const int& NodeN) const { return Net->GetNDat(GetOutNId(NodeN)); }
531  TNodeData& GetOutNDat(const int& NodeN) { return Net->GetNDat(GetOutNId(NodeN)); }
532  const TNodeData& GetInNDat(const int& NodeN) const { return Net->GetNDat(GetInNId(NodeN)); }
533  TNodeData& GetInNDat(const int& NodeN) { return Net->GetNDat(GetInNId(NodeN)); }
534  const TNodeData& GetNbrNDat(const int& NodeN) const { return Net->GetNDat(GetNbrNId(NodeN)); }
535  TNodeData& GetNbrNDat(const int& NodeN) { return Net->GetNDat(GetNbrNId(NodeN)); }
536  // edge data
537  TEdgeData& GetOutEDat(const int& EdgeN) { return NodeHI.GetDat().GetOutEDat(EdgeN); }
538  const TEdgeData& GetOutEDat(const int& EdgeN) const { return NodeHI.GetDat().GetOutEDat(EdgeN); }
539  TEdgeData& GetInEDat(const int& EdgeN) { return Net->GetEDat(GetInNId(EdgeN), GetId()); }
540  const TEdgeData& GetInEDat(const int& EdgeN) const { return Net->GetEDat(GetInNId(EdgeN), GetId()); }
541  TEdgeData& GetNbrEDat(const int& EdgeN) { return EdgeN<GetOutDeg() ? GetOutEDat(EdgeN) : GetInEDat(EdgeN-GetOutDeg()); }
542  const TEdgeData& GetNbrEDat(const int& EdgeN) const { return EdgeN<GetOutDeg() ? GetOutEDat(EdgeN) : GetInEDat(EdgeN-GetOutDeg()); }
543  friend class TNodeEDatNet<TNodeData, TEdgeData>;
544  };
545 
547  class TEdgeI {
548  private:
550  int CurEdge;
551  public:
552  TEdgeI() : CurNode(), EndNode(), CurEdge(0) { }
553  TEdgeI(const TNodeI& NodeI, const TNodeI& EndNodeI, const int& EdgeN=0) : CurNode(NodeI), EndNode(EndNodeI), CurEdge(EdgeN) { }
554  TEdgeI(const TEdgeI& EdgeI) : CurNode(EdgeI.CurNode), EndNode(EdgeI.EndNode), CurEdge(EdgeI.CurEdge) { }
555  TEdgeI& operator = (const TEdgeI& EdgeI) { if (this!=&EdgeI) { CurNode=EdgeI.CurNode; EndNode=EdgeI.EndNode; CurEdge=EdgeI.CurEdge; } return *this; }
558  while (CurNode < EndNode && CurNode.GetOutDeg()==0) { CurNode++; } } return *this; }
559  bool operator < (const TEdgeI& EdgeI) const { return CurNode<EdgeI.CurNode || (CurNode==EdgeI.CurNode && CurEdge<EdgeI.CurEdge); }
560  bool operator == (const TEdgeI& EdgeI) const { return CurNode == EdgeI.CurNode && CurEdge == EdgeI.CurEdge; }
562  int GetId() const { return -1; }
564  int GetSrcNId() const { return CurNode.GetId(); }
566  int GetDstNId() const { return CurNode.GetOutNId(CurEdge); }
567  TEdgeData& operator () () { return CurNode.GetOutEDat(CurEdge); }
568  const TEdgeData& operator () () const { return CurNode.GetOutEDat(CurEdge); }
569  TEdgeData& GetDat() { return CurNode.GetOutEDat(CurEdge); }
570  const TEdgeData& GetDat() const { return CurNode.GetOutEDat(CurEdge); }
571  TNodeData& GetSrcNDat() { return CurNode(); }
572  const TNodeData& GetSrcNDat() const { return CurNode(); }
573  TNodeData& GetDstNDat() { return CurNode.GetOutNDat(CurEdge); }
574  const TNodeData& GetDstNDat() const { return CurNode.GetOutNDat(CurEdge); }
575  friend class TNodeEDatNet<TNodeData, TEdgeData>;
576  };
577 
578 protected:
579  TNode& GetNode(const int& NId) { return NodeH.GetDat(NId); }
580  static int GetNIdPos(const TVec<TPair<TInt, TEdgeData> >& NIdV, const int& NId);
581 protected:
585 public:
586  TNodeEDatNet() : CRef(), MxNId(0), NodeH() { }
588  explicit TNodeEDatNet(const int& Nodes, const int& Edges) : MxNId(0) { Reserve(Nodes, Edges); }
589  TNodeEDatNet(const TNodeEDatNet& NodeNet) : MxNId(NodeNet.MxNId), NodeH(NodeNet.NodeH) { }
591  TNodeEDatNet(TSIn& SIn) : MxNId(SIn), NodeH(SIn) { }
592  virtual ~TNodeEDatNet() { }
594  virtual void Save(TSOut& SOut) const { MxNId.Save(SOut); NodeH.Save(SOut); }
596  static PNet New() { return PNet(new TNet()); }
598  static PNet Load(TSIn& SIn) { return PNet(new TNet(SIn)); }
600  bool HasFlag(const TGraphFlag& Flag) const;
601  TNodeEDatNet& operator = (const TNodeEDatNet& NodeNet) { if (this!=&NodeNet) {
602  NodeH=NodeNet.NodeH; MxNId=NodeNet.MxNId; } return *this; }
603  // nodes
605  int GetNodes() const { return NodeH.Len(); }
607 
611  int AddNode(int NId = -1);
613 
617  int AddNode(int NId, const TNodeData& NodeDat);
619  int AddNode(const TNodeI& NodeI) { return AddNode(NodeI.GetId(), NodeI.GetDat()); }
621 
623  void DelNode(const int& NId);
625  void DelNode(const TNode& NodeI) { DelNode(NodeI.GetId()); }
627  bool IsNode(const int& NId) const { return NodeH.IsKey(NId); }
629  TNodeI BegNI() const { return TNodeI(NodeH.BegI(), this); }
631  TNodeI EndNI() const { return TNodeI(NodeH.EndI(), this); }
633  TNodeI GetNI(const int& NId) const { return TNodeI(NodeH.GetI(NId), this); }
635  const TNode& GetNode(const int& NId) const { return NodeH.GetDat(NId); }
637  void SetNDat(const int& NId, const TNodeData& NodeDat);
639  TNodeData& GetNDat(const int& NId) { return NodeH.GetDat(NId).NodeDat; }
641  const TNodeData& GetNDat(const int& NId) const { return NodeH.GetDat(NId).NodeDat; }
643  int GetMxNId() const { return MxNId; }
644 
645  // edges
647  int GetEdges() const;
649 
655  int AddEdge(const int& SrcNId, const int& DstNId);
657 
663  int AddEdge(const int& SrcNId, const int& DstNId, const TEdgeData& EdgeDat);
665  int AddEdge(const TEdgeI& EdgeI) { return AddEdge(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), EdgeI()); }
667 
671  void DelEdge(const int& SrcNId, const int& DstNId, const bool& IsDir = true);
673  bool IsEdge(const int& SrcNId, const int& DstNId, const bool& IsDir = true) const;
675  TEdgeI BegEI() const { TNodeI NI=BegNI(); while(NI<EndNI() && NI.GetOutDeg()==0) NI++; return TEdgeI(NI, EndNI()); }
677  TEdgeI EndEI() const { return TEdgeI(EndNI(), EndNI()); }
679  TEdgeI GetEI(const int& EId) const; // not supported
681  TEdgeI GetEI(const int& SrcNId, const int& DstNId) const;
683  void SetEDat(const int& SrcNId, const int& DstNId, const TEdgeData& EdgeDat);
685 
687  bool GetEDat(const int& SrcNId, const int& DstNId, TEdgeData& EdgeDat) const;
689  TEdgeData& GetEDat(const int& SrcNId, const int& DstNId);
691  const TEdgeData& GetEDat(const int& SrcNId, const int& DstNId) const;
693  void SetAllEDat(const TEdgeData& EdgeDat);
694 
696  int GetRndNId(TRnd& Rnd=TInt::Rnd) { return NodeH.GetKey(NodeH.GetRndKeyId(Rnd, 0.8)); }
698  TNodeI GetRndNI(TRnd& Rnd=TInt::Rnd) { return GetNI(GetRndNId(Rnd)); }
700  void GetNIdV(TIntV& NIdV) const;
701 
703  bool Empty() const { return GetNodes()==0; }
705  void Clr(const bool& DoDel=true, const bool& ResetDat=true) {
706  MxNId = 0; NodeH.Clr(DoDel, -1, ResetDat); }
708  void Reserve(const int& Nodes, const int& Edges) { if (Nodes>0) { NodeH.Gen(Nodes/2); } }
710  void SortNIdById(const bool& Asc=true) { NodeH.SortByKey(Asc); }
712  void SortNIdByDat(const bool& Asc=true) { NodeH.SortByDat(Asc); }
714 
719  void Defrag(const bool& OnlyNodeLinks=false);
721 
724  bool IsOk(const bool& ThrowExcept=true) const;
725 
726  friend class TPt<TNodeEDatNet<TNodeData, TEdgeData> >;
727 };
728 
729 // set flags
730 namespace TSnap {
731 template <class TNodeData, class TEdgeData> struct IsDirected<TNodeEDatNet<TNodeData, TEdgeData> > { enum { Val = 1 }; };
732 template <class TNodeData, class TEdgeData> struct IsNodeDat<TNodeEDatNet<TNodeData, TEdgeData> > { enum { Val = 1 }; };
733 template <class TNodeData, class TEdgeData> struct IsEdgeDat<TNodeEDatNet<TNodeData, TEdgeData> > { enum { Val = 1 }; };
734 }
735 
736 template <class TNodeData, class TEdgeData>
738  return HasGraphFlag(typename TNet, Flag);
739 }
740 
741 template <class TNodeData, class TEdgeData>
743  int LValN=0, RValN = NIdV.Len()-1;
744  while (RValN >= LValN) {
745  const int ValN = (LValN+RValN)/2;
746  const int CurNId = NIdV[ValN].Val1;
747  if (NId == CurNId) { return ValN; }
748  if (NId < CurNId) { RValN=ValN-1; }
749  else { LValN=ValN+1; }
750  }
751  return -1;
752 }
753 
754 template <class TNodeData, class TEdgeData>
756  if (NId == -1) {
757  NId = MxNId; MxNId++;
758  } else {
759  IAssertR(!IsNode(NId), TStr::Fmt("NodeId %d already exists", NId));
760  MxNId = TMath::Mx(NId+1, MxNId());
761  }
762  NodeH.AddDat(NId, TNode(NId));
763  return NId;
764 }
765 
766 template <class TNodeData, class TEdgeData>
767 int TNodeEDatNet<TNodeData, TEdgeData>::AddNode(int NId, const TNodeData& NodeDat) {
768  if (NId == -1) {
769  NId = MxNId; MxNId++;
770  } else {
771  IAssertR(!IsNode(NId), TStr::Fmt("NodeId %d already exists", NId));
772  MxNId = TMath::Mx(NId+1, MxNId());
773  }
774  NodeH.AddDat(NId, TNode(NId, NodeDat));
775  return NId;
776 }
777 
778 template <class TNodeData, class TEdgeData>
779 void TNodeEDatNet<TNodeData, TEdgeData>::SetNDat(const int& NId, const TNodeData& NodeDat) {
780  IAssertR(IsNode(NId), TStr::Fmt("NodeId %d does not exist.", NId).CStr());
781  NodeH.GetDat(NId).NodeDat = NodeDat;
782 }
783 
784 template <class TNodeData, class TEdgeData>
786  const TNode& Node = GetNode(NId);
787  for (int out = 0; out < Node.GetOutDeg(); out++) {
788  const int nbr = Node.GetOutNId(out);
789  if (nbr == NId) { continue; }
790  TIntV& NIdV = GetNode(nbr).InNIdV;
791  const int pos = NIdV.SearchBin(NId);
792  if (pos != -1) { NIdV.Del(pos); }
793  }
794  for (int in = 0; in < Node.GetInDeg(); in++) {
795  const int nbr = Node.GetInNId(in);
796  if (nbr == NId) { continue; }
797  TNIdDatPrV& NIdDatV = GetNode(nbr).OutNIdV;
798  const int pos = GetNIdPos(NIdDatV, NId);
799  if (pos != -1) { NIdDatV.Del(pos); }
800  }
801  NodeH.DelKey(NId);
802 }
803 
804 template <class TNodeData, class TEdgeData>
806  int edges=0;
807  for (int N=NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
808  edges+=NodeH[N].GetOutDeg(); }
809  return edges;
810 }
811 
812 template <class TNodeData, class TEdgeData>
813 int TNodeEDatNet<TNodeData, TEdgeData>::AddEdge(const int& SrcNId, const int& DstNId) {
814  return AddEdge(SrcNId, DstNId, TEdgeData());
815 }
816 
817 template <class TNodeData, class TEdgeData>
818 int TNodeEDatNet<TNodeData, TEdgeData>::AddEdge(const int& SrcNId, const int& DstNId, const TEdgeData& EdgeDat) {
819  IAssertR(IsNode(SrcNId) && IsNode(DstNId), TStr::Fmt("%d or %d not a node.", SrcNId, DstNId).CStr());
820  //IAssert(! IsEdge(SrcNId, DstNId));
821  if (IsEdge(SrcNId, DstNId)) {
822  GetEDat(SrcNId, DstNId) = EdgeDat;
823  return -2;
824  }
825  GetNode(SrcNId).OutNIdV.AddSorted(TPair<TInt, TEdgeData>(DstNId, EdgeDat));
826  GetNode(DstNId).InNIdV.AddSorted(SrcNId);
827  return -1; // edge id
828 }
829 
830 template <class TNodeData, class TEdgeData>
831 void TNodeEDatNet<TNodeData, TEdgeData>::DelEdge(const int& SrcNId, const int& DstNId, const bool& IsDir) {
832  IAssertR(IsNode(SrcNId) && IsNode(DstNId), TStr::Fmt("%d or %d not a node.", SrcNId, DstNId).CStr());
833  int pos = GetNIdPos(GetNode(SrcNId).OutNIdV, DstNId);
834  if (pos != -1) { GetNode(SrcNId).OutNIdV.Del(pos); }
835  pos = GetNode(DstNId).InNIdV.SearchBin(SrcNId);
836  if (pos != -1) { GetNode(DstNId).InNIdV.Del(pos); }
837  if (! IsDir) {
838  pos = GetNIdPos(GetNode(DstNId).OutNIdV, SrcNId);
839  if (pos != -1) { GetNode(DstNId).OutNIdV.Del(pos); }
840  pos = GetNode(SrcNId).InNIdV.SearchBin(DstNId);
841  if (pos != -1) { GetNode(SrcNId).InNIdV.Del(pos); }
842  }
843 }
844 
845 template <class TNodeData, class TEdgeData>
846 bool TNodeEDatNet<TNodeData, TEdgeData>::IsEdge(const int& SrcNId, const int& DstNId, const bool& IsDir) const {
847  if (! IsNode(SrcNId) || ! IsNode(DstNId)) { return false; }
848  if (IsDir) { return GetNode(SrcNId).IsOutNId(DstNId); }
849  else { return GetNode(SrcNId).IsOutNId(DstNId) || GetNode(DstNId).IsOutNId(SrcNId); }
850 }
851 
852 template <class TNodeData, class TEdgeData>
853 void TNodeEDatNet<TNodeData, TEdgeData>::SetEDat(const int& SrcNId, const int& DstNId, const TEdgeData& EdgeDat) {
854  IAssertR(IsNode(SrcNId) && IsNode(DstNId), TStr::Fmt("%d or %d not a node.", SrcNId, DstNId).CStr());
855  IAssertR(IsEdge(SrcNId, DstNId), TStr::Fmt("Edge between %d and %d does not exist.", SrcNId, DstNId).CStr());
856  GetEDat(SrcNId, DstNId) = EdgeDat;
857 }
858 
859 template <class TNodeData, class TEdgeData>
860 bool TNodeEDatNet<TNodeData, TEdgeData>::GetEDat(const int& SrcNId, const int& DstNId, TEdgeData& EdgeDat) const {
861  if (! IsEdge(SrcNId, DstNId)) { return false; }
862  const TNode& N = GetNode(SrcNId);
863  EdgeDat = N.GetOutEDat(GetNIdPos(N.OutNIdV, DstNId));
864  return true;
865 }
866 
867 template <class TNodeData, class TEdgeData>
868 TEdgeData& TNodeEDatNet<TNodeData, TEdgeData>::GetEDat(const int& SrcNId, const int& DstNId) {
869  Assert(IsEdge(SrcNId, DstNId));
870  TNode& N = GetNode(SrcNId);
871  return N.GetOutEDat(GetNIdPos(N.OutNIdV, DstNId));
872 }
873 
874 template <class TNodeData, class TEdgeData>
875 const TEdgeData& TNodeEDatNet<TNodeData, TEdgeData>::GetEDat(const int& SrcNId, const int& DstNId) const {
876  Assert(IsEdge(SrcNId, DstNId));
877  const TNode& N = GetNode(SrcNId);
878  return N.GetOutEDat(GetNIdPos(N.OutNIdV, DstNId));
879 }
880 
881 template <class TNodeData, class TEdgeData>
882 void TNodeEDatNet<TNodeData, TEdgeData>::SetAllEDat(const TEdgeData& EdgeDat) {
883  for (TEdgeI EI = BegEI(); EI < EndEI(); EI++) {
884  EI() = EdgeDat;
885  }
886 }
887 
888 template <class TNodeData, class TEdgeData>
889 typename TNodeEDatNet<TNodeData, TEdgeData>::TEdgeI TNodeEDatNet<TNodeData, TEdgeData>::GetEI(const int& SrcNId, const int& DstNId) const {
890  const TNodeI SrcNI = GetNI(SrcNId);
891  int NodeN = -1;
892  //SrcNI.NodeHI.GetDat().OutNIdV.SearchBin(DstNId);
893  const TNIdDatPrV& NIdDatV = SrcNI.NodeHI.GetDat().OutNIdV;
894  int LValN=0, RValN=NIdDatV.Len()-1;
895  while (RValN>=LValN){
896  int ValN=(LValN+RValN)/2;
897  if (DstNId==NIdDatV[ValN].Val1){ NodeN=ValN; break; }
898  if (DstNId<NIdDatV[ValN].Val1){RValN=ValN-1;} else {LValN=ValN+1;}
899  }
900  if (NodeN == -1) { return EndEI(); }
901  else { return TEdgeI(SrcNI, EndNI(), NodeN); }
902 }
903 
904 template <class TNodeData, class TEdgeData>
906  NIdV.Reserve(GetNodes(), 0);
907  for (int N=NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
908  NIdV.Add(NodeH.GetKey(N)); }
909 }
910 
911 template <class TNodeData, class TEdgeData>
912 void TNodeEDatNet<TNodeData, TEdgeData>::Defrag(const bool& OnlyNodeLinks) {
913  for (int n = NodeH.FFirstKeyId(); NodeH.FNextKeyId(n);) {
914  TNode& Node = NodeH[n];
915  Node.InNIdV.Pack(); Node.OutNIdV.Pack();
916  }
917  if (! OnlyNodeLinks && ! NodeH.IsKeyIdEqKeyN()) {
918  NodeH.Defrag();
919  }
920 }
921 
922 template <class TNodeData, class TEdgeData>
923 bool TNodeEDatNet<TNodeData, TEdgeData>::IsOk(const bool& ThrowExcept) const {
924  bool RetVal = true;
925  for (int N = NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
926  const TNode& Node = NodeH[N];
927  if (! Node.OutNIdV.IsSorted()) {
928  const TStr Msg = TStr::Fmt("Out-neighbor list of node %d is not sorted.", Node.GetId());
929  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
930  }
931  if (! Node.InNIdV.IsSorted()) {
932  const TStr Msg = TStr::Fmt("In-neighbor list of node %d is not sorted.", Node.GetId());
933  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
934  }
935  // check out-edges
936  int prevNId = -1;
937  for (int e = 0; e < Node.GetOutDeg(); e++) {
938  if (! IsNode(Node.GetOutNId(e))) {
939  const TStr Msg = TStr::Fmt("Out-edge %d --> %d: node %d does not exist.",
940  Node.GetId(), Node.GetOutNId(e), Node.GetOutNId(e));
941  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
942  }
943  if (e > 0 && prevNId == Node.GetOutNId(e)) {
944  const TStr Msg = TStr::Fmt("Node %d has duplidate out-edge %d --> %d.",
945  Node.GetId(), Node.GetId(), Node.GetOutNId(e));
946  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
947  }
948  prevNId = Node.GetOutNId(e);
949  }
950  // check in-edges
951  prevNId = -1;
952  for (int e = 0; e < Node.GetInDeg(); e++) {
953  if (! IsNode(Node.GetInNId(e))) {
954  const TStr Msg = TStr::Fmt("In-edge %d <-- %d: node %d does not exist.",
955  Node.GetId(), Node.GetInNId(e), Node.GetInNId(e));
956  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
957  }
958  if (e > 0 && prevNId == Node.GetInNId(e)) {
959  const TStr Msg = TStr::Fmt("Node %d has duplidate in-edge %d <-- %d.",
960  Node.GetId(), Node.GetId(), Node.GetInNId(e));
961  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
962  }
963  prevNId = Node.GetInNId(e);
964  }
965  }
966  return RetVal;
967 }
968 
970 // Common network types
977 
978 //#//////////////////////////////////////////////
980 template <class TNodeData, class TEdgeData>
982 public:
983  typedef TNodeData TNodeDat;
984  typedef TEdgeData TEdgeDat;
986  typedef TPt<TNet> PNet;
987 public:
988  class TNode {
989  private:
992  TNodeData NodeDat;
993  public:
994  TNode() : Id(-1), InEIdV(), OutEIdV(), NodeDat() { }
995  TNode(const int& NId) : Id(NId), InEIdV(), OutEIdV(), NodeDat() { }
996  TNode(const int& NId, const TNodeData& NodeData) : Id(NId), InEIdV(), OutEIdV(), NodeDat(NodeData) { }
997  TNode(const TNode& Node) : Id(Node.Id), InEIdV(Node.InEIdV), OutEIdV(Node.OutEIdV), NodeDat(Node.NodeDat) { }
998  TNode(TSIn& SIn) : Id(SIn), InEIdV(SIn), OutEIdV(SIn), NodeDat(SIn) { }
999  void Save(TSOut& SOut) const { Id.Save(SOut); InEIdV.Save(SOut); OutEIdV.Save(SOut); NodeDat.Save(SOut); }
1000  bool operator < (const TNode& Node) const { return NodeDat < Node.NodeDat; }
1001  int GetId() const { return Id; }
1002  int GetDeg() const { return GetInDeg() + GetOutDeg(); }
1003  int GetInDeg() const { return InEIdV.Len(); }
1004  int GetOutDeg() const { return OutEIdV.Len(); }
1005  const TNodeData& GetDat() const { return NodeDat; }
1006  TNodeData& GetDat() { return NodeDat; }
1007  int GetInEId(const int& NodeN) const { return InEIdV[NodeN]; }
1008  int GetOutEId(const int& NodeN) const { return OutEIdV[NodeN]; }
1009  int GetNbrEId(const int& EdgeN) const { return EdgeN<GetOutDeg()?GetOutEId(EdgeN):GetInEId(EdgeN-GetOutDeg()); }
1010  bool IsInEId(const int& EId) const { return InEIdV.SearchBin(EId) != -1; }
1011  bool IsOutEId(const int& EId) const { return OutEIdV.SearchBin(EId) != -1; }
1012  bool IsNbrEId(const int& EId) const { return IsInEId(EId) || IsOutEId(EId); }
1013  friend class TNodeEdgeNet<TNodeData, TEdgeData>;
1014  };
1015 
1016  class TEdge {
1017  private:
1019  TEdgeData EdgeDat;
1020  public:
1021  TEdge() : Id(-1), SrcNId(-1), DstNId(-1), EdgeDat() { }
1022  TEdge(const int& EId, const int& SourceNId, const int& DestNId) : Id(EId), SrcNId(SourceNId), DstNId(DestNId), EdgeDat() { }
1023  TEdge(const int& EId, const int& SourceNId, const int& DestNId, const TEdgeData& EdgeData) : Id(EId), SrcNId(SourceNId), DstNId(DestNId), EdgeDat(EdgeData) { }
1024  TEdge(const TEdge& Edge) : Id(Edge.Id), SrcNId(Edge.SrcNId), DstNId(Edge.DstNId), EdgeDat(Edge.EdgeDat) { }
1025  TEdge(TSIn& SIn) : Id(SIn), SrcNId(SIn), DstNId(SIn), EdgeDat(SIn) { }
1026  void Save(TSOut& SOut) const { Id.Save(SOut); SrcNId.Save(SOut); DstNId.Save(SOut); EdgeDat.Save(SOut); }
1027  bool operator < (const TEdge& Edge) const { return EdgeDat < Edge.EdgeDat; }
1028  int GetId() const { return Id; }
1029  int GetSrcNId() const { return SrcNId; }
1030  int GetDstNId() const { return DstNId; }
1031  const TEdgeData& GetDat() const { return EdgeDat; }
1032  TEdgeData& GetDat() { return EdgeDat; }
1033  friend class TNodeEdgeNet;
1034  };
1035 
1037  class TNodeI {
1038  private:
1042  public:
1043  TNodeI() : NodeHI(), Net(NULL) { }
1044  TNodeI(const THashIter& NodeHIter, const TNodeEdgeNet* NetPt) : NodeHI(NodeHIter), Net((TNodeEdgeNet *)NetPt) { }
1045  TNodeI(const TNodeI& NodeI) : NodeHI(NodeI.NodeHI), Net(NodeI.Net) { }
1046  TNodeI& operator = (const TNodeI& NodeI) { NodeHI = NodeI.NodeHI; Net=NodeI.Net; return *this; }
1048  TNodeI& operator++ (int) { NodeHI++; return *this; }
1049  bool operator < (const TNodeI& NodeI) const { return NodeHI < NodeI.NodeHI; }
1050  bool operator == (const TNodeI& NodeI) const { return NodeHI == NodeI.NodeHI; }
1052  int GetId() const { return NodeHI.GetDat().GetId(); }
1054  int GetDeg() const { return NodeHI.GetDat().GetDeg(); }
1056  int GetInDeg() const { return NodeHI.GetDat().GetInDeg(); }
1058  int GetOutDeg() const { return NodeHI.GetDat().GetOutDeg(); }
1060 
1062  int GetInNId(const int& EdgeN) const { return Net->GetEdge(NodeHI.GetDat().GetInEId(EdgeN)).GetSrcNId(); }
1064 
1066  int GetOutNId(const int& EdgeN) const { return Net->GetEdge(NodeHI.GetDat().GetOutEId(EdgeN)).GetDstNId(); }
1068 
1070  int GetNbrNId(const int& EdgeN) const { const TEdge& E = Net->GetEdge(NodeHI.GetDat().GetNbrEId(EdgeN));
1071  return GetId()==E.GetSrcNId() ? E.GetDstNId():E.GetSrcNId(); }
1073  bool IsInNId(const int& NId) const;
1075  bool IsOutNId(const int& NId) const;
1077  bool IsNbrNId(const int& NId) const { return IsOutNId(NId) || IsInNId(NId); }
1078  // node data
1079  const TNodeData& operator () () const { return NodeHI.GetDat().GetDat(); }
1080  TNodeData& operator () () { return NodeHI.GetDat().GetDat(); }
1081  const TNodeData& GetDat() const { return NodeHI.GetDat().GetDat(); }
1082  TNodeData& GetDat() { return NodeHI.GetDat().GetDat(); }
1083  const TNodeData& GetInNDat(const int& EdgeN) const { return Net->GetNDat(GetInNId(EdgeN)); }
1084  TNodeData& GetInNDat(const int& EdgeN) { return Net->GetNDat(GetInNId(EdgeN)); }
1085  const TNodeData& GetOutNDat(const int& EdgeN) const { return Net->GetNDat(GetOutNId(EdgeN)); }
1086  TNodeData& GetOutNDat(const int& EdgeN) { return Net->GetNDat(GetOutNId(EdgeN)); }
1087  const TNodeData& GetNbrNDat(const int& EdgeN) const { return Net->GetNDat(GetNbrNId(EdgeN)); }
1088  TNodeData& GetNbrNDat(const int& EdgeN) { return Net->GetNDat(GetNbrNId(EdgeN)); }
1089  // edges
1091  int GetInEId(const int& EdgeN) const { return NodeHI.GetDat().GetInEId(EdgeN); }
1093  int GetOutEId(const int& EdgeN) const { return NodeHI.GetDat().GetOutEId(EdgeN); }
1095  int GetNbrEId(const int& EdgeN) const { return NodeHI.GetDat().GetNbrEId(EdgeN); }
1097  bool IsInEId(const int& EId) const { return NodeHI.GetDat().IsInEId(EId); }
1099  bool IsOutEId(const int& EId) const { return NodeHI.GetDat().IsOutEId(EId); }
1101  bool IsNbrEId(const int& EId) const { return NodeHI.GetDat().IsNbrEId(EId); }
1102  // edge data
1103  TEdgeDat& GetInEDat(const int& EdgeN) { return Net->GetEDat(GetInEId(EdgeN)); }
1104  const TEdgeDat& GetInEDat(const int& EdgeN) const { return Net->GetEDat(GetInEId(EdgeN)); }
1105  TEdgeDat& GetOutEDat(const int& EdgeN) { return Net->GetEDat(GetOutEId(EdgeN)); }
1106  const TEdgeDat& GetOutEDat(const int& EdgeN) const { return Net->GetEDat(GetOutEId(EdgeN)); }
1107  TEdgeDat& GetNbrEDat(const int& EdgeN) { return Net->GetEDat(GetNbrEId(EdgeN)); }
1108  const TEdgeDat& GetNbrEDat(const int& EdgeN) const { return Net->GetEDat(GetNbrEId(EdgeN)); }
1109  friend class TNodeEdgeNet;
1110  };
1111 
1113  class TEdgeI {
1114  private:
1118  public:
1119  TEdgeI() : EdgeHI(), Net(NULL) { }
1120  TEdgeI(const THashIter& EdgeHIter, const TNodeEdgeNet *NetPt) : EdgeHI(EdgeHIter), Net((TNodeEdgeNet *) NetPt) { }
1121  TEdgeI(const TEdgeI& EdgeI) : EdgeHI(EdgeI.EdgeHI), Net(EdgeI.Net) { }
1122  TEdgeI& operator = (const TEdgeI& EdgeI) { if (this!=&EdgeI) { EdgeHI=EdgeI.EdgeHI; Net=EdgeI.Net; } return *this; }
1123  TEdgeI& operator++ (int) { EdgeHI++; return *this; }
1124  bool operator < (const TEdgeI& EdgeI) const { return EdgeHI < EdgeI.EdgeHI; }
1125  bool operator == (const TEdgeI& EdgeI) const { return EdgeHI == EdgeI.EdgeHI; }
1127  int GetId() const { return EdgeHI.GetDat().GetId(); }
1129  int GetSrcNId() const { return EdgeHI.GetDat().GetSrcNId(); }
1131  int GetDstNId() const { return EdgeHI.GetDat().GetDstNId(); }
1132  const TEdgeData& operator () () const { return EdgeHI.GetDat().GetDat(); }
1133  TEdgeData& operator () () { return EdgeHI.GetDat().GetDat(); }
1134  const TEdgeData& GetDat() const { return EdgeHI.GetDat().GetDat(); }
1135  TEdgeData& GetDat() { return EdgeHI.GetDat().GetDat(); }
1136  const TNodeData& GetSrcNDat() const { return Net->GetNDat(GetSrcNId()); }
1137  TNodeData& GetSrcNDat() { return Net->GetNDat(GetSrcNId()); }
1138  const TNodeData& GetDstNDat() const { return Net->GetNDat(GetDstNId()); }
1139  TNodeData& GetDstNDat() { return Net->GetNDat(GetDstNId()); }
1140  friend class TNodeEdgeNet;
1141  };
1142 
1143 private:
1144  TNode& GetNode(const int& NId) { return NodeH.GetDat(NId); }
1145  const TNode& GetNode(const int& NId) const { return NodeH.GetDat(NId); }
1146  const TNode& GetNodeKId(const int& NodeKeyId) const { return NodeH[NodeKeyId]; }
1147  TEdge& GetEdge(const int& EId) { return EdgeH.GetDat(EId); }
1148  const TEdge& GetEdge(const int& EId) const { return EdgeH.GetDat(EId); }
1149  const TEdge& GetEdgeKId(const int& EdgeKeyId) const { return EdgeH[EdgeKeyId]; }
1150 protected:
1155 public:
1156  TNodeEdgeNet() : CRef(), MxNId(0), MxEId(0) { }
1158  explicit TNodeEdgeNet(const int& Nodes, const int& Edges) : CRef(), MxNId(0), MxEId(0) { Reserve(Nodes, Edges); }
1159  TNodeEdgeNet(const TNodeEdgeNet& Net) : MxNId(Net.MxNId), MxEId(Net.MxEId), NodeH(Net.NodeH), EdgeH(Net.EdgeH) { }
1161  TNodeEdgeNet(TSIn& SIn) : MxNId(SIn), MxEId(SIn), NodeH(SIn), EdgeH(SIn) { }
1162  virtual ~TNodeEdgeNet() { }
1164  virtual void Save(TSOut& SOut) const { MxNId.Save(SOut); MxEId.Save(SOut); NodeH.Save(SOut); EdgeH.Save(SOut); }
1166  static PNet New() { return PNet(new TNet()); }
1168  static PNet Load(TSIn& SIn) { return PNet(new TNet(SIn)); }
1170  bool HasFlag(const TGraphFlag& Flag) const;
1172  if (this!=&Net) { NodeH=Net.NodeH; EdgeH=Net.EdgeH; MxNId=Net.MxNId; MxEId=Net.MxEId; } return *this; }
1173  // nodes
1175  int GetNodes() const { return NodeH.Len(); }
1177 
1181  int AddNode(int NId = -1);
1183 
1187  int AddNode(int NId, const TNodeData& NodeDat);
1189  friend class TCrossNet;
1190  int AddNode(const TNodeI& NodeI) { return AddNode(NodeI.GetId(), NodeI.GetDat()); }
1192 
1194  void DelNode(const int& NId);
1196  void DelNode(const TNode& NodeI) { DelNode(NodeI.GetId()); }
1198  bool IsNode(const int& NId) const { return NodeH.IsKey(NId); }
1200  TNodeI BegNI() const { return TNodeI(NodeH.BegI(), this); }
1202  TNodeI EndNI() const { return TNodeI(NodeH.EndI(), this); }
1204  TNodeI GetNI(const int& NId) const { return TNodeI(NodeH.GetI(NId), this); }
1206  void SetNDat(const int& NId, const TNodeData& NodeDat);
1208  TNodeData& GetNDat(const int& NId) { return NodeH.GetDat(NId).NodeDat; }
1210  const TNodeData& GetNDat(const int& NId) const { return NodeH.GetDat(NId).NodeDat; }
1212  int GetMxNId() const { return MxNId; }
1213 
1214  // edges
1216  int GetEdges() const { return EdgeH.Len(); }
1218  int GetUniqEdges(const bool& IsDir=true) const;
1220 
1225  int AddEdge(const int& SrcNId, const int& DstNId, int EId = -1);
1227 
1232  int AddEdge(const int& SrcNId, const int& DstNId, int EId, const TEdgeData& EdgeDat);
1234  int AddEdge(const TEdgeI& EdgeI) { return AddEdge(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), EdgeI.GetId(), EdgeI.GetDat()); }
1236  void DelEdge(const int& EId);
1238 
1242  void DelEdge(const int& SrcNId, const int& DstNId, const bool& IsDir = true);
1244  bool IsEdge(const int& EId) const { return EdgeH.IsKey(EId); }
1246  bool IsEdge(const int& SrcNId, const int& DstNId, const bool& IsDir = true) const { int EId; return IsEdge(SrcNId, DstNId, EId, IsDir); }
1248  bool IsEdge(const int& SrcNId, const int& DstNId, int& EId, const bool& IsDir = true) const;
1249  int GetEId(const int& SrcNId, const int& DstNId) const { int EId; return IsEdge(SrcNId, DstNId, EId)?EId:-1; }
1251  TEdgeI BegEI() const { return TEdgeI(EdgeH.BegI(), this); }
1253  TEdgeI EndEI() const { return TEdgeI(EdgeH.EndI(), this); }
1255  TEdgeI GetEI(const int& EId) const { return TEdgeI(EdgeH.GetI(EId), this); }
1257  TEdgeI GetEI(const int& SrcNId, const int& DstNId) const { return GetEI(GetEId(SrcNId, DstNId)); }
1259  void SetEDat(const int& EId, const TEdgeData& EdgeDat);
1261  TEdgeData& GetEDat(const int& EId) { return EdgeH.GetDat(EId).EdgeDat; }
1263  const TEdgeData& GetEDat(const int& EId) const { return EdgeH.GetDat(EId).EdgeDat; }
1265  void SetAllEDat(const TEdgeData& EdgeDat);
1266 
1268  int GetRndNId(TRnd& Rnd=TInt::Rnd) { return NodeH.GetKey(NodeH.GetRndKeyId(Rnd, 0.8)); }
1270  TNodeI GetRndNI(TRnd& Rnd=TInt::Rnd) { return GetNI(GetRndNId(Rnd)); }
1272  int GetRndEId(TRnd& Rnd=TInt::Rnd) { return EdgeH.GetKey(EdgeH.GetRndKeyId(Rnd, 0.8)); }
1274  TEdgeI GetRndEI(TRnd& Rnd=TInt::Rnd) { return GetEI(GetRndEId(Rnd)); }
1276  void GetNIdV(TIntV& NIdV) const;
1278  void GetEIdV(TIntV& EIdV) const;
1279 
1281  bool Empty() const { return GetNodes()==0; }
1283  void Clr() { MxNId=0; MxEId=0; NodeH.Clr(); EdgeH.Clr(); }
1285  void Reserve(const int& Nodes, const int& Edges) {
1286  if (Nodes>0) { NodeH.Gen(Nodes/2); } if (Edges>0) { EdgeH.Gen(Edges/2); } }
1288  void SortNIdById(const bool& Asc=true) { NodeH.SortByKey(Asc); }
1290  void SortNIdByDat(const bool& Asc=true) { NodeH.SortByDat(Asc); }
1292  void SortEIdById(const bool& Asc=true) { EdgeH.SortByKey(Asc); }
1294  void SortEIdByDat(const bool& Asc=true) { EdgeH.SortByDat(Asc); }
1296 
1301  void Defrag(const bool& OnlyNodeLinks=false);
1303 
1306  bool IsOk(const bool& ThrowExcept=true) const;
1307 
1308  friend class TPt<TNodeEdgeNet<TNodeData, TEdgeData> >;
1309 };
1310 
1311 // set flags
1312 namespace TSnap {
1313 template <class TNodeData, class TEdgeData> struct IsMultiGraph<TNodeEdgeNet<TNodeData, TEdgeData> > { enum { Val = 1 }; };
1314 template <class TNodeData, class TEdgeData> struct IsDirected<TNodeEdgeNet<TNodeData, TEdgeData> > { enum { Val = 1 }; };
1315 template <class TNodeData, class TEdgeData> struct IsNodeDat<TNodeEdgeNet<TNodeData, TEdgeData> > { enum { Val = 1 }; };
1316 template <class TNodeData, class TEdgeData> struct IsEdgeDat<TNodeEdgeNet<TNodeData, TEdgeData> > { enum { Val = 1 }; };
1317 }
1318 
1319 template <class TNodeData, class TEdgeData>
1321  return HasGraphFlag(typename TNet, Flag);
1322 }
1323 
1324 template <class TNodeData, class TEdgeData>
1326  const TNode& Node = NodeHI.GetDat();
1327  for (int edge = 0; edge < Node.GetInDeg(); edge++) {
1328  if (NId == Net->GetEdge(Node.GetInEId(edge)).GetSrcNId())
1329  return true;
1330  }
1331  return false;
1332 }
1333 
1334 template <class TNodeData, class TEdgeData>
1336  const TNode& Node = NodeHI.GetDat();
1337  for (int edge = 0; edge < Node.GetOutDeg(); edge++) {
1338  if (NId == Net->GetEdge(Node.GetOutEId(edge)).GetDstNId())
1339  return true;
1340  }
1341  return false;
1342 }
1343 
1344 template <class TNodeData, class TEdgeData>
1346  if (NId == -1) {
1347  NId = MxNId; MxNId++;
1348  } else {
1349  IAssertR(!IsNode(NId), TStr::Fmt("NodeId %d already exists", NId));
1350  MxNId = TMath::Mx(NId+1, MxNId());
1351  }
1352  NodeH.AddDat(NId, TNode(NId));
1353  return NId;
1354 }
1355 
1356 template <class TNodeData, class TEdgeData>
1357 int TNodeEdgeNet<TNodeData, TEdgeData>::AddNode(int NId, const TNodeData& NodeDat) {
1358  if (NId == -1) {
1359  NId = MxNId; MxNId++;
1360  } else {
1361  IAssertR(!IsNode(NId), TStr::Fmt("NodeId %d already exists", NId));
1362  MxNId = TMath::Mx(NId+1, MxNId());
1363  }
1364  NodeH.AddDat(NId, TNode(NId, NodeDat));
1365  return NId;
1366 }
1367 
1368 template <class TNodeData, class TEdgeData>
1370  const TNode& Node = GetNode(NId);
1371  for (int out = 0; out < Node.GetOutDeg(); out++) {
1372  const int EId = Node.GetOutEId(out);
1373  const TEdge& Edge = GetEdge(EId);
1374  IAssert(Edge.GetSrcNId() == NId);
1375  GetNode(Edge.GetDstNId()).InEIdV.DelIfIn(EId);
1376  EdgeH.DelKey(EId);
1377  }
1378  for (int in = 0; in < Node.GetInDeg(); in++) {
1379  const int EId = Node.GetInEId(in);
1380  const TEdge& Edge = GetEdge(EId);
1381  IAssert(Edge.GetDstNId() == NId);
1382  GetNode(Edge.GetSrcNId()).OutEIdV.DelIfIn(EId);
1383  EdgeH.DelKey(EId);
1384  }
1385  NodeH.DelKey(NId);
1386 }
1387 
1388 template <class TNodeData, class TEdgeData>
1389 void TNodeEdgeNet<TNodeData, TEdgeData>::SetNDat(const int& NId, const TNodeData& NodeDat) {
1390  IAssertR(IsNode(NId), TStr::Fmt("NodeId %d does not exist.", NId).CStr());
1391  NodeH.GetDat(NId).NodeDat = NodeDat;
1392 }
1393 
1394 template <class TNodeData, class TEdgeData>
1396  TIntPrSet UniqESet(GetEdges());
1397  for (TEdgeI EI = BegEI(); EI < EndEI(); EI++) {
1398  const int Src = EI.GetSrcNId();
1399  const int Dst = EI.GetDstNId();
1400  if (IsDir) { UniqESet.AddKey(TIntPr(Src, Dst)); }
1401  else { UniqESet.AddKey(TIntPr(TMath::Mn(Src, Dst), TMath::Mx(Src, Dst))); }
1402  }
1403  return UniqESet.Len();
1404 }
1405 
1406 template <class TNodeData, class TEdgeData>
1407 int TNodeEdgeNet<TNodeData, TEdgeData>::AddEdge(const int& SrcNId, const int& DstNId, int EId) {
1408  if (EId == -1) { EId = MxEId; MxEId++; }
1409  else { MxEId = TMath::Mx(EId+1, MxEId()); }
1410  IAssertR(!IsEdge(EId), TStr::Fmt("EdgeId %d already exists", EId));
1411  IAssertR(IsNode(SrcNId) && IsNode(DstNId), TStr::Fmt("%d or %d not a node.", SrcNId, DstNId).CStr());
1412  EdgeH.AddDat(EId, TEdge(EId, SrcNId, DstNId));
1413  GetNode(SrcNId).OutEIdV.AddSorted(EId);
1414  GetNode(DstNId).InEIdV.AddSorted(EId);
1415  return EId;
1416 }
1417 
1418 template <class TNodeData, class TEdgeData>
1419 int TNodeEdgeNet<TNodeData, TEdgeData>::AddEdge(const int& SrcNId, const int& DstNId, int EId, const TEdgeData& EdgeDat) {
1420  if (EId == -1) { EId = MxEId; MxEId++; }
1421  else { MxEId = TMath::Mx(EId+1, MxEId()); }
1422  IAssertR(!IsEdge(EId), TStr::Fmt("EdgeId %d already exists", EId));
1423  IAssertR(IsNode(SrcNId) && IsNode(DstNId), TStr::Fmt("%d or %d not a node.", SrcNId, DstNId).CStr());
1424  EdgeH.AddDat(EId, TEdge(EId, SrcNId, DstNId, EdgeDat));
1425  GetNode(SrcNId).OutEIdV.AddSorted(EId);
1426  GetNode(DstNId).InEIdV.AddSorted(EId);
1427  return EId;
1428 }
1429 
1430 template <class TNodeData, class TEdgeData>
1432  IAssert(IsEdge(EId));
1433  const int SrcNId = GetEdge(EId).GetSrcNId();
1434  const int DstNId = GetEdge(EId).GetDstNId();
1435  GetNode(SrcNId).OutEIdV.DelIfIn(EId);
1436  GetNode(DstNId).InEIdV.DelIfIn(EId);
1437  EdgeH.DelKey(EId);
1438 }
1439 
1440 template <class TNodeData, class TEdgeData>
1441 void TNodeEdgeNet<TNodeData, TEdgeData>::DelEdge(const int& SrcNId, const int& DstNId, const bool& IsDir) {
1442  int EId;
1443  IAssert(IsEdge(SrcNId, DstNId, EId, IsDir));
1444  GetNode(SrcNId).OutEIdV.DelIfIn(EId);
1445  GetNode(DstNId).InEIdV.DelIfIn(EId);
1446  EdgeH.DelKey(EId);
1447 }
1448 
1449 template <class TNodeData, class TEdgeData>
1450 bool TNodeEdgeNet<TNodeData, TEdgeData>::IsEdge(const int& SrcNId, const int& DstNId, int& EId, const bool& IsDir) const {
1451  if (! IsNode(SrcNId)) { return false; }
1452  if (! IsNode(DstNId)) { return false; }
1453  const TNode& SrcNode = GetNode(SrcNId);
1454  for (int edge = 0; edge < SrcNode.GetOutDeg(); edge++) {
1455  const TEdge& Edge = GetEdge(SrcNode.GetOutEId(edge));
1456  if (DstNId == Edge.GetDstNId()) {
1457  EId = Edge.GetId(); return true; }
1458  }
1459  if (! IsDir) {
1460  for (int edge = 0; edge < SrcNode.GetInDeg(); edge++) {
1461  const TEdge& Edge = GetEdge(SrcNode.GetInEId(edge));
1462  if (DstNId == Edge.GetSrcNId()) {
1463  EId = Edge.GetId(); return true; }
1464  }
1465  }
1466  return false;
1467 }
1468 
1469 template <class TNodeData, class TEdgeData>
1470 void TNodeEdgeNet<TNodeData, TEdgeData>::SetEDat(const int& EId, const TEdgeData& EdgeDat) {
1471  IAssertR(IsEdge(EId), TStr::Fmt("EdgeId %d does not exist.", EId).CStr());
1472  GetEI(EId).GetDat() = EdgeDat;
1473 }
1474 
1475 template <class TNodeData, class TEdgeData>
1476 void TNodeEdgeNet<TNodeData, TEdgeData>::SetAllEDat(const TEdgeData& EdgeDat) {
1477  for (TEdgeI EI = BegEI(); EI < EndEI(); EI++) {
1478  EI() = EdgeDat;
1479  }
1480 }
1481 
1482 
1483 template <class TNodeData, class TEdgeData>
1485  NIdV.Gen(GetNodes(), 0);
1486  for (int N=NodeH.FFirstKeyId(); NodeH.FNextKeyId(N);) {
1487  NIdV.Add(NodeH.GetKey(N));
1488  }
1489 }
1490 
1491 template <class TNodeData, class TEdgeData>
1493  EIdV.Gen(GetEdges(), 0);
1494  for (int E=EdgeH.FFirstKeyId(); EdgeH.FNextKeyId(E);) {
1495  EIdV.Add(EdgeH.GetKey(E));
1496  }
1497 }
1498 
1499 template <class TNodeData, class TEdgeData>
1500 void TNodeEdgeNet<TNodeData, TEdgeData>::Defrag(const bool& OnlyNodeLinks) {
1501  for (int kid = NodeH.FFirstKeyId(); NodeH.FNextKeyId(kid);) {
1502  TNode& Node = NodeH[kid];
1503  Node.InEIdV.Pack(); Node.OutEIdV.Pack();
1504  }
1505  if (! OnlyNodeLinks && ! NodeH.IsKeyIdEqKeyN()) { NodeH.Defrag(); }
1506  if (! OnlyNodeLinks && ! EdgeH.IsKeyIdEqKeyN()) { EdgeH.Defrag(); }
1507 }
1508 
1509 template <class TNodeData, class TEdgeData>
1510 bool TNodeEdgeNet<TNodeData, TEdgeData>::IsOk(const bool& ThrowExcept) const {
1511  bool RetVal = true;
1512  for (int N = NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
1513  const TNode& Node = NodeH[N];
1514  if (! Node.OutEIdV.IsSorted()) {
1515  const TStr Msg = TStr::Fmt("Out-edge list of node %d is not sorted.", Node.GetId());
1516  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
1517  }
1518  if (! Node.InEIdV.IsSorted()) {
1519  const TStr Msg = TStr::Fmt("In-edge list of node %d is not sorted.", Node.GetId());
1520  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
1521  }
1522  // check out-edge ids
1523  int prevEId = -1;
1524  for (int e = 0; e < Node.GetOutDeg(); e++) {
1525  if (! IsEdge(Node.GetOutEId(e))) {
1526  const TStr Msg = TStr::Fmt("Out-edge id %d of node %d does not exist.", Node.GetOutEId(e), Node.GetId());
1527  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
1528  }
1529  if (e > 0 && prevEId == Node.GetOutEId(e)) {
1530  const TStr Msg = TStr::Fmt("Node %d has duplidate out-edge id %d.", Node.GetId(), Node.GetOutEId(e));
1531  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
1532  }
1533  prevEId = Node.GetOutEId(e);
1534  }
1535  // check in-edge ids
1536  prevEId = -1;
1537  for (int e = 0; e < Node.GetInDeg(); e++) {
1538  if (! IsEdge(Node.GetInEId(e))) {
1539  const TStr Msg = TStr::Fmt("Out-edge id %d of node %d does not exist.", Node.GetInEId(e), Node.GetId());
1540  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
1541  }
1542  if (e > 0 && prevEId == Node.GetInEId(e)) {
1543  const TStr Msg = TStr::Fmt("Node %d has duplidate out-edge id %d.", Node.GetId(), Node.GetInEId(e));
1544  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
1545  }
1546  prevEId = Node.GetInEId(e);
1547  }
1548  }
1549  for (int E = EdgeH.FFirstKeyId(); EdgeH.FNextKeyId(E); ) {
1550  const TEdge& Edge = EdgeH[E];
1551  if (! IsNode(Edge.GetSrcNId())) {
1552  const TStr Msg = TStr::Fmt("Edge %d source node %d does not exist.", Edge.GetId(), Edge.GetSrcNId());
1553  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
1554  }
1555  if (! IsNode(Edge.GetDstNId())) {
1556  const TStr Msg = TStr::Fmt("Edge %d destination node %d does not exist.", Edge.GetId(), Edge.GetDstNId());
1557  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
1558  }
1559  }
1560  return RetVal;
1561 }
1562 
1564 // Common Node-Edge Network Types
1569 
1570 class TNEANet;
1572 typedef TPt<TNEANet> PNEANet;
1573 
1574 //#//////////////////////////////////////////////
1576 
1591 class TNEANet {
1592 public:
1593  typedef TNEANet TNet;
1595 public:
1596  class TNode {
1597  private:
1599  TIntV InEIdV, OutEIdV;
1600  public:
1601  TNode() : Id(-1), InEIdV(), OutEIdV() { }
1602  TNode(const int& NId) : Id(NId), InEIdV(), OutEIdV() { }
1603  TNode(const TNode& Node) : Id(Node.Id), InEIdV(Node.InEIdV), OutEIdV(Node.OutEIdV) { }
1604  TNode(TSIn& SIn) : Id(SIn), InEIdV(SIn), OutEIdV(SIn) { }
1605  void Save(TSOut& SOut) const { Id.Save(SOut); InEIdV.Save(SOut); OutEIdV.Save(SOut); }
1606  int GetId() const { return Id; }
1607  int GetDeg() const { return GetInDeg() + GetOutDeg(); }
1608  int GetInDeg() const { return InEIdV.Len(); }
1609  int GetOutDeg() const { return OutEIdV.Len(); }
1610  int GetInEId(const int& EdgeN) const { return InEIdV[EdgeN]; }
1611  int GetOutEId(const int& EdgeN) const { return OutEIdV[EdgeN]; }
1612  int GetNbrEId(const int& EdgeN) const { return EdgeN<GetOutDeg()?GetOutEId(EdgeN):GetInEId(EdgeN-GetOutDeg()); }
1613  bool IsInEId(const int& EId) const { return InEIdV.SearchBin(EId) != -1; }
1614  bool IsOutEId(const int& EId) const { return OutEIdV.SearchBin(EId) != -1; }
1615  friend class TNEANet;
1616  };
1617  class TEdge {
1618  private:
1619  TInt Id, SrcNId, DstNId;
1620  public:
1621  TEdge() : Id(-1), SrcNId(-1), DstNId(-1) { }
1622  TEdge(const int& EId, const int& SourceNId, const int& DestNId) : Id(EId), SrcNId(SourceNId), DstNId(DestNId) { }
1623  TEdge(const TEdge& Edge) : Id(Edge.Id), SrcNId(Edge.SrcNId), DstNId(Edge.DstNId) { }
1624  TEdge(TSIn& SIn) : Id(SIn), SrcNId(SIn), DstNId(SIn) { }
1625  void Save(TSOut& SOut) const { Id.Save(SOut); SrcNId.Save(SOut); DstNId.Save(SOut); }
1626  int GetId() const { return Id; }
1627  int GetSrcNId() const { return SrcNId; }
1628  int GetDstNId() const { return DstNId; }
1629  friend class TNEANet;
1630  };
1632  class TNodeI {
1633  protected:
1636  const TNEANet *Graph;
1637  public:
1638  TNodeI() : NodeHI(), Graph(NULL) { }
1639  TNodeI(const THashIter& NodeHIter, const TNEANet* GraphPt) : NodeHI(NodeHIter), Graph(GraphPt) { }
1640  TNodeI(const TNodeI& NodeI) : NodeHI(NodeI.NodeHI), Graph(NodeI.Graph) { }
1641  TNodeI& operator = (const TNodeI& NodeI) { NodeHI = NodeI.NodeHI; Graph=NodeI.Graph; return *this; }
1643  TNodeI& operator++ (int) { NodeHI++; return *this; }
1644  bool operator < (const TNodeI& NodeI) const { return NodeHI < NodeI.NodeHI; }
1645  bool operator == (const TNodeI& NodeI) const { return NodeHI == NodeI.NodeHI; }
1647  int GetId() const { return NodeHI.GetDat().GetId(); }
1649  int GetDeg() const { return NodeHI.GetDat().GetDeg(); }
1651  int GetInDeg() const { return NodeHI.GetDat().GetInDeg(); }
1653  int GetOutDeg() const { return NodeHI.GetDat().GetOutDeg(); }
1655 
1657  int GetInNId(const int& EdgeN) const { return Graph->GetEdge(NodeHI.GetDat().GetInEId(EdgeN)).GetSrcNId(); }
1659 
1661  int GetOutNId(const int& EdgeN) const { return Graph->GetEdge(NodeHI.GetDat().GetOutEId(EdgeN)).GetDstNId(); }
1663 
1665  int GetNbrNId(const int& EdgeN) const { const TEdge& E = Graph->GetEdge(NodeHI.GetDat().GetNbrEId(EdgeN)); return GetId()==E.GetSrcNId() ? E.GetDstNId():E.GetSrcNId(); }
1667  bool IsInNId(const int& NId) const;
1669  bool IsOutNId(const int& NId) const;
1671  bool IsNbrNId(const int& NId) const { return IsOutNId(NId) || IsInNId(NId); }
1673  int GetInEId(const int& EdgeN) const { return NodeHI.GetDat().GetInEId(EdgeN); }
1675  int GetOutEId(const int& EdgeN) const { return NodeHI.GetDat().GetOutEId(EdgeN); }
1677  int GetNbrEId(const int& EdgeN) const { return NodeHI.GetDat().GetNbrEId(EdgeN); }
1679  bool IsInEId(const int& EId) const { return NodeHI.GetDat().IsInEId(EId); }
1681  bool IsOutEId(const int& EId) const { return NodeHI.GetDat().IsOutEId(EId); }
1683  bool IsNbrEId(const int& EId) const { return IsInEId(EId) || IsOutEId(EId); }
1685  void GetAttrNames(TStrV& Names) const { Graph->AttrNameNI(GetId(), Names); }
1687  void GetAttrVal(TStrV& Val) const { Graph->AttrValueNI(GetId(), Val); }
1689  void GetIntAttrNames(TStrV& Names) const { Graph->IntAttrNameNI(GetId(), Names); }
1691  void GetIntAttrVal(TIntV& Val) const { Graph->IntAttrValueNI(GetId(), Val); }
1693  void GetIntVAttrNames(TStrV& Names) const { Graph->IntVAttrNameNI(GetId(), Names); }
1695  void GetIntVAttrVal(TVec<TIntV>& Val) const { Graph->IntVAttrValueNI(GetId(), Val); }
1697  void GetStrAttrNames(TStrV& Names) const { Graph->StrAttrNameNI(GetId(), Names); }
1699  void GetStrAttrVal(TStrV& Val) const { Graph->StrAttrValueNI(GetId(), Val); }
1701  void GetFltAttrNames(TStrV& Names) const { Graph->FltAttrNameNI(GetId(), Names); }
1703  void GetFltAttrVal(TFltV& Val) const { Graph->FltAttrValueNI(GetId(), Val); }
1704  friend class TNEANet;
1705  };
1707  class TEdgeI {
1708  private:
1711  const TNEANet *Graph;
1712  public:
1713  TEdgeI() : EdgeHI(), Graph(NULL) { }
1714  TEdgeI(const THashIter& EdgeHIter, const TNEANet *GraphPt) : EdgeHI(EdgeHIter), Graph(GraphPt) { }
1715  TEdgeI(const TEdgeI& EdgeI) : EdgeHI(EdgeI.EdgeHI), Graph(EdgeI.Graph) { }
1716  TEdgeI& operator = (const TEdgeI& EdgeI) { if (this!=&EdgeI) { EdgeHI=EdgeI.EdgeHI; Graph=EdgeI.Graph; } return *this; }
1718  TEdgeI& operator++ (int) { EdgeHI++; return *this; }
1719  bool operator < (const TEdgeI& EdgeI) const { return EdgeHI < EdgeI.EdgeHI; }
1720  bool operator == (const TEdgeI& EdgeI) const { return EdgeHI == EdgeI.EdgeHI; }
1722  int GetId() const { return EdgeHI.GetDat().GetId(); }
1724  int GetSrcNId() const { return EdgeHI.GetDat().GetSrcNId(); }
1726  int GetDstNId() const { return EdgeHI.GetDat().GetDstNId(); }
1728  void GetAttrNames(TStrV& Names) const { Graph->AttrNameEI(GetId(), Names); }
1730  void GetAttrVal(TStrV& Val) const { Graph->AttrValueEI(GetId(), Val); }
1732  void GetIntAttrNames(TStrV& Names) const { Graph->IntAttrNameEI(GetId(), Names); }
1734  void GetIntAttrVal(TIntV& Val) const { Graph->IntAttrValueEI(GetId(), Val); }
1736  void GetIntVAttrNames(TStrV& Names) const { Graph->IntVAttrNameEI(GetId(), Names); }
1738  void GetIntVAttrVal(TVec<TIntV>& Val) const { Graph->IntVAttrValueEI(GetId(), Val); }
1740  void GetStrAttrNames(TStrV& Names) const { Graph->StrAttrNameEI(GetId(), Names); }
1742  void GetStrAttrVal(TStrV& Val) const { Graph->StrAttrValueEI(GetId(), Val); }
1744  void GetFltAttrNames(TStrV& Names) const { Graph->FltAttrNameEI(GetId(), Names); }
1746  void GetFltAttrVal(TFltV& Val) const { Graph->FltAttrValueEI(GetId(), Val); }
1747  friend class TNEANet;
1748  };
1749 
1751  class TAIntI {
1752  private:
1755  bool isNode;
1757  const TNEANet *Graph;
1758  public:
1759  TAIntI() : HI(), attr(), Graph(NULL) { }
1760  TAIntI(const TIntVecIter& HIter, TStr attribute, bool isEdgeIter, const TNEANet* GraphPt) : HI(HIter), attr(), Graph(GraphPt) { isNode = !isEdgeIter; attr = attribute; }
1761  TAIntI(const TAIntI& I) : HI(I.HI), attr(I.attr), Graph(I.Graph) { isNode = I.isNode; }
1762  TAIntI& operator = (const TAIntI& I) { HI = I.HI; Graph=I.Graph; isNode = I.isNode; attr = I.attr; return *this; }
1763  bool operator < (const TAIntI& I) const { return HI < I.HI; }
1764  bool operator == (const TAIntI& I) const { return HI == I.HI; }
1766  TInt GetDat() const { return HI[0]; }
1768  bool IsDeleted() const { return isNode ? GetDat() == Graph->GetIntAttrDefaultN(attr) : GetDat() == Graph->GetIntAttrDefaultE(attr); };
1769  TAIntI& operator++(int) { HI++; return *this; }
1770  friend class TNEANet;
1771  };
1772 
1773  class TAIntVI {
1774  private:
1777  bool isNode;
1779  const TNEANet *Graph;
1780  public:
1781  TAIntVI() : HI(), attr(), Graph(NULL) { }
1782  TAIntVI(const TIntVVecIter& HIter, TStr attribute, bool isEdgeIter, const TNEANet* GraphPt) : HI(HIter), attr(), Graph(GraphPt) { isNode = !isEdgeIter; attr = attribute; }
1783  TAIntVI(const TAIntVI& I) : HI(I.HI), attr(I.attr), Graph(I.Graph) { isNode = I.isNode; }
1784  TAIntVI& operator = (const TAIntVI& I) { HI = I.HI; Graph=I.Graph; isNode = I.isNode; attr = I.attr; return *this; }
1785  bool operator < (const TAIntVI& I) const { return HI < I.HI; }
1786  bool operator == (const TAIntVI& I) const { return HI == I.HI; }
1788  TIntV GetDat() const { return HI[0]; }
1789  TAIntVI& operator++(int) { HI++; return *this; }
1790  friend class TNEANet;
1791  };
1792 
1794  class TAStrI {
1795  private:
1798  bool isNode;
1800  const TNEANet *Graph;
1801  public:
1802  TAStrI() : HI(), attr(), Graph(NULL) { }
1803  TAStrI(const TStrVecIter& HIter, TStr attribute, bool isEdgeIter, const TNEANet* GraphPt) : HI(HIter), attr(), Graph(GraphPt) { isNode = !isEdgeIter; attr = attribute; }
1804  TAStrI(const TAStrI& I) : HI(I.HI), attr(I.attr), Graph(I.Graph) { isNode = I.isNode; }
1805  TAStrI& operator = (const TAStrI& I) { HI = I.HI; Graph=I.Graph; isNode = I.isNode; attr = I.attr; return *this; }
1806  bool operator < (const TAStrI& I) const { return HI < I.HI; }
1807  bool operator == (const TAStrI& I) const { return HI == I.HI; }
1809  TStr GetDat() const { return HI[0]; }
1811  bool IsDeleted() const { return isNode ? GetDat() == Graph->GetStrAttrDefaultN(attr) : GetDat() == Graph->GetStrAttrDefaultE(attr); };
1812  TAStrI& operator++(int) { HI++; return *this; }
1813  friend class TNEANet;
1814  };
1815 
1817  class TAFltI {
1818  private:
1821  bool isNode;
1823  const TNEANet *Graph;
1824  public:
1825  TAFltI() : HI(), attr(), Graph(NULL) { }
1826  TAFltI(const TFltVecIter& HIter, TStr attribute, bool isEdgeIter, const TNEANet* GraphPt) : HI(HIter), attr(), Graph(GraphPt) { isNode = !isEdgeIter; attr = attribute; }
1827  TAFltI(const TAFltI& I) : HI(I.HI), attr(I.attr), Graph(I.Graph) { isNode = I.isNode; }
1828  TAFltI& operator = (const TAFltI& I) { HI = I.HI; Graph=I.Graph; isNode = I.isNode; attr = I.attr; return *this; }
1829  bool operator < (const TAFltI& I) const { return HI < I.HI; }
1830  bool operator == (const TAFltI& I) const { return HI == I.HI; }
1832  TFlt GetDat() const { return HI[0]; }
1834  bool IsDeleted() const { return isNode ? GetDat() == Graph->GetFltAttrDefaultN(attr) : GetDat() == Graph->GetFltAttrDefaultE(attr); };
1835  TAFltI& operator++(int) { HI++; return *this; }
1836  friend class TNEANet;
1837  };
1838 
1839 protected:
1840  TNode& GetNode(const int& NId) { return NodeH.GetDat(NId); }
1841  const TNode& GetNode(const int& NId) const { return NodeH.GetDat(NId); }
1842  TEdge& GetEdge(const int& EId) { return EdgeH.GetDat(EId); }
1843  const TEdge& GetEdge(const int& EId) const { return EdgeH.GetDat(EId); }
1844 
1845 protected:
1847  TInt GetIntAttrDefaultN(const TStr& attribute) const { return IntDefaultsN.IsKey(attribute) ? IntDefaultsN.GetDat(attribute) : (TInt) TInt::Mn; }
1849  TStr GetStrAttrDefaultN(const TStr& attribute) const { return StrDefaultsN.IsKey(attribute) ? StrDefaultsN.GetDat(attribute) : (TStr) TStr::GetNullStr(); }
1851  TFlt GetFltAttrDefaultN(const TStr& attribute) const { return FltDefaultsN.IsKey(attribute) ? FltDefaultsN.GetDat(attribute) : (TFlt) TFlt::Mn; }
1853  TInt GetIntAttrDefaultE(const TStr& attribute) const { return IntDefaultsE.IsKey(attribute) ? IntDefaultsE.GetDat(attribute) : (TInt) TInt::Mn; }
1855  TStr GetStrAttrDefaultE(const TStr& attribute) const { return StrDefaultsE.IsKey(attribute) ? StrDefaultsE.GetDat(attribute) : (TStr) TStr::GetNullStr(); }
1857  TFlt GetFltAttrDefaultE(const TStr& attribute) const { return FltDefaultsE.IsKey(attribute) ? FltDefaultsE.GetDat(attribute) : (TFlt) TFlt::Mn; }
1858 public:
1860 protected:
1866 
1875 
1878 
1879 public:
1880  TNEANet() : CRef(), MxNId(0), MxEId(0), NodeH(), EdgeH(),
1886  explicit TNEANet(const int& Nodes, const int& Edges) : CRef(),
1891  { Reserve(Nodes, Edges); }
1892  TNEANet(const TNEANet& Graph) : MxNId(Graph.MxNId), MxEId(Graph.MxEId),
1893  NodeH(Graph.NodeH), EdgeH(Graph.EdgeH), KeyToIndexTypeN(), KeyToIndexTypeE(),
1898  TNEANet(TSIn& SIn) : MxNId(SIn), MxEId(SIn), NodeH(SIn), EdgeH(SIn),
1900  StrDefaultsN(SIn), StrDefaultsE(SIn), FltDefaultsN(SIn), FltDefaultsE(SIn),
1902  VecOfFltVecsN(SIn), VecOfFltVecsE(SIn), VecOfIntVecVecsN(SIn), VecOfIntVecVecsE(SIn), SAttrN(SIn), SAttrE(SIn) { }
1903  protected:
1904  TNEANet(const TNEANet& Graph, bool modeSubGraph) : MxNId(Graph.MxNId), MxEId(Graph.MxEId),
1910  TNEANet(bool copyAll, const TNEANet& Graph) : MxNId(Graph.MxNId), MxEId(Graph.MxEId),
1916  public:
1918  void Save(TSOut& SOut) const {
1919  MxNId.Save(SOut); MxEId.Save(SOut); NodeH.Save(SOut); EdgeH.Save(SOut);
1921  IntDefaultsN.Save(SOut); IntDefaultsE.Save(SOut);
1922  StrDefaultsN.Save(SOut); StrDefaultsE.Save(SOut);
1923  FltDefaultsN.Save(SOut); FltDefaultsE.Save(SOut);
1924  VecOfIntVecsN.Save(SOut); VecOfIntVecsE.Save(SOut);
1925  VecOfStrVecsN.Save(SOut); VecOfStrVecsE.Save(SOut);
1926  VecOfFltVecsN.Save(SOut); VecOfFltVecsE.Save(SOut);
1927  VecOfIntVecVecsN.Save(SOut); VecOfIntVecVecsE.Save(SOut);
1928  SAttrN.Save(SOut); SAttrE.Save(SOut); }
1930  void Save_V1(TSOut& SOut) const {
1931  MxNId.Save(SOut); MxEId.Save(SOut); NodeH.Save(SOut); EdgeH.Save(SOut);
1933  IntDefaultsN.Save(SOut); IntDefaultsE.Save(SOut);
1934  StrDefaultsN.Save(SOut); StrDefaultsE.Save(SOut);
1935  FltDefaultsN.Save(SOut); FltDefaultsE.Save(SOut);
1936  VecOfIntVecsN.Save(SOut); VecOfIntVecsE.Save(SOut);
1937  VecOfStrVecsN.Save(SOut); VecOfStrVecsE.Save(SOut);
1938  VecOfFltVecsN.Save(SOut); VecOfFltVecsE.Save(SOut); }
1940  static PNEANet New() { return PNEANet(new TNEANet()); }
1942 
1944  static PNEANet New(const int& Nodes, const int& Edges) { return PNEANet(new TNEANet(Nodes, Edges)); }
1946  static PNEANet Load(TSIn& SIn) { return PNEANet(new TNEANet(SIn)); }
1948  static PNEANet Load_V1(TSIn& SIn) {
1949  PNEANet Graph = PNEANet(new TNEANet());
1950  Graph->MxNId.Load(SIn); Graph->MxEId.Load(SIn);
1951  Graph->NodeH.Load(SIn); Graph->EdgeH.Load(SIn);
1952  Graph->KeyToIndexTypeN.Load(SIn); Graph->KeyToIndexTypeE.Load(SIn);
1953  Graph->IntDefaultsN.Load(SIn); Graph->IntDefaultsE.Load(SIn);
1954  Graph->StrDefaultsN.Load(SIn); Graph->StrDefaultsE.Load(SIn);
1955  Graph->FltDefaultsN.Load(SIn); Graph->FltDefaultsE.Load(SIn);
1956  Graph->VecOfIntVecsN.Load(SIn); Graph->VecOfIntVecsE.Load(SIn);
1957  Graph->VecOfStrVecsN.Load(SIn); Graph->VecOfStrVecsE.Load(SIn);
1958  Graph->VecOfFltVecsN.Load(SIn); Graph->VecOfFltVecsE.Load(SIn);
1959  return Graph;
1960  }
1962  bool HasFlag(const TGraphFlag& Flag) const;
1963 
1964  TNEANet& operator = (const TNEANet& Graph) { if (this!=&Graph) {
1965  MxNId=Graph.MxNId; MxEId=Graph.MxEId; NodeH=Graph.NodeH; EdgeH=Graph.EdgeH; }
1966  return *this; }
1967 
1969  int GetNodes() const { return NodeH.Len(); }
1971 
1975  int AddNode(int NId = -1);
1977  int AddNode(const TNodeI& NodeI) { return AddNode(NodeI.GetId()); }
1979 
1981  virtual void DelNode(const int& NId);
1983  void DelNode(const TNode& NodeI) { DelNode(NodeI.GetId()); }
1985  bool IsNode(const int& NId) const { return NodeH.IsKey(NId); }
1987  TNodeI BegNI() const { return TNodeI(NodeH.BegI(), this); }
1989  TNodeI EndNI() const { return TNodeI(NodeH.EndI(), this); }
1991  TNodeI GetNI(const int& NId) const { return TNodeI(NodeH.GetI(NId), this); }
1993  TAIntI BegNAIntI(const TStr& attr) const {
1994  return TAIntI(VecOfIntVecsN[KeyToIndexTypeN.GetDat(attr).Val2].BegI(), attr, false, this); }
1996  TAIntI EndNAIntI(const TStr& attr) const {
1997  return TAIntI(VecOfIntVecsN[KeyToIndexTypeN.GetDat(attr).Val2].EndI(), attr, false, this); }
1999  TAIntI GetNAIntI(const TStr& attr, const int& NId) const {
2000  return TAIntI(VecOfIntVecsN[KeyToIndexTypeN.GetDat(attr).Val2].GetI(NodeH.GetKeyId(NId)), attr, false, this); }
2001 
2003  TAIntVI BegNAIntVI(const TStr& attr) const {
2004  return TAIntVI(VecOfIntVecVecsN[KeyToIndexTypeN.GetDat(attr).Val2].BegI(), attr, false, this); }
2006  TAIntVI EndNAIntVI(const TStr& attr) const {
2007  return TAIntVI(VecOfIntVecVecsN[KeyToIndexTypeN.GetDat(attr).Val2].EndI(), attr, false, this); }
2009  TAIntVI GetNAIntVI(const TStr& attr, const int& NId) const {
2010  return TAIntVI(VecOfIntVecVecsN[KeyToIndexTypeN.GetDat(attr).Val2].GetI(NodeH.GetKeyId(NId)), attr, false, this); }
2011 
2012 
2014  TAStrI BegNAStrI(const TStr& attr) const {
2015 
2016  return TAStrI(VecOfStrVecsN[KeyToIndexTypeN.GetDat(attr).Val2].BegI(), attr, false, this); }
2018  TAStrI EndNAStrI(const TStr& attr) const {
2019  return TAStrI(VecOfStrVecsN[KeyToIndexTypeN.GetDat(attr).Val2].EndI(), attr, false, this); }
2021  TAStrI GetNAStrI(const TStr& attr, const int& NId) const {
2022  return TAStrI(VecOfStrVecsN[KeyToIndexTypeN.GetDat(attr).Val2].GetI(NodeH.GetKeyId(NId)), attr, false, this); }
2024  TAFltI BegNAFltI(const TStr& attr) const {
2025  return TAFltI(VecOfFltVecsN[KeyToIndexTypeN.GetDat(attr).Val2].BegI(), attr, false, this); }
2027  TAFltI EndNAFltI(const TStr& attr) const {
2028  return TAFltI(VecOfFltVecsN[KeyToIndexTypeN.GetDat(attr).Val2].EndI(), attr, false, this); }
2030  TAFltI GetNAFltI(const TStr& attr, const int& NId) const {
2031  return TAFltI(VecOfFltVecsN[KeyToIndexTypeN.GetDat(attr).Val2].GetI(NodeH.GetKeyId(NId)), attr, false, this); }
2032 
2034  void AttrNameNI(const TInt& NId, TStrV& Names) const {
2035  AttrNameNI(NId, KeyToIndexTypeN.BegI(), Names);}
2036  void AttrNameNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TStrV& Names) const;
2038  void AttrValueNI(const TInt& NId, TStrV& Values) const {
2039  AttrValueNI(NId, KeyToIndexTypeN.BegI(), Values);}
2040  void AttrValueNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TStrV& Values) const;
2041 
2043  void IntAttrNameNI(const TInt& NId, TStrV& Names) const {
2044  IntAttrNameNI(NId, KeyToIndexTypeN.BegI(), Names);}
2045  void IntAttrNameNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TStrV& Names) const;
2047  void IntAttrValueNI(const TInt& NId, TIntV& Values) const {
2048  IntAttrValueNI(NId, KeyToIndexTypeN.BegI(), Values);}
2049  void IntAttrValueNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TIntV& Values) const;
2050 
2051 
2053  void IntVAttrNameNI(const TInt& NId, TStrV& Names) const {
2054  IntVAttrNameNI(NId, KeyToIndexTypeN.BegI(), Names);}
2055  void IntVAttrNameNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TStrV& Names) const;
2057  void IntVAttrValueNI(const TInt& NId, TVec<TIntV>& Values) const {
2058  IntVAttrValueNI(NId, KeyToIndexTypeN.BegI(), Values);}
2059  void IntVAttrValueNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TVec<TIntV>& Values) const;
2060 
2061 
2063  void StrAttrNameNI(const TInt& NId, TStrV& Names) const {
2064  StrAttrNameNI(NId, KeyToIndexTypeN.BegI(), Names);}
2065  void StrAttrNameNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TStrV& Names) const;
2067  void StrAttrValueNI(const TInt& NId, TStrV& Values) const {
2068  StrAttrValueNI(NId, KeyToIndexTypeN.BegI(), Values);}
2069  void StrAttrValueNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TStrV& Values) const;
2071  void FltAttrNameNI(const TInt& NId, TStrV& Names) const {
2072  FltAttrNameNI(NId, KeyToIndexTypeN.BegI(), Names);}
2073  void FltAttrNameNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TStrV& Names) const;
2075  void FltAttrValueNI(const TInt& NId, TFltV& Values) const {
2076  FltAttrValueNI(NId, KeyToIndexTypeN.BegI(), Values);}
2077  void FltAttrValueNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TFltV& Values) const;
2078 
2080  void AttrNameEI(const TInt& EId, TStrV& Names) const {
2081  AttrNameEI(EId, KeyToIndexTypeE.BegI(), Names);}
2082  void AttrNameEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TStrV& Names) const;
2084  void AttrValueEI(const TInt& EId, TStrV& Values) const {
2085  AttrValueEI(EId, KeyToIndexTypeE.BegI(), Values);}
2086  void AttrValueEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TStrV& Values) const;
2088  void IntAttrNameEI(const TInt& EId, TStrV& Names) const {
2089  IntAttrNameEI(EId, KeyToIndexTypeE.BegI(), Names);}
2090  void IntAttrNameEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TStrV& Names) const;
2092  void IntAttrValueEI(const TInt& EId, TIntV& Values) const {
2093  IntAttrValueEI(EId, KeyToIndexTypeE.BegI(), Values);}
2094  void IntAttrValueEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TIntV& Values) const;
2095 
2096 
2098  void IntVAttrNameEI(const TInt& EId, TStrV& Names) const {
2099  IntVAttrNameEI(EId, KeyToIndexTypeE.BegI(), Names);}
2100  void IntVAttrNameEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TStrV& Names) const;
2102  void IntVAttrValueEI(const TInt& EId, TVec<TIntV>& Values) const {
2103  IntVAttrValueEI(EId, KeyToIndexTypeE.BegI(), Values);}
2104  void IntVAttrValueEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TVec<TIntV>& Values) const;
2105 
2106 
2108  void StrAttrNameEI(const TInt& EId, TStrV& Names) const {
2109  StrAttrNameEI(EId, KeyToIndexTypeE.BegI(), Names);}
2110  void StrAttrNameEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TStrV& Names) const;
2112  void StrAttrValueEI(const TInt& EId, TStrV& Values) const {
2113  StrAttrValueEI(EId, KeyToIndexTypeE.BegI(), Values);}
2114  void StrAttrValueEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TStrV& Values) const;
2116  void FltAttrNameEI(const TInt& EId, TStrV& Names) const {
2117  FltAttrNameEI(EId, KeyToIndexTypeE.BegI(), Names);}
2118  void FltAttrNameEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TStrV& Names) const;
2120  void FltAttrValueEI(const TInt& EId, TFltV& Values) const {
2121  FltAttrValueEI(EId, KeyToIndexTypeE.BegI(), Values);}
2122  void FltAttrValueEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TFltV& Values) const;
2123 
2125  TAIntI BegEAIntI(const TStr& attr) const {
2126  return TAIntI(VecOfIntVecsE[KeyToIndexTypeE.GetDat(attr).Val2].BegI(), attr, true, this);
2127  }
2129  TAIntI EndEAIntI(const TStr& attr) const {
2130  return TAIntI(VecOfIntVecsE[KeyToIndexTypeE.GetDat(attr).Val2].EndI(), attr, true, this);
2131  }
2133  TAIntI GetEAIntI(const TStr& attr, const int& EId) const {
2134  return TAIntI(VecOfIntVecsE[KeyToIndexTypeE.GetDat(attr).Val2].GetI(EdgeH.GetKeyId(EId)), attr, true, this);
2135  }
2136 
2138  TAIntVI BegEAIntVI(const TStr& attr) const {
2139  return TAIntVI(VecOfIntVecVecsE[KeyToIndexTypeE.GetDat(attr).Val2].BegI(), attr, true, this);
2140  }
2142  TAIntVI EndEAIntVI(const TStr& attr) const {
2143  return TAIntVI(VecOfIntVecVecsE[KeyToIndexTypeE.GetDat(attr).Val2].EndI(), attr, true, this);
2144  }
2146  TAIntVI GetEAIntVI(const TStr& attr, const int& EId) const {
2147  return TAIntVI(VecOfIntVecVecsE[KeyToIndexTypeE.GetDat(attr).Val2].GetI(EdgeH.GetKeyId(EId)), attr, true, this);
2148  }
2149 
2151  TAStrI BegEAStrI(const TStr& attr) const {
2152  return TAStrI(VecOfStrVecsE[KeyToIndexTypeE.GetDat(attr).Val2].BegI(), attr, true, this); }
2154  TAStrI EndEAStrI(const TStr& attr) const {
2155  return TAStrI(VecOfStrVecsE[KeyToIndexTypeE.GetDat(attr).Val2].EndI(), attr, true, this);
2156  }
2158  TAStrI GetEAStrI(const TStr& attr, const int& EId) const {
2159  return TAStrI(VecOfStrVecsE[KeyToIndexTypeE.GetDat(attr).Val2].GetI(EdgeH.GetKeyId(EId)), attr, true, this);
2160  }
2162  TAFltI BegEAFltI(const TStr& attr) const {
2163  return TAFltI(VecOfFltVecsE[KeyToIndexTypeE.GetDat(attr).Val2].BegI(), attr, true, this);
2164  }
2166  TAFltI EndEAFltI(const TStr& attr) const {
2167  return TAFltI(VecOfFltVecsE[KeyToIndexTypeE.GetDat(attr).Val2].EndI(), attr, true, this);
2168  }
2170  TAFltI GetEAFltI(const TStr& attr, const int& EId) const {
2171  return TAFltI(VecOfFltVecsE[KeyToIndexTypeE.GetDat(attr).Val2].GetI(EdgeH.GetKeyId(EId)), attr, true, this);
2172  }
2174  int GetMxNId() const { return MxNId; }
2176  int GetMxEId() const { return MxEId; }
2177 
2179  int GetEdges() const { return EdgeH.Len(); }
2181 
2186  int AddEdge(const int& SrcNId, const int& DstNId, int EId = -1);
2188  int AddEdge(const TEdgeI& EdgeI) { return AddEdge(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), EdgeI.GetId()); }
2190  void DelEdge(const int& EId);
2192 
2196  void DelEdge(const int& SrcNId, const int& DstNId, const bool& IsDir = true);
2198  bool IsEdge(const int& EId) const { return EdgeH.IsKey(EId); }
2200  bool IsEdge(const int& SrcNId, const int& DstNId, const bool& IsDir = true) const { int EId; return IsEdge(SrcNId, DstNId, EId, IsDir); }
2202  bool IsEdge(const int& SrcNId, const int& DstNId, int& EId, const bool& IsDir = true) const;
2204  int GetEId(const int& SrcNId, const int& DstNId) const { int EId; return IsEdge(SrcNId, DstNId, EId)?EId:-1; }
2206  TEdgeI BegEI() const { return TEdgeI(EdgeH.BegI(), this); }
2208  TEdgeI EndEI() const { return TEdgeI(EdgeH.EndI(), this); }
2210  TEdgeI GetEI(const int& EId) const { return TEdgeI(EdgeH.GetI(EId), this); }
2212  TEdgeI GetEI(const int& SrcNId, const int& DstNId) const { return GetEI(GetEId(SrcNId, DstNId)); }
2213 
2215  int GetRndNId(TRnd& Rnd=TInt::Rnd) { return NodeH.GetKey(NodeH.GetRndKeyId(Rnd, 0.8)); }
2217  TNodeI GetRndNI(TRnd& Rnd=TInt::Rnd) { return GetNI(GetRndNId(Rnd)); }
2219  int GetRndEId(TRnd& Rnd=TInt::Rnd) { return EdgeH.GetKey(EdgeH.GetRndKeyId(Rnd, 0.8)); }
2221  TEdgeI GetRndEI(TRnd& Rnd=TInt::Rnd) { return GetEI(GetRndEId(Rnd)); }
2223  void GetNIdV(TIntV& NIdV) const;
2225  void GetEIdV(TIntV& EIdV) const;
2226 
2228  bool Empty() const { return GetNodes()==0; }
2230  void Clr() { MxNId=0; MxEId=0; NodeH.Clr(); EdgeH.Clr();
2234  VecOfFltVecsN.Clr(); VecOfFltVecsE.Clr(); VecOfIntVecVecsN.Clr(); VecOfIntVecVecsE.Clr();
2235  SAttrN.Clr(); SAttrE.Clr();}
2237  void Reserve(const int& Nodes, const int& Edges) {
2238  if (Nodes>0) { NodeH.Gen(Nodes/2); } if (Edges>0) { EdgeH.Gen(Edges/2); } }
2240 
2245  void Defrag(const bool& OnlyNodeLinks=false);
2247 
2250  bool IsOk(const bool& ThrowExcept=true) const;
2252  void Dump(FILE *OutF=stdout) const;
2253 
2255 
2257  int AddIntAttrDatN(const TNodeI& NodeI, const TInt& value, const TStr& attr) { return AddIntAttrDatN(NodeI.GetId(), value, attr); }
2258  int AddIntAttrDatN(const int& NId, const TInt& value, const TStr& attr);
2260 
2262  int AddStrAttrDatN(const TNodeI& NodeI, const TStr& value, const TStr& attr) { return AddStrAttrDatN(NodeI.GetId(), value, attr); }
2263  int AddStrAttrDatN(const int& NId, const TStr& value, const TStr& attr);
2265 
2267  int AddFltAttrDatN(const TNodeI& NodeI, const TFlt& value, const TStr& attr) { return AddFltAttrDatN(NodeI.GetId(), value, attr); }
2268  int AddFltAttrDatN(const int& NId, const TFlt& value, const TStr& attr);
2270 
2272  int AddIntVAttrDatN(const TNodeI& NodeI, const TIntV& value, const TStr& attr) { return AddIntVAttrDatN(NodeI.GetId(), value, attr); }
2273  int AddIntVAttrDatN(const int& NId, const TIntV& value, const TStr& attr);
2275  int AppendIntVAttrDatN(const TNodeI& NodeI, const TInt& value, const TStr& attr) { return AppendIntVAttrDatN(NodeI.GetId(), value, attr); }
2276  int AppendIntVAttrDatN(const int& NId, const TInt& value, const TStr& attr);
2278  int DelFromIntVAttrDatN(const TNodeI& NodeI, const TInt& value, const TStr& attr) { return DelFromIntVAttrDatN(NodeI.GetId(), value, attr); }
2279  int DelFromIntVAttrDatN(const int& NId, const TInt& value, const TStr& attr);
2281 
2283  int AddIntAttrDatE(const TEdgeI& EdgeI, const TInt& value, const TStr& attr) { return AddIntAttrDatE(EdgeI.GetId(), value, attr); }
2284  int AddIntAttrDatE(const int& EId, const TInt& value, const TStr& attr);
2286 
2288  int AddStrAttrDatE(const TEdgeI& EdgeI, const TStr& value, const TStr& attr) { return AddStrAttrDatE(EdgeI.GetId(), value, attr); }
2289  int AddStrAttrDatE(const int& EId, const TStr& value, const TStr& attr);
2291 
2293  int AddFltAttrDatE(const TEdgeI& EdgeI, const TFlt& value, const TStr& attr) { return AddFltAttrDatE(EdgeI.GetId(), value, attr); }
2294  int AddFltAttrDatE(const int& EId, const TFlt& value, const TStr& attr);
2296 
2298  int AddIntVAttrDatE(const TEdgeI& EdgeI, const TIntV& value, const TStr& attr) { return AddIntVAttrDatE(EdgeI.GetId(), value, attr); }
2299  int AddIntVAttrDatE(const int& EId, const TIntV& value, const TStr& attr);
2301  int AppendIntVAttrDatE(const TEdgeI& EdgeI, const TInt& value, const TStr& attr) { return AppendIntVAttrDatE(EdgeI.GetId(), value, attr); }
2302  int AppendIntVAttrDatE(const int& EId, const TInt& value, const TStr& attr);
2304  TInt GetIntAttrDatN(const TNodeI& NodeI, const TStr& attr) { return GetIntAttrDatN(NodeI.GetId(), attr); }
2305  TInt GetIntAttrDatN(const int& NId, const TStr& attr);
2306 
2308  TStr GetStrAttrDatN(const TNodeI& NodeI, const TStr& attr) { return GetStrAttrDatN(NodeI.GetId(), attr); }
2309  TStr GetStrAttrDatN(const int& NId, const TStr& attr);
2311  TFlt GetFltAttrDatN(const TNodeI& NodeI, const TStr& attr) { return GetFltAttrDatN(NodeI.GetId(), attr); }
2312  TFlt GetFltAttrDatN(const int& NId, const TStr& attr);
2314  TIntV GetIntVAttrDatN(const TNodeI& NodeI, const TStr& attr) const { return GetIntVAttrDatN(NodeI.GetId(), attr); }
2315  TIntV GetIntVAttrDatN(const int& NId, const TStr& attr) const;
2316 
2318  int GetIntAttrIndN(const TStr& attr);
2320  int GetAttrIndN(const TStr& attr);
2321 
2323  TInt GetIntAttrIndDatN(const TNodeI& NodeI, const int& index) { return GetIntAttrIndDatN(NodeI.GetId(), index); }
2325  TInt GetIntAttrIndDatN(const int& NId, const int& index);
2326 
2328  TStr GetStrAttrIndDatN(const TNodeI& NodeI, const int& index) { return GetStrAttrIndDatN(NodeI.GetId(), index); }
2330  TStr GetStrAttrIndDatN(const int& NId, const int& index);
2331 
2333  TFlt GetFltAttrIndDatN(const TNodeI& NodeI, const int& index) { return GetFltAttrIndDatN(NodeI.GetId(), index); }
2335  TFlt GetFltAttrIndDatN(const int& NId, const int& index);
2336 
2338  TInt GetIntAttrDatE(const TEdgeI& EdgeI, const TStr& attr) { return GetIntAttrDatE(EdgeI.GetId(), attr); }
2339  TInt GetIntAttrDatE(const int& EId, const TStr& attr);
2341  TStr GetStrAttrDatE(const TEdgeI& EdgeI, const TStr& attr) { return GetStrAttrDatE(EdgeI.GetId(), attr); }
2342  TStr GetStrAttrDatE(const int& EId, const TStr& attr);
2344  TFlt GetFltAttrDatE(const TEdgeI& EdgeI, const TStr& attr) { return GetFltAttrDatE(EdgeI.GetId(), attr); }
2345  TFlt GetFltAttrDatE(const int& EId, const TStr& attr);
2347  TIntV GetIntVAttrDatE(const TEdgeI& EdgeI, const TStr& attr) { return GetIntVAttrDatE(EdgeI.GetId(), attr); }
2348  TIntV GetIntVAttrDatE(const int& EId, const TStr& attr);
2349 
2351  int GetIntAttrIndE(const TStr& attr);
2353  int GetAttrIndE(const TStr& attr);
2354 
2356  TInt GetIntAttrIndDatE(const TEdgeI& EdgeI, const int& index) { return GetIntAttrIndDatE(EdgeI.GetId(), index); }
2358  TInt GetIntAttrIndDatE(const int& EId, const int& index);
2359 
2361  TFlt GetFltAttrIndDatE(const TEdgeI& EdgeI, const int& index) { return GetFltAttrIndDatE(EdgeI.GetId(), index); }
2363  TFlt GetFltAttrIndDatE(const int& EId, const int& index);
2364 
2366  TStr GetStrAttrIndDatE(const TEdgeI& EdgeI, const int& index) { return GetStrAttrIndDatE(EdgeI.GetId(), index); }
2368  TStr GetStrAttrIndDatE(const int& EId, const int& index);
2369 
2371  int DelAttrDatN(const TNodeI& NodeI, const TStr& attr) { return DelAttrDatN(NodeI.GetId(), attr); }
2372  int DelAttrDatN(const int& NId, const TStr& attr);
2374  int DelAttrDatE(const TEdgeI& EdgeI, const TStr& attr) { return DelAttrDatE(EdgeI.GetId(), attr); }
2375  int DelAttrDatE(const int& EId, const TStr& attr);
2376 
2378  int AddIntAttrN(const TStr& attr, TInt defaultValue=TInt::Mn);
2380  int AddStrAttrN(const TStr& attr, TStr defaultValue=TStr::GetNullStr());
2382  int AddFltAttrN(const TStr& attr, TFlt defaultValue=TFlt::Mn);
2384  int AddIntVAttrN(const TStr& attr);
2385 
2387  int AddIntAttrE(const TStr& attr, TInt defaultValue=TInt::Mn);
2389  int AddStrAttrE(const TStr& attr, TStr defaultValue=TStr::GetNullStr());
2391  int AddFltAttrE(const TStr& attr, TFlt defaultValue=TFlt::Mn);
2393  int AddIntVAttrE(const TStr& attr);
2394 
2396  int DelAttrN(const TStr& attr);
2398  int DelAttrE(const TStr& attr);
2399 
2401  bool IsAttrDeletedN(const int& NId, const TStr& attr) const;
2403  bool IsIntAttrDeletedN(const int& NId, const TStr& attr) const;
2405  bool IsIntVAttrDeletedN(const int& NId, const TStr& attr) const;
2407  bool IsStrAttrDeletedN(const int& NId, const TStr& attr) const;
2409  bool IsFltAttrDeletedN(const int& NId, const TStr& attr) const;
2410 
2412  bool NodeAttrIsDeleted(const int& NId, const TStrIntPrH::TIter& NodeHI) const;
2414  bool NodeAttrIsIntDeleted(const int& NId, const TStrIntPrH::TIter& NodeHI) const;
2416  bool NodeAttrIsIntVDeleted(const int& NId, const TStrIntPrH::TIter& NodeHI) const;
2418  bool NodeAttrIsStrDeleted(const int& NId, const TStrIntPrH::TIter& NodeHI) const;
2420  bool NodeAttrIsFltDeleted(const int& NId, const TStrIntPrH::TIter& NodeHI) const;
2421 
2423  bool IsAttrDeletedE(const int& EId, const TStr& attr) const;
2425  bool IsIntAttrDeletedE(const int& EId, const TStr& attr) const;
2427  bool IsIntVAttrDeletedE(const int& EId, const TStr& attr) const;
2429  bool IsStrAttrDeletedE(const int& EId, const TStr& attr) const;
2431  bool IsFltAttrDeletedE(const int& EId, const TStr& attr) const;
2432 
2434  bool EdgeAttrIsDeleted(const int& EId, const TStrIntPrH::TIter& EdgeHI) const;
2436  bool EdgeAttrIsIntDeleted(const int& EId, const TStrIntPrH::TIter& EdgeHI) const;
2438  bool EdgeAttrIsIntVDeleted(const int& EId, const TStrIntPrH::TIter& EdgeHI) const;
2440  bool EdgeAttrIsStrDeleted(const int& EId, const TStrIntPrH::TIter& EdgeHI) const;
2442  bool EdgeAttrIsFltDeleted(const int& EId, const TStrIntPrH::TIter& EdgeHI) const;
2443 
2445  TStr GetNodeAttrValue(const int& NId, const TStrIntPrH::TIter& NodeHI) const;
2447  TStr GetEdgeAttrValue(const int& EId, const TStrIntPrH::TIter& EdgeHI) const;
2448 
2450  TFlt GetWeightOutEdges(const TNodeI& NI, const TStr& attr);
2452  bool IsFltAttrE(const TStr& attr);
2454  bool IsIntAttrE(const TStr& attr);
2456  bool IsStrAttrE(const TStr& attr);
2458  TVec<TFlt>& GetFltAttrVecE(const TStr& attr);
2460  int GetFltKeyIdE(const int& EId);
2461 
2463  void GetWeightOutEdgesV(TFltV& OutWeights, const TFltV& AttrVal) ;
2465  void GetAttrNNames(TStrV& IntAttrNames, TStrV& FltAttrNames, TStrV& StrAttrNames) const;
2467  void GetAttrENames(TStrV& IntAttrNames, TStrV& FltAttrNames, TStrV& StrAttrNames) const;
2468 
2469 
2471  int AddSAttrDatN(const TInt& NId, const TStr& AttrName, const TInt& Val);
2473  int AddSAttrDatN(const TInt& NId, const TInt& AttrId, const TInt& Val);
2474 
2476  int AddSAttrDatN(const TNodeI& NodeI, const TStr& AttrName, const TInt& Val) {
2477  return AddSAttrDatN(NodeI.GetId(), AttrName, Val);
2478  }
2480  int AddSAttrDatN(const TNodeI& NodeI, const TInt& AttrId, const TInt& Val) {
2481  return AddSAttrDatN(NodeI.GetId(), AttrId, Val);
2482  }
2483 
2485  int AddSAttrDatN(const TInt& NId, const TStr& AttrName, const TFlt& Val);
2487  int AddSAttrDatN(const TInt& NId, const TInt& AttrId, const TFlt& Val);
2488 
2490  int AddSAttrDatN(const TNodeI& NodeI, const TStr& AttrName, const TFlt& Val) {
2491  return AddSAttrDatN(NodeI.GetId(), AttrName, Val);
2492  }
2494  int AddSAttrDatN(const TNodeI& NodeI, const TInt& AttrId, const TFlt& Val) {
2495  return AddSAttrDatN(NodeI.GetId(), AttrId, Val);
2496  }
2497 
2499  int AddSAttrDatN(const TInt& NId, const TStr& AttrName, const TStr& Val);
2501  int AddSAttrDatN(const TInt& NId, const TInt& AttrId, const TStr& Val);
2502 
2504  int AddSAttrDatN(const TNodeI& NodeI, const TStr& AttrName, const TStr& Val) {
2505  return AddSAttrDatN(NodeI.GetId(), AttrName, Val);
2506  }
2508  int AddSAttrDatN(const TNodeI& NodeI, const TInt& AttrId, const TStr& Val) {
2509  return AddSAttrDatN(NodeI.GetId(), AttrId, Val);
2510  }
2511 
2513  int GetSAttrDatN(const TInt& NId, const TStr& AttrName, TInt& ValX) const;
2515  int GetSAttrDatN(const TInt& NId, const TInt& AttrId, TInt& ValX) const;
2516 
2518  int GetSAttrDatN(const TNodeI& NodeI, const TStr& AttrName, TInt& ValX) const {
2519  return GetSAttrDatN(NodeI.GetId(), AttrName, ValX);
2520  }
2522  int GetSAttrDatN(const TNodeI& NodeI, const TInt& AttrId, TInt& ValX) const {
2523  return GetSAttrDatN(NodeI.GetId(), AttrId, ValX);
2524  }
2525 
2527  int GetSAttrDatN(const TInt& NId, const TStr& AttrName, TFlt& ValX) const;
2529  int GetSAttrDatN(const TInt& NId, const TInt& AttrId, TFlt& ValX) const;
2530 
2532  int GetSAttrDatN(const TNodeI& NodeI, const TStr& AttrName, TFlt& ValX) const {
2533  return GetSAttrDatN(NodeI.GetId(), AttrName, ValX);
2534  }
2536  int GetSAttrDatN(const TNodeI& NodeI, const TInt& AttrId, TFlt& ValX) const {
2537  return GetSAttrDatN(NodeI.GetId(), AttrId, ValX);
2538  }
2539 
2541  int GetSAttrDatN(const TInt& NId, const TStr& AttrName, TStr& ValX) const;
2543  int GetSAttrDatN(const TInt& NId, const TInt& AttrId, TStr& ValX) const;
2544 
2546  int GetSAttrDatN(const TNodeI& NodeI, const TStr& AttrName, TStr& ValX) const {
2547  return GetSAttrDatN(NodeI.GetId(), AttrName, ValX);
2548  }
2550  int GetSAttrDatN(const TNodeI& NodeI, const TInt& AttrId, TStr& ValX) const {
2551  return GetSAttrDatN(NodeI.GetId(), AttrId, ValX);
2552  }
2553 
2555  int DelSAttrDatN(const TInt& NId, const TStr& AttrName);
2557  int DelSAttrDatN(const TInt& NId, const TInt& AttrId);
2558 
2560  int DelSAttrDatN(const TNodeI& NodeI, const TStr& AttrName) {
2561  return DelSAttrDatN(NodeI.GetId(), AttrName);
2562  }
2564  int DelSAttrDatN(const TNodeI& NodeI, const TInt& AttrId) {
2565  return DelSAttrDatN(NodeI.GetId(), AttrId);
2566  }
2567 
2569  int GetSAttrVN(const TInt& NId, const TAttrType AttrType, TAttrPrV& AttrV) const;
2571  int GetSAttrVN(const TNodeI& NodeI, const TAttrType AttrType, TAttrPrV& AttrV) const {
2572  return GetSAttrVN(NodeI.GetId(), AttrType, AttrV);
2573  }
2574 
2576  int GetIdVSAttrN(const TStr& AttrName, TIntV& IdV) const;
2578  int GetIdVSAttrN(const TInt& AttrId, TIntV& IdV) const;
2579 
2581  int AddSAttrN(const TStr& Name, const TAttrType& AttrType, TInt& AttrId);
2582 
2584  int GetSAttrIdN(const TStr& Name, TInt& AttrIdX, TAttrType& AttrTypeX) const;
2586  int GetSAttrNameN(const TInt& AttrId, TStr& NameX, TAttrType& AttrTypeX) const;
2587 
2589  int AddSAttrDatE(const TInt& EId, const TStr& AttrName, const TInt& Val);
2591  int AddSAttrDatE(const TInt& EId, const TInt& AttrId, const TInt& Val);
2592 
2594  int AddSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName, const TInt& Val) {
2595  return AddSAttrDatE(EdgeI.GetId(), AttrName, Val);
2596  }
2598  int AddSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId, const TInt& Val) {
2599  return AddSAttrDatE(EdgeI.GetId(), AttrId, Val);
2600  }
2601 
2603  int AddSAttrDatE(const TInt& EId, const TStr& AttrName, const TFlt& Val);
2605  int AddSAttrDatE(const TInt& EId, const TInt& AttrId, const TFlt& Val);
2606 
2608  int AddSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName, const TFlt& Val) {
2609  return AddSAttrDatE(EdgeI.GetId(), AttrName, Val);
2610  }
2612  int AddSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId, const TFlt& Val){
2613  return AddSAttrDatE(EdgeI.GetId(), AttrId, Val);
2614  }
2615 
2617  int AddSAttrDatE(const TInt& EId, const TStr& AttrName, const TStr& Val);
2619  int AddSAttrDatE(const TInt& EId, const TInt& AttrId, const TStr& Val);
2620 
2622  int AddSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName, const TStr& Val) {
2623  return AddSAttrDatE(EdgeI.GetId(), AttrName, Val);
2624  }
2626  int AddSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId, const TStr& Val) {
2627  return AddSAttrDatE(EdgeI.GetId(), AttrId, Val);
2628  }
2629 
2631  int GetSAttrDatE(const TInt& EId, const TStr& AttrName, TInt& ValX) const;
2633  int GetSAttrDatE(const TInt& EId, const TInt& AttrId, TInt& ValX) const;
2634 
2636  int GetSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName, TInt& ValX) const {
2637  return GetSAttrDatE(EdgeI.GetId(), AttrName, ValX);
2638  }
2640  int GetSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId, TInt& ValX) const {
2641  return GetSAttrDatE(EdgeI.GetId(), AttrId, ValX);
2642  }
2643 
2645  int GetSAttrDatE(const TInt& EId, const TStr& AttrName, TFlt& ValX) const;
2647  int GetSAttrDatE(const TInt& EId, const TInt& AttrId, TFlt& ValX) const;
2648 
2650  int GetSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName, TFlt& ValX) const {
2651  return GetSAttrDatE(EdgeI.GetId(), AttrName, ValX);
2652  }
2654  int GetSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId, TFlt& ValX) const {
2655  return GetSAttrDatE(EdgeI.GetId(), AttrId, ValX);
2656  }
2657 
2659  int GetSAttrDatE(const TInt& EId, const TStr& AttrName, TStr& ValX) const;
2661  int GetSAttrDatE(const TInt& EId, const TInt& AttrId, TStr& ValX) const;
2662 
2664  int GetSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName, TStr& ValX) const {
2665  return GetSAttrDatE(EdgeI.GetId(), AttrName, ValX);
2666  }
2668  int GetSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId, TStr& ValX) const {
2669  return GetSAttrDatE(EdgeI.GetId(), AttrId, ValX);
2670  }
2671 
2673  int DelSAttrDatE(const TInt& EId, const TStr& AttrName);
2675  int DelSAttrDatE(const TInt& EId, const TInt& AttrId);
2676 
2678  int DelSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName) {
2679  return DelSAttrDatE(EdgeI.GetId(), AttrName);
2680  }
2682  int DelSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId) {
2683  return DelSAttrDatE(EdgeI.GetId(), AttrId);
2684  }
2686  int GetSAttrVE(const TInt& EId, const TAttrType AttrType, TAttrPrV& AttrV) const;
2688  int GetSAttrVE(const TEdgeI& EdgeI, const TAttrType AttrType, TAttrPrV& AttrV) const {
2689  return GetSAttrVE(EdgeI.GetId(), AttrType, AttrV);
2690  }
2691 
2693  int GetIdVSAttrE(const TStr& AttrName, TIntV& IdV) const;
2695  int GetIdVSAttrE(const TInt& AttrId, TIntV& IdV) const;
2696 
2698  int AddSAttrE(const TStr& Name, const TAttrType& AttrType, TInt& AttrId);
2699 
2701  int GetSAttrIdE(const TStr& Name, TInt& AttrIdX, TAttrType& AttrTypeX) const;
2703  int GetSAttrNameE(const TInt& AttrId, TStr& NameX, TAttrType& AttrTypeX) const;
2704 
2706 
2710  static PNEANet GetSmallGraph();
2711  friend class TPt<TNEANet>;
2712 };
2713 
2714 // set flags
2715 namespace TSnap {
2716 template <> struct IsMultiGraph<TNEANet> { enum { Val = 1 }; };
2717 template <> struct IsDirected<TNEANet> { enum { Val = 1 }; };
2718 }
2719 
2720  //#//////////////////////////////////////////////
2722 
2724 
2726 typedef TPt<TUndirNet> PUndirNet;
2727 
2728 //#//////////////////////////////////////////////
2730 class TDirNet;
2731 
2733 typedef TPt<TDirNet> PDirNet;
2734 
2735 //#//////////////////////////////////////////////
2737 
2748 class TUndirNet {
2749 public:
2750  typedef TUndirNet TNet;
2752 public:
2753  class TNode {
2754  private:
2757  public:
2758  TNode() : Id(-1), NIdV() { }
2759  TNode(const int& NId) : Id(NId), NIdV() { }
2760  TNode(const TNode& Node) : Id(Node.Id), NIdV(Node.NIdV) { }
2761  TNode(TSIn& SIn) : Id(SIn), NIdV(SIn) { }
2762  void Save(TSOut& SOut) const { Id.Save(SOut); NIdV.Save(SOut); }
2763  int GetId() const { return Id; }
2764  int GetDeg() const { return NIdV.Len(); }
2765  int GetInDeg() const { return GetDeg(); }
2766  int GetOutDeg() const { return GetDeg(); }
2767  int GetInNId(const int& NodeN) const { return GetNbrNId(NodeN); }
2768  int GetOutNId(const int& NodeN) const { return GetNbrNId(NodeN); }
2769  int GetNbrNId(const int& NodeN) const { return NIdV[NodeN]; }
2770  bool IsNbrNId(const int& NId) const { return NIdV.SearchBin(NId)!=-1; }
2771  bool IsInNId(const int& NId) const { return IsNbrNId(NId); }
2772  bool IsOutNId(const int& NId) const { return IsNbrNId(NId); }
2773  void PackOutNIdV() { NIdV.Pack(); }
2774  void PackNIdV() { NIdV.Pack(); }
2775  friend class TUndirNet;
2776  friend class TUndirNetMtx;
2777  };
2779  class TNodeI {
2780  private:
2783  public:
2784  TNodeI() : NodeHI() { }
2785  TNodeI(const THashIter& NodeHIter) : NodeHI(NodeHIter) { }
2786  TNodeI(const TNodeI& NodeI) : NodeHI(NodeI.NodeHI) { }
2787  TNodeI& operator = (const TNodeI& NodeI) { NodeHI = NodeI.NodeHI; return *this; }
2788 
2790  TNodeI& operator++ (int) { NodeHI++; return *this; }
2792  TNodeI& operator-- (int) { NodeHI--; return *this; }
2793 
2794 
2795  bool operator < (const TNodeI& NodeI) const { return NodeHI < NodeI.NodeHI; }
2796  bool operator == (const TNodeI& NodeI) const { return NodeHI == NodeI.NodeHI; }
2797 
2799  int GetId() const { return NodeHI.GetDat().GetId(); }
2801  int GetDeg() const { return NodeHI.GetDat().GetDeg(); }
2803  int GetInDeg() const { return NodeHI.GetDat().GetInDeg(); }
2805  int GetOutDeg() const { return NodeHI.GetDat().GetOutDeg(); }
2807 
2810  int GetInNId(const int& NodeN) const { return NodeHI.GetDat().GetInNId(NodeN); }
2812 
2815  int GetOutNId(const int& NodeN) const { return NodeHI.GetDat().GetOutNId(NodeN); }
2817 
2820  int GetNbrNId(const int& NodeN) const { return NodeHI.GetDat().GetNbrNId(NodeN); }
2822  bool IsInNId(const int& NId) const { return NodeHI.GetDat().IsInNId(NId); }
2824  bool IsOutNId(const int& NId) const { return NodeHI.GetDat().IsOutNId(NId); }
2826  bool IsNbrNId(const int& NId) const { return NodeHI.GetDat().IsNbrNId(NId); }
2827  friend class TUndirNet;
2828  };
2830  class TEdgeI {
2831  private:
2832  TNodeI CurNode, EndNode;
2833  int CurEdge;
2834  public:
2835  TEdgeI() : CurNode(), EndNode(), CurEdge(0) { }
2836  TEdgeI(const TNodeI& NodeI, const TNodeI& EndNodeI, const int& EdgeN=0) : CurNode(NodeI), EndNode(EndNodeI), CurEdge(EdgeN) { }
2837  TEdgeI(const TEdgeI& EdgeI) : CurNode(EdgeI.CurNode), EndNode(EdgeI.EndNode), CurEdge(EdgeI.CurEdge) { }
2838  TEdgeI& operator = (const TEdgeI& EdgeI) { if (this!=&EdgeI) { CurNode=EdgeI.CurNode; EndNode=EdgeI.EndNode; CurEdge=EdgeI.CurEdge; } return *this; }
2840  TEdgeI& operator++ (int) { do { CurEdge++; if (CurEdge >= CurNode.GetOutDeg()) { CurEdge=0; CurNode++; while (CurNode < EndNode && CurNode.GetOutDeg()==0) { CurNode++; } } } while (CurNode < EndNode && GetSrcNId()>GetDstNId()); return *this; }
2841  bool operator < (const TEdgeI& EdgeI) const { return CurNode<EdgeI.CurNode || (CurNode==EdgeI.CurNode && CurEdge<EdgeI.CurEdge); }
2842  bool operator == (const TEdgeI& EdgeI) const { return CurNode == EdgeI.CurNode && CurEdge == EdgeI.CurEdge; }
2844  int GetId() const { return -1; }
2846  int GetSrcNId() const { return CurNode.GetId(); }
2848  int GetDstNId() const { return CurNode.GetOutNId(CurEdge); }
2849  friend class TUndirNet;
2850  };
2851 private:
2855 
2858 private:
2859  TNode& GetNode(const int& NId) { return NodeH.GetDat(NId); }
2860  const TNode& GetNode(const int& NId) const { return NodeH.GetDat(NId); }
2861  TIntPr OrderEdgeNodes(const int& SrcNId, const int& DstNId) const;
2862 public:
2863  TUndirNet() : CRef(), MxNId(0), NEdges(0), NodeH(), SAttrN(), SAttrE() { }
2865  explicit TUndirNet(const int& Nodes, const int& Edges) : MxNId(0), NEdges(0), SAttrN(), SAttrE() { Reserve(Nodes, Edges); }
2866  TUndirNet(const TUndirNet& Graph) : MxNId(Graph.MxNId), NEdges(Graph.NEdges), NodeH(Graph.NodeH),
2867  SAttrN(), SAttrE() { }
2869  TUndirNet(TSIn& SIn) : MxNId(SIn), NEdges(SIn), NodeH(SIn), SAttrN(SIn), SAttrE(SIn) { }
2871  void Save(TSOut& SOut) const { MxNId.Save(SOut); NEdges.Save(SOut); NodeH.Save(SOut);
2872  SAttrN.Save(SOut); SAttrE.Save(SOut); }
2874  void Save_V1(TSOut& SOut) const { MxNId.Save(SOut); NEdges.Save(SOut); NodeH.Save(SOut); }
2876  static PUndirNet New() { return new TUndirNet(); }
2878 
2880  static PUndirNet New(const int& Nodes, const int& Edges) { return new TUndirNet(Nodes, Edges); }
2882  static PUndirNet Load(TSIn& SIn) { return PUndirNet(new TUndirNet(SIn)); }
2884  static PUndirNet Load_V1(TSIn& SIn) { PUndirNet Graph = PUndirNet(new TUndirNet());
2885  Graph->MxNId.Load(SIn); Graph->NEdges.Load(SIn); Graph->NodeH.Load(SIn); return Graph;
2886  }
2887 
2889  bool HasFlag(const TGraphFlag& Flag) const;
2891  if (this!=&Graph) { MxNId=Graph.MxNId; NEdges=Graph.NEdges; NodeH=Graph.NodeH; } return *this; }
2892 
2894  int GetNodes() const { return NodeH.Len(); }
2896 
2900  int AddNode(int NId = -1);
2902  int AddNode(const TNodeI& NodeI) { return AddNode(NodeI.GetId()); }
2904 
2913  int AddNode(const int& NId, const TIntV& NbrNIdV);
2915 
2924  int AddNode(const int& NId, const TVecPool<TInt>& Pool, const int& NIdVId);
2926 
2928  void DelNode(const int& NId);
2930  void DelNode(const TNode& NodeI) { DelNode(NodeI.GetId()); }
2932  bool IsNode(const int& NId) const { return NodeH.IsKey(NId); }
2934  TNodeI BegNI() const { return TNodeI(NodeH.BegI()); }
2936  TNodeI EndNI() const { return TNodeI(NodeH.EndI()); }
2938  TNodeI GetNI(const int& NId) const { return TNodeI(NodeH.GetI(NId)); }
2940  int GetMxNId() const { return MxNId; }
2941 
2943  int GetEdges() const;
2945 
2951  int AddEdge(const int& SrcNId, const int& DstNId);
2953  int AddEdge(const TEdgeI& EdgeI) { return AddEdge(EdgeI.GetSrcNId(), EdgeI.GetDstNId()); }
2955 
2959  void DelEdge(const int& SrcNId, const int& DstNId);
2961  bool IsEdge(const int& SrcNId, const int& DstNId) const;
2963  TEdgeI BegEI() const { TNodeI NI = BegNI(); TEdgeI EI(NI, EndNI(), 0); if (GetNodes() != 0 && (NI.GetOutDeg()==0 || NI.GetId()>NI.GetOutNId(0))) { EI++; } return EI; }
2965  TEdgeI EndEI() const { return TEdgeI(EndNI(), EndNI()); }
2967  TEdgeI GetEI(const int& EId) const;
2969 
2972  TEdgeI GetEI(const int& SrcNId, const int& DstNId) const;
2973 
2975  int GetRndNId(TRnd& Rnd=TInt::Rnd) { return NodeH.GetKey(NodeH.GetRndKeyId(Rnd, 0.8)); }
2977  TNodeI GetRndNI(TRnd& Rnd=TInt::Rnd) { return GetNI(GetRndNId(Rnd)); }
2979  void GetNIdV(TIntV& NIdV) const;
2980 
2982  bool Empty() const { return GetNodes()==0; }
2984  void Clr() { MxNId=0; NEdges=0; NodeH.Clr(); SAttrN.Clr(); SAttrE.Clr(); }
2986  void Reserve(const int& Nodes, const int& Edges) { if (Nodes>0) NodeH.Gen(Nodes/2); }
2988  void ReserveNIdDeg(const int& NId, const int& Deg) { GetNode(NId).NIdV.Reserve(Deg); }
2990 
2995  void Defrag(const bool& OnlyNodeLinks=false);
2997 
3000  bool IsOk(const bool& ThrowExcept=true) const;
3002  void Dump(FILE *OutF=stdout) const;
3004 
3010  static PUndirNet GetSmallGraph();
3011 
3013  int AddSAttrDatN(const TInt& NId, const TStr& AttrName, const TInt& Val);
3015  int AddSAttrDatN(const TInt& NId, const TInt& AttrId, const TInt& Val);
3016 
3018  int AddSAttrDatN(const TNodeI& NodeI, const TStr& AttrName, const TInt& Val) {
3019  return AddSAttrDatN(NodeI.GetId(), AttrName, Val);
3020  }
3022  int AddSAttrDatN(const TNodeI& NodeI, const TInt& AttrId, const TInt& Val) {
3023  return AddSAttrDatN(NodeI.GetId(), AttrId, Val);
3024  }
3025 
3027  int AddSAttrDatN(const TInt& NId, const TStr& AttrName, const TFlt& Val);
3029  int AddSAttrDatN(const TInt& NId, const TInt& AttrId, const TFlt& Val);
3030 
3032  int AddSAttrDatN(const TNodeI& NodeI, const TStr& AttrName, const TFlt& Val) {
3033  return AddSAttrDatN(NodeI.GetId(), AttrName, Val);
3034  }
3036  int AddSAttrDatN(const TNodeI& NodeI, const TInt& AttrId, const TFlt& Val) {
3037  return AddSAttrDatN(NodeI.GetId(), AttrId, Val);
3038  }
3039 
3041  int AddSAttrDatN(const TInt& NId, const TStr& AttrName, const TStr& Val);
3043  int AddSAttrDatN(const TInt& NId, const TInt& AttrId, const TStr& Val);
3044 
3046  int AddSAttrDatN(const TNodeI& NodeI, const TStr& AttrName, const TStr& Val) {
3047  return AddSAttrDatN(NodeI.GetId(), AttrName, Val);
3048  }
3050  int AddSAttrDatN(const TNodeI& NodeI, const TInt& AttrId, const TStr& Val) {
3051  return AddSAttrDatN(NodeI.GetId(), AttrId, Val);
3052  }
3053 
3055  int GetSAttrDatN(const TInt& NId, const TStr& AttrName, TInt& ValX) const;
3057  int GetSAttrDatN(const TInt& NId, const TInt& AttrId, TInt& ValX) const;
3058 
3060  int GetSAttrDatN(const TNodeI& NodeI, const TStr& AttrName, TInt& ValX) const {
3061  return GetSAttrDatN(NodeI.GetId(), AttrName, ValX);
3062  }
3064  int GetSAttrDatN(const TNodeI& NodeI, const TInt& AttrId, TInt& ValX) const {
3065  return GetSAttrDatN(NodeI.GetId(), AttrId, ValX);
3066  }
3067 
3069  int GetSAttrDatN(const TInt& NId, const TStr& AttrName, TFlt& ValX) const;
3071  int GetSAttrDatN(const TInt& NId, const TInt& AttrId, TFlt& ValX) const;
3072 
3074  int GetSAttrDatN(const TNodeI& NodeI, const TStr& AttrName, TFlt& ValX) const {
3075  return GetSAttrDatN(NodeI.GetId(), AttrName, ValX);
3076  }
3078  int GetSAttrDatN(const TNodeI& NodeI, const TInt& AttrId, TFlt& ValX) const {
3079  return GetSAttrDatN(NodeI.GetId(), AttrId, ValX);
3080  }
3081 
3083  int GetSAttrDatN(const TInt& NId, const TStr& AttrName, TStr& ValX) const;
3085  int GetSAttrDatN(const TInt& NId, const TInt& AttrId, TStr& ValX) const;
3086 
3088  int GetSAttrDatN(const TNodeI& NodeI, const TStr& AttrName, TStr& ValX) const {
3089  return GetSAttrDatN(NodeI.GetId(), AttrName, ValX);
3090  }
3092  int GetSAttrDatN(const TNodeI& NodeI, const TInt& AttrId, TStr& ValX) const {
3093  return GetSAttrDatN(NodeI.GetId(), AttrId, ValX);
3094  }
3095 
3097  int DelSAttrDatN(const TInt& NId, const TStr& AttrName);
3099  int DelSAttrDatN(const TInt& NId, const TInt& AttrId);
3100 
3102  int DelSAttrDatN(const TNodeI& NodeI, const TStr& AttrName) {
3103  return DelSAttrDatN(NodeI.GetId(), AttrName);
3104  }
3106  int DelSAttrDatN(const TNodeI& NodeI, const TInt& AttrId) {
3107  return DelSAttrDatN(NodeI.GetId(), AttrId);
3108  }
3109 
3111  int GetSAttrVN(const TInt& NId, const TAttrType AttrType, TAttrPrV& AttrV) const;
3113  int GetSAttrVN(const TNodeI& NodeI, const TAttrType AttrType, TAttrPrV& AttrV) const {
3114  return GetSAttrVN(NodeI.GetId(), AttrType, AttrV);
3115  }
3116 
3118  int GetIdVSAttrN(const TStr& AttrName, TIntV& IdV) const;
3120  int GetIdVSAttrN(const TInt& AttrId, TIntV& IdV) const;
3121 
3123  int AddSAttrN(const TStr& Name, const TAttrType& AttrType, TInt& AttrId);
3124 
3126  int GetSAttrIdN(const TStr& Name, TInt& AttrIdX, TAttrType& AttrTypeX) const;
3128  int GetSAttrNameN(const TInt& AttrId, TStr& NameX, TAttrType& AttrTypeX) const;
3129 
3131  int AddSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName, const TInt& Val);
3133  int AddSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId, const TInt& Val);
3134 
3136  int AddSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName, const TInt& Val) {
3137  return AddSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName, Val);
3138  }
3140  int AddSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId, const TInt& Val) {
3141  return AddSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId, Val);
3142  }
3143 
3145  int AddSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName, const TFlt& Val);
3147  int AddSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId, const TFlt& Val);
3148 
3150  int AddSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName, const TFlt& Val) {
3151  return AddSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName, Val);
3152  }
3154  int AddSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId, const TFlt& Val){
3155  return AddSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId, Val);
3156  }
3157 
3159  int AddSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName, const TStr& Val);
3161  int AddSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId, const TStr& Val);
3162 
3164  int AddSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName, const TStr& Val) {
3165  return AddSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName, Val);
3166  }
3168  int AddSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId, const TStr& Val) {
3169  return AddSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId, Val);
3170  }
3171 
3173  int GetSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName, TInt& ValX) const;
3175  int GetSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId, TInt& ValX) const;
3176 
3178  int GetSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName, TInt& ValX) const {
3179  return GetSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName, ValX);
3180  }
3182  int GetSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId, TInt& ValX) const {
3183  return GetSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId, ValX);
3184  }
3185 
3187  int GetSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName, TFlt& ValX) const;
3189  int GetSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId, TFlt& ValX) const;
3190 
3192  int GetSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName, TFlt& ValX) const {
3193  return GetSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName, ValX);
3194  }
3196  int GetSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId, TFlt& ValX) const {
3197  return GetSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId, ValX);
3198  }
3199 
3201  int GetSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName, TStr& ValX) const;
3203  int GetSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId, TStr& ValX) const;
3204 
3206  int GetSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName, TStr& ValX) const {
3207  return GetSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName, ValX);
3208  }
3210  int GetSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId, TStr& ValX) const {
3211  return GetSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId, ValX);
3212  }
3213 
3215  int DelSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName);
3217  int DelSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId);
3218 
3220  int DelSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName) {
3221  return DelSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName);
3222  }
3224  int DelSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId) {
3225  return DelSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId);
3226  }
3228  int GetSAttrVE(const int& SrcNId, const int& DstNId, const TAttrType AttrType, TAttrPrV& AttrV) const;
3230  int GetSAttrVE(const TEdgeI& EdgeI, const TAttrType AttrType, TAttrPrV& AttrV) const {
3231  return GetSAttrVE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrType, AttrV);
3232  }
3233 
3235  int GetIdVSAttrE(const TStr& AttrName, TIntPrV& IdV) const;
3237  int GetIdVSAttrE(const TInt& AttrId, TIntPrV& IdV) const;
3238 
3240  int AddSAttrE(const TStr& Name, const TAttrType& AttrType, TInt& AttrId);
3241 
3243  int GetSAttrIdE(const TStr& Name, TInt& AttrIdX, TAttrType& AttrTypeX) const;
3245  int GetSAttrNameE(const TInt& AttrId, TStr& NameX, TAttrType& AttrTypeX) const;
3246 
3247  friend class TUndirNetMtx;
3248  friend class TPt<TUndirNet>;
3249 };
3250 
3251 //#//////////////////////////////////////////////
3253 
3267 class TDirNet {
3268 public:
3269  typedef TDirNet TNet;
3271 public:
3272  class TNode {
3273  private:
3275  TIntV InNIdV, OutNIdV;
3276  public:
3277  TNode() : Id(-1), InNIdV(), OutNIdV() { }
3278  TNode(const int& NId) : Id(NId), InNIdV(), OutNIdV() { }
3279  TNode(const TNode& Node) : Id(Node.Id), InNIdV(Node.InNIdV), OutNIdV(Node.OutNIdV) { }
3280  TNode(TSIn& SIn) : Id(SIn), InNIdV(SIn), OutNIdV(SIn) { }
3281  void Save(TSOut& SOut) const { Id.Save(SOut); InNIdV.Save(SOut); OutNIdV.Save(SOut); }
3282  int GetId() const { return Id; }
3283  int GetDeg() const { return GetInDeg() + GetOutDeg(); }
3284  int GetInDeg() const { return InNIdV.Len(); }
3285  int GetOutDeg() const { return OutNIdV.Len(); }
3286  int GetInNId(const int& NodeN) const { return InNIdV[NodeN]; }
3287  int GetOutNId(const int& NodeN) const { return OutNIdV[NodeN]; }
3288  int GetNbrNId(const int& NodeN) const { return NodeN<GetOutDeg()?GetOutNId(NodeN):GetInNId(NodeN-GetOutDeg()); }
3289  bool IsInNId(const int& NId) const { return InNIdV.SearchBin(NId) != -1; }
3290  bool IsOutNId(const int& NId) const { return OutNIdV.SearchBin(NId) != -1; }
3291  bool IsNbrNId(const int& NId) const { return IsOutNId(NId) || IsInNId(NId); }
3292  void PackOutNIdV() { OutNIdV.Pack(); }
3293  void PackNIdV() { InNIdV.Pack(); }
3294  friend class TDirNet;
3295  friend class TDirNetMtx;
3296  };
3298  class TNodeI {
3299  private:
3302  public:
3303  TNodeI() : NodeHI() { }
3304  TNodeI(const THashIter& NodeHIter) : NodeHI(NodeHIter) { }
3305  TNodeI(const TNodeI& NodeI) : NodeHI(NodeI.NodeHI) { }
3306  TNodeI& operator = (const TNodeI& NodeI) { NodeHI = NodeI.NodeHI; return *this; }
3308  TNodeI& operator++ (int) { NodeHI++; return *this; }
3310  TNodeI& operator-- (int) { NodeHI--; return *this; }
3311 
3312  bool operator < (const TNodeI& NodeI) const { return NodeHI < NodeI.NodeHI; }
3313  bool operator == (const TNodeI& NodeI) const { return NodeHI == NodeI.NodeHI; }
3315  int GetId() const { return NodeHI.GetDat().GetId(); }
3317  int GetDeg() const { return NodeHI.GetDat().GetDeg(); }
3319  int GetInDeg() const { return NodeHI.GetDat().GetInDeg(); }
3321  int GetOutDeg() const { return NodeHI.GetDat().GetOutDeg(); }
3323 
3325  int GetInNId(const int& NodeN) const { return NodeHI.GetDat().GetInNId(NodeN); }
3327 
3329  int GetOutNId(const int& NodeN) const { return NodeHI.GetDat().GetOutNId(NodeN); }
3331 
3333  int GetNbrNId(const int& NodeN) const { return NodeHI.GetDat().GetNbrNId(NodeN); }
3335  bool IsInNId(const int& NId) const { return NodeHI.GetDat().IsInNId(NId); }
3337  bool IsOutNId(const int& NId) const { return NodeHI.GetDat().IsOutNId(NId); }
3339  bool IsNbrNId(const int& NId) const { return IsOutNId(NId) || IsInNId(NId); }
3340  friend class TDirNet;
3341  };
3343  class TEdgeI {
3344  private:
3345  TNodeI CurNode, EndNode;
3346  int CurEdge;
3347  public:
3348  TEdgeI() : CurNode(), EndNode(), CurEdge(0) { }
3349  TEdgeI(const TNodeI& NodeI, const TNodeI& EndNodeI, const int& EdgeN=0) : CurNode(NodeI), EndNode(EndNodeI), CurEdge(EdgeN) { }
3350  TEdgeI(const TEdgeI& EdgeI) : CurNode(EdgeI.CurNode), EndNode(EdgeI.EndNode), CurEdge(EdgeI.CurEdge) { }
3351  TEdgeI& operator = (const TEdgeI& EdgeI) { if (this!=&EdgeI) { CurNode=EdgeI.CurNode; EndNode=EdgeI.EndNode; CurEdge=EdgeI.CurEdge; } return *this; }
3353  TEdgeI& operator++ (int) { CurEdge++; if (CurEdge >= CurNode.GetOutDeg()) { CurEdge=0; CurNode++;
3354  while (CurNode < EndNode && CurNode.GetOutDeg()==0) { CurNode++; } } return *this; }
3355  bool operator < (const TEdgeI& EdgeI) const { return CurNode<EdgeI.CurNode || (CurNode==EdgeI.CurNode && CurEdge<EdgeI.CurEdge); }
3356  bool operator == (const TEdgeI& EdgeI) const { return CurNode == EdgeI.CurNode && CurEdge == EdgeI.CurEdge; }
3358  int GetId() const { return -1; }
3360  int GetSrcNId() const { return CurNode.GetId(); }
3362  int GetDstNId() const { return CurNode.GetOutNId(CurEdge); }
3363  friend class TDirNet;
3364  };
3365 private:
3371 private:
3372  TNode& GetNode(const int& NId) { return NodeH.GetDat(NId); }
3373  const TNode& GetNode(const int& NId) const { return NodeH.GetDat(NId); }
3374 public:
3375  TDirNet() : CRef(), MxNId(0), NodeH(), SAttrN(), SAttrE() { }
3377  explicit TDirNet(const int& Nodes, const int& Edges) : MxNId(0), SAttrN(), SAttrE() { Reserve(Nodes, Edges); }
3378  TDirNet(const TDirNet& Graph) : MxNId(Graph.MxNId), NodeH(Graph.NodeH), SAttrN(), SAttrE() { }
3380  TDirNet(TSIn& SIn) : MxNId(SIn), NodeH(SIn), SAttrN(SIn), SAttrE(SIn) { }
3382  void Save(TSOut& SOut) const { MxNId.Save(SOut); NodeH.Save(SOut); SAttrN.Save(SOut); SAttrE.Save(SOut); }
3384  void Save_V1(TSOut& SOut) const { MxNId.Save(SOut); NodeH.Save(SOut); }
3386  static PDirNet New() { return new TDirNet(); }
3388 
3390  static PDirNet New(const int& Nodes, const int& Edges) { return new TDirNet(Nodes, Edges); }
3392  static PDirNet Load(TSIn& SIn) { return PDirNet(new TDirNet(SIn)); }
3394  static PDirNet Load_V1(TSIn& SIn) { PDirNet Graph = PDirNet(new TDirNet());
3395  Graph->MxNId.Load(SIn); Graph->NodeH.Load(SIn); return Graph;
3396  }
3398  bool HasFlag(const TGraphFlag& Flag) const;
3399  TDirNet& operator = (const TDirNet& Graph) {
3400  if (this!=&Graph) { MxNId=Graph.MxNId; NodeH=Graph.NodeH; } return *this; }
3401 
3403  int GetNodes() const { return NodeH.Len(); }
3405 
3409  int AddNode(int NId = -1);
3411  int AddNode(const TNodeI& NodeId) { return AddNode(NodeId.GetId()); }
3413 
3423  int AddNode(const int& NId, const TIntV& InNIdV, const TIntV& OutNIdV);
3425 
3434  int AddNode(const int& NId, const TVecPool<TInt>& Pool, const int& SrcVId, const int& DstVId);
3436 
3438  void DelNode(const int& NId);
3440  void DelNode(const TNode& NodeI) { DelNode(NodeI.GetId()); }
3442  bool IsNode(const int& NId) const { return NodeH.IsKey(NId); }
3444  TNodeI BegNI() const { return TNodeI(NodeH.BegI()); }
3446  TNodeI EndNI() const { return TNodeI(NodeH.EndI()); }
3448  TNodeI GetNI(const int& NId) const { return TNodeI(NodeH.GetI(NId)); }
3449  // GetNodeC() has been commented out. It was a quick shortcut, do not use.
3450  //const TNode& GetNodeC(const int& NId) const { return NodeH.GetDat(NId); }
3452  int GetMxNId() const { return MxNId; }
3453 
3455  int GetEdges() const;
3457 
3463  int AddEdge(const int& SrcNId, const int& DstNId);
3465  int AddEdge(const TEdgeI& EdgeI) { return AddEdge(EdgeI.GetSrcNId(), EdgeI.GetDstNId()); }
3467 
3471  void DelEdge(const int& SrcNId, const int& DstNId, const bool& IsDir = true);
3473  bool IsEdge(const int& SrcNId, const int& DstNId, const bool& IsDir = true) const;
3475  TEdgeI BegEI() const { TNodeI NI=BegNI(); while(NI<EndNI() && NI.GetOutDeg()==0){NI++;} return TEdgeI(NI, EndNI()); }
3477  TEdgeI EndEI() const { return TEdgeI(EndNI(), EndNI()); }
3479  TEdgeI GetEI(const int& EId) const; // not supported
3481  TEdgeI GetEI(const int& SrcNId, const int& DstNId) const;
3482 
3484  int GetRndNId(TRnd& Rnd=TInt::Rnd) { return NodeH.GetKey(NodeH.GetRndKeyId(Rnd, 0.8)); }
3486  TNodeI GetRndNI(TRnd& Rnd=TInt::Rnd) { return GetNI(GetRndNId(Rnd)); }
3488  void GetNIdV(TIntV& NIdV) const;
3489 
3491  bool Empty() const { return GetNodes()==0; }
3493  void Clr() { MxNId=0; NodeH.Clr(); SAttrN.Clr(); SAttrE.Clr(); }
3495  void Reserve(const int& Nodes, const int& Edges) { if (Nodes>0) { NodeH.Gen(Nodes/2); } }
3497  void ReserveNIdInDeg(const int& NId, const int& InDeg) { GetNode(NId).InNIdV.Reserve(InDeg); }
3499  void ReserveNIdOutDeg(const int& NId, const int& OutDeg) { GetNode(NId).OutNIdV.Reserve(OutDeg); }
3501 
3506  void Defrag(const bool& OnlyNodeLinks=false);
3508 
3511  bool IsOk(const bool& ThrowExcept=true) const;
3513  void Dump(FILE *OutF=stdout) const;
3515 
3519  static PDirNet GetSmallGraph();
3520 
3522  int AddSAttrDatN(const TInt& NId, const TStr& AttrName, const TInt& Val);
3524  int AddSAttrDatN(const TInt& NId, const TInt& AttrId, const TInt& Val);
3525 
3527  int AddSAttrDatN(const TNodeI& NodeI, const TStr& AttrName, const TInt& Val) {
3528  return AddSAttrDatN(NodeI.GetId(), AttrName, Val);
3529  }
3531  int AddSAttrDatN(const TNodeI& NodeI, const TInt& AttrId, const TInt& Val) {
3532  return AddSAttrDatN(NodeI.GetId(), AttrId, Val);
3533  }
3534 
3536  int AddSAttrDatN(const TInt& NId, const TStr& AttrName, const TFlt& Val);
3538  int AddSAttrDatN(const TInt& NId, const TInt& AttrId, const TFlt& Val);
3539 
3541  int AddSAttrDatN(const TNodeI& NodeI, const TStr& AttrName, const TFlt& Val) {
3542  return AddSAttrDatN(NodeI.GetId(), AttrName, Val);
3543  }
3545  int AddSAttrDatN(const TNodeI& NodeI, const TInt& AttrId, const TFlt& Val) {
3546  return AddSAttrDatN(NodeI.GetId(), AttrId, Val);
3547  }
3548 
3550  int AddSAttrDatN(const TInt& NId, const TStr& AttrName, const TStr& Val);
3552  int AddSAttrDatN(const TInt& NId, const TInt& AttrId, const TStr& Val);
3553 
3555  int AddSAttrDatN(const TNodeI& NodeI, const TStr& AttrName, const TStr& Val) {
3556  return AddSAttrDatN(NodeI.GetId(), AttrName, Val);
3557  }
3559  int AddSAttrDatN(const TNodeI& NodeI, const TInt& AttrId, const TStr& Val) {
3560  return AddSAttrDatN(NodeI.GetId(), AttrId, Val);
3561  }
3562 
3564  int GetSAttrDatN(const TInt& NId, const TStr& AttrName, TInt& ValX) const;
3566  int GetSAttrDatN(const TInt& NId, const TInt& AttrId, TInt& ValX) const;
3567 
3569  int GetSAttrDatN(const TNodeI& NodeI, const TStr& AttrName, TInt& ValX) const {
3570  return GetSAttrDatN(NodeI.GetId(), AttrName, ValX);
3571  }
3573  int GetSAttrDatN(const TNodeI& NodeI, const TInt& AttrId, TInt& ValX) const {
3574  return GetSAttrDatN(NodeI.GetId(), AttrId, ValX);
3575  }
3576 
3578  int GetSAttrDatN(const TInt& NId, const TStr& AttrName, TFlt& ValX) const;
3580  int GetSAttrDatN(const TInt& NId, const TInt& AttrId, TFlt& ValX) const;
3581 
3583  int GetSAttrDatN(const TNodeI& NodeI, const TStr& AttrName, TFlt& ValX) const {
3584  return GetSAttrDatN(NodeI.GetId(), AttrName, ValX);
3585  }
3587  int GetSAttrDatN(const TNodeI& NodeI, const TInt& AttrId, TFlt& ValX) const {
3588  return GetSAttrDatN(NodeI.GetId(), AttrId, ValX);
3589  }
3590 
3592  int GetSAttrDatN(const TInt& NId, const TStr& AttrName, TStr& ValX) const;
3594  int GetSAttrDatN(const TInt& NId, const TInt& AttrId, TStr& ValX) const;
3595 
3597  int GetSAttrDatN(const TNodeI& NodeI, const TStr& AttrName, TStr& ValX) const {
3598  return GetSAttrDatN(NodeI.GetId(), AttrName, ValX);
3599  }
3601  int GetSAttrDatN(const TNodeI& NodeI, const TInt& AttrId, TStr& ValX) const {
3602  return GetSAttrDatN(NodeI.GetId(), AttrId, ValX);
3603  }
3604 
3606  int DelSAttrDatN(const TInt& NId, const TStr& AttrName);
3608  int DelSAttrDatN(const TInt& NId, const TInt& AttrId);
3609 
3611  int DelSAttrDatN(const TNodeI& NodeI, const TStr& AttrName) {
3612  return DelSAttrDatN(NodeI.GetId(), AttrName);
3613  }
3615  int DelSAttrDatN(const TNodeI& NodeI, const TInt& AttrId) {
3616  return DelSAttrDatN(NodeI.GetId(), AttrId);
3617  }
3618 
3620  int GetSAttrVN(const TInt& NId, const TAttrType AttrType, TAttrPrV& AttrV) const;
3622  int GetSAttrVN(const TNodeI& NodeI, const TAttrType AttrType, TAttrPrV& AttrV) const {
3623  return GetSAttrVN(NodeI.GetId(), AttrType, AttrV);
3624  }
3625 
3627  int GetIdVSAttrN(const TStr& AttrName, TIntV& IdV) const;
3629  int GetIdVSAttrN(const TInt& AttrId, TIntV& IdV) const;
3630 
3632  int AddSAttrN(const TStr& Name, const TAttrType& AttrType, TInt& AttrId);
3633 
3635  int GetSAttrIdN(const TStr& Name, TInt& AttrIdX, TAttrType& AttrTypeX) const;
3637  int GetSAttrNameN(const TInt& AttrId, TStr& NameX, TAttrType& AttrTypeX) const;
3638 
3640  int AddSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName, const TInt& Val);
3642  int AddSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId, const TInt& Val);
3643 
3645  int AddSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName, const TInt& Val) {
3646  return AddSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName, Val);
3647  }
3649  int AddSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId, const TInt& Val) {
3650  return AddSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId, Val);
3651  }
3652 
3654  int AddSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName, const TFlt& Val);
3656  int AddSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId, const TFlt& Val);
3657 
3659  int AddSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName, const TFlt& Val) {
3660  return AddSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName, Val);
3661  }
3663  int AddSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId, const TFlt& Val){
3664  return AddSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId, Val);
3665  }
3666 
3668  int AddSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName, const TStr& Val);
3670  int AddSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId, const TStr& Val);
3671 
3673  int AddSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName, const TStr& Val) {
3674  return AddSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName, Val);
3675  }
3677  int AddSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId, const TStr& Val) {
3678  return AddSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId, Val);
3679  }
3680 
3682  int GetSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName, TInt& ValX) const;
3684  int GetSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId, TInt& ValX) const;
3685 
3687  int GetSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName, TInt& ValX) const {
3688  return GetSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName, ValX);
3689  }
3691  int GetSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId, TInt& ValX) const {
3692  return GetSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId, ValX);
3693  }
3694 
3696  int GetSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName, TFlt& ValX) const;
3698  int GetSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId, TFlt& ValX) const;
3699 
3701  int GetSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName, TFlt& ValX) const {
3702  return GetSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName, ValX);
3703  }
3705  int GetSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId, TFlt& ValX) const {
3706  return GetSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId, ValX);
3707  }
3708 
3710  int GetSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName, TStr& ValX) const;
3712  int GetSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId, TStr& ValX) const;
3713 
3715  int GetSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName, TStr& ValX) const {
3716  return GetSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName, ValX);
3717  }
3719  int GetSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId, TStr& ValX) const {
3720  return GetSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId, ValX);
3721  }
3722 
3724  int DelSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName);
3726  int DelSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId);
3727 
3729  int DelSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName) {
3730  return DelSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName);
3731  }
3733  int DelSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId) {
3734  return DelSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId);
3735  }
3737  int GetSAttrVE(const int& SrcNId, const int& DstNId, const TAttrType AttrType, TAttrPrV& AttrV) const;
3739  int GetSAttrVE(const TEdgeI& EdgeI, const TAttrType AttrType, TAttrPrV& AttrV) const {
3740  return GetSAttrVE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrType, AttrV);
3741  }
3742 
3744  int GetIdVSAttrE(const TStr& AttrName, TIntPrV& IdV) const;
3746  int GetIdVSAttrE(const TInt& AttrId, TIntPrV& IdV) const;
3747 
3749  int AddSAttrE(const TStr& Name, const TAttrType& AttrType, TInt& AttrId);
3750 
3752  int GetSAttrIdE(const TStr& Name, TInt& AttrIdX, TAttrType& AttrTypeX) const;
3754  int GetSAttrNameE(const TInt& AttrId, TStr& NameX, TAttrType& AttrTypeX) const;
3755 
3756  friend class TPt<TDirNet>;
3757  friend class TDirNetMtx;
3758 };
3759 
3760 // set flags
3761 namespace TSnap {
3762 template <> struct IsDirected<TDirNet> { enum { Val = 1 }; };
3763 }
3764 #endif // NETWORK_H
int GetSAttrVE(const TEdgeI &EdgeI, const TAttrType AttrType, TAttrPrV &AttrV) const
Gets a list of all sparse attributes of type AttrType for EdgeI.
Definition: network.h:3739
int GetNbrEId(const int &EdgeN) const
Definition: network.h:1009
int AddEdge(const TEdgeI &EdgeI)
Adds an edge from EdgeI.GetSrcNId() to EdgeI.GetDstNId() to the network.
Definition: network.h:212
TEdgeI EndEI() const
Returns an iterator referring to the past-the-end edge in the network.
Definition: network.h:3477
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:627
TEdgeI GetEI(const int &EId) const
Not supported/implemented!
Definition: bd.h:440
TEdgeDat & GetOutEDat(const int &EdgeN)
Definition: network.h:1105
#define IAssert(Cond)
Definition: bd.h:262
static int GetNIdPos(const TVec< TPair< TInt, TEdgeData > > &NIdV, const int &NId)
Definition: network.h:742
TVec< TIntV > VecOfIntVecsN
Definition: network.h:1870
int AddSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to NodeI.
Definition: network.h:2476
TNEANet(TSIn &SIn)
Constructor for loading the graph from a (binary) stream SIn.
Definition: network.h:1898
bool IsNbrNId(const int &NId) const
Tests whether node with ID NId is a neighbor of the current node.
Definition: network.h:1671
int GetSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, TFlt &ValX) const
Gets Flt sparse attribute with name AttrName from EdgeI.
Definition: network.h:3701
TInt MxEId
Definition: network.h:1152
TNodeData TNodeDat
Definition: network.h:983
TEdgeI(const THashIter &EdgeHIter, const TNodeEdgeNet *NetPt)
Definition: network.h:1120
static const T & Mn(const T &LVal, const T &RVal)
Definition: xmath.h:36
TNodeI & operator++(int)
Increment iterator.
Definition: network.h:495
TNodeNet(const TNodeNet &NodeNet)
Definition: network.h:144
TEdgeI & operator++(int)
Definition: network.h:1123
TNodeI(const THashIter &NodeHIter, const TNodeNet *NetPt)
Definition: network.h:59
TPair< TInt, TInt > TIntPr
Definition: ds.h:83
TNodeData & GetDat()
Definition: network.h:470
Tests (at compile time) if the graph is a network with data on nodes.
Definition: gbase.h:32
TEdge(const TEdge &Edge)
Definition: network.h:1024
void IntVAttrNameNI(const TInt &NId, TStrV &Names) const
Returns a vector of int attr names for node NId.
Definition: network.h:2053
int DelSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName)
Deletes sparse attribute with name AttrName from EdgeI.
Definition: network.h:3729
void Reserve(const int &Nodes, const int &Edges)
Reserves memory for a network of Nodes nodes and Edges edges.
Definition: network.h:3495
TNodeData & GetOutNDat(const int &EdgeN)
Definition: network.h:1086
bool IsDeleted() const
Returns true if the attribute has been deleted.
Definition: network.h:1768
TInt GetIntAttrDatN(const TNodeI &NodeI, const TStr &attr)
Gets the value of int attr from the node attr value vector.
Definition: network.h:2304
bool IsOutNId(const int &NId) const
Definition: network.h:45
int GetSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, TFlt &ValX) const
Gets Flt sparse attribute with name AttrName from NodeI.
Definition: network.h:3074
int GetRndNId(TRnd &Rnd=TInt::Rnd)
Returns an ID of a random node in the graph.
Definition: network.h:2215
int GetAttrIndE(const TStr &attr)
Gets the index of the edge attr value vector specified by attr.
Definition: network.cpp:1106
bool DelIfIn(const TVal &Val)
Removes the first occurrence of element Val.
Definition: ds.h:1151
int GetDeg() const
Returns degree of the current node.
Definition: network.h:2801
void Clr()
Deletes all nodes and edges from the network.
Definition: network.h:1283
TIter EndI() const
Returns an iterator referring to the past-the-end element in the vector.
Definition: ds.h:567
int GetInEId(const int &EdgeN) const
Returns ID of EdgeN-th in-edge.
Definition: network.h:1091
const TNodeData & GetInNDat(const int &EdgeN) const
Definition: network.h:1083
int GetId() const
Definition: network.h:1626
int GetNbrEId(const int &EdgeN) const
Returns ID of EdgeN-th in or out-edge.
Definition: network.h:1095
int GetSAttrIdE(const TStr &Name, TInt &AttrIdX, TAttrType &AttrTypeX) const
Gets id and type for attribute with name Name.
Definition: network.cpp:2128
static PUndirNet New()
Static constructor that returns a pointer to the network. Call: PUndirNet Graph = TUndirNet::New()...
Definition: network.h:2876
void GetAttrENames(TStrV &IntAttrNames, TStrV &FltAttrNames, TStrV &StrAttrNames) const
Fills each of the vectors with the names of edge attributes of the given type.
Definition: network.cpp:1357
int GetNodes() const
Returns the number of nodes in the graph.
Definition: network.h:1969
TPt< TIntNEDNet > PIntNEDNet
Definition: network.h:972
const TEdgeDat & GetOutEDat(const int &EdgeN) const
Definition: network.h:1106
int GetSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, TInt &ValX) const
Gets Int sparse attribute with id AttrId from NodeI.
Definition: network.h:3573
void SetNDat(const int &NId, const TNodeData &NodeDat)
Sets node data for the node of ID NId in the network.
Definition: network.h:1389
bool IsKeyIdEqKeyN() const
Definition: hash.h:191
TPt< TIntFltNEDNet > PIntFltNEDNet
Definition: network.h:974
void SortEIdByDat(const bool &Asc=true)
Sorts edges by edge data.
Definition: network.h:1294
int GetSAttrIdN(const TStr &Name, TInt &AttrIdX, TAttrType &AttrTypeX) const
Gets id and type for attribute with name Name.
Definition: network.cpp:2468
THash< TInt, TNode >::TIter THashIter
Definition: network.h:3300
int GetSAttrVN(const TInt &NId, const TAttrType AttrType, TAttrPrV &AttrV) const
Gets a list of all sparse attributes of type AttrType for node with id NId.
Definition: network.cpp:2448
int GetSAttrIdE(const TStr &Name, TInt &AttrIdX, TAttrType &AttrTypeX) const
Gets id and type for attribute with name Name.
Definition: network.cpp:2609
#define IAssertR(Cond, Reason)
Definition: bd.h:265
int GetOutNId(const int &EdgeN) const
Returns ID of EdgeN-th out-node (the node the current node points to).
Definition: network.h:1066
int GetSrcNId() const
Definition: network.h:1627
TNodeData TNodeDat
Definition: network.h:19
TStr GetStrAttrDatN(const TNodeI &NodeI, const TStr &attr)
Gets the value of str attr from the node attr value vector.
Definition: network.h:2308
THash< TStr, TFlt > FltDefaultsE
Definition: network.h:1869
TNode(TSIn &SIn)
Definition: network.h:998
int AppendIntVAttrDatN(const TNodeI &NodeI, const TInt &value, const TStr &attr)
Appends value onto the TIntV attribute for the given node.
Definition: network.h:2275
virtual void Save(TSOut &SOut) const
Saves the network to a (binary) stream SOut.
Definition: network.h:594
int AddSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, const TInt &Val)
Adds Int sparse attribute with id AttrId to EdgeI.
Definition: network.h:3140
int GetDeg() const
Returns degree of the current node.
Definition: network.h:70
int AddFltAttrDatE(const TEdgeI &EdgeI, const TFlt &value, const TStr &attr)
Attribute based add function for attr to Flt value.
Definition: network.h:2293
bool IsOutNId(const int &NId) const
Tests whether the current node points to node with ID NId.
Definition: network.h:2824
TNode(const int &NId, const TNodeData &NodeData)
Definition: network.h:996
int GetOutNId(const int &EdgeN) const
Returns ID of EdgeN-th out-node (the node the current node points to).
Definition: network.h:1661
int GetDeg() const
Definition: network.h:36
TDirNet(const TDirNet &Graph)
Definition: network.h:3378
TNode & GetNode(const int &NId)
Definition: network.h:133
TAStrI GetNAStrI(const TStr &attr, const int &NId) const
Returns an iterator referring to the node of ID NId in the graph.
Definition: network.h:2021
void Save_V1(TSOut &SOut) const
Saves the network to a (binary) stream SOut. Available for backwards compatibility.
Definition: network.h:3384
TStr GetEdgeAttrValue(const int &EId, const TStrIntPrH::TIter &EdgeHI) const
Returns edge attribute value, converted to Str type.
Definition: network.cpp:367
THash< TInt, TNode > NodeH
Definition: network.h:2854
int GetOutDeg() const
Returns out-degree of the current node.
Definition: network.h:1653
TEdgeI(const TNodeI &NodeI, const TNodeI &EndNodeI, const int &EdgeN=0)
Definition: network.h:113
int GetSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from NodeI.
Definition: network.h:3060
enum TAttrType_ TAttrType
Types for tables, sparse and dense attributes.
TEdgeI BegEI() const
Returns an iterator referring to the first edge in the network.
Definition: network.h:1251
int GetSAttrIdN(const TStr &Name, TInt &AttrIdX, TAttrType &AttrTypeX) const
Gets id and type for attribute with name Name.
Definition: network.cpp:1980
const TNodeData & GetNDat(const int &NId) const
Returns node data for the node of ID NId in the network.
Definition: network.h:1210
const TNodeData & GetDat() const
Definition: network.h:469
TNode(TSIn &SIn)
Definition: network.h:2761
TVec< TStrV > VecOfStrVecsE
Definition: network.h:1871
TCRef CRef
Definition: network.h:582
THash< TStr, TInt > IntDefaultsE
Definition: network.h:1867
int GetInNId(const int &EdgeN) const
Returns ID of EdgeN-th in-node (the node pointing to the current node).
Definition: network.h:1062
void Save(TSOut &SOut) const
Definition: network.h:999
int GetSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, TFlt &ValX) const
Gets Flt sparse attribute with id AttrId from NodeI.
Definition: network.h:3587
TNodeEDatNet & operator=(const TNodeEDatNet &NodeNet)
Definition: network.h:601
TCRef CRef
Definition: network.h:3366
const TNodeData & operator()() const
Definition: network.h:526
int GetIntAttrIndN(const TStr &attr)
Gets the index of the node attr value vector specified by attr (same as GetAttrIndN for compatibility...
Definition: network.cpp:1066
void Save(TSOut &SOut) const
Definition: network.h:1605
bool NodeAttrIsStrDeleted(const int &NId, const TStrIntPrH::TIter &NodeHI) const
Returns true if NId attr deleted value for current node str attr iterator.
Definition: network.cpp:177
void Save_V1(TSOut &SOut) const
Saves the graph to a (binary) stream SOut. Available for backwards compatibility. ...
Definition: network.h:1930
int AddNode(const TNodeI &NodeI)
Adds a node NodeI and its node data to the network.
Definition: network.h:619
TFlt GetWeightOutEdges(const TNodeI &NI, const TStr &attr)
Gets the sum of the weights of all the outgoing edges of the node.
Definition: network.cpp:1371
int DelAttrN(const TStr &attr)
Removes all the values for node attr.
Definition: network.cpp:1283
TNode(const TNode &Node)
Definition: network.h:2760
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:3442
TNode & GetNode(const int &NId)
Definition: network.h:3372
int GetId() const
Returns edge ID. Always returns -1 since only edges in multigraphs have explicit IDs.
Definition: network.h:3358
int GetSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, TStr &ValX) const
Gets Str sparse attribute with name AttrName from EdgeI.
Definition: network.h:3715
int GetInNId(const int &NodeN) const
Returns ID of NodeN-th in-node (the node pointing to the current node).
Definition: network.h:510
int AddEdge(const TEdgeI &EdgeI)
Adds an edge from EdgeI.GetSrcNId() to EdgeI.GetDstNId() and its edge data to the network...
Definition: network.h:1234
bool NodeAttrIsDeleted(const int &NId, const TStrIntPrH::TIter &NodeHI) const
Returns true if NId attr deleted for current node attr iterator.
Definition: network.cpp:153
int GetOutDeg() const
Returns out-degree of the current node (returns same as value GetDeg() since the network is undirecte...
Definition: network.h:2805
int DelSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId)
Deletes sparse attribute with id AttrId from EdgeI.
Definition: network.h:2682
int GetSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, TFlt &ValX) const
Gets Flt sparse attribute with name AttrName from NodeI.
Definition: network.h:3583
void SortNIdById(const bool &Asc=true)
Sorts nodes by node IDs.
Definition: network.h:1288
bool Empty() const
Tests whether the network is empty (has zero nodes).
Definition: network.h:238
int GetInNId(const int &NodeN) const
Definition: network.h:41
int GetInNId(const int &NodeN) const
Definition: network.h:2767
void Reserve(const int &Nodes, const int &Edges)
Reserves memory for a network of Nodes nodes and Edges edges.
Definition: network.h:1285
TEdgeI GetEI(const int &EId) const
Returns an iterator referring to edge with edge ID EId.
Definition: network.h:2210
void DelNode(const int &NId)
Deletes node of ID NId from the network.
Definition: network.h:785
TNodeData & GetDat()
Definition: network.h:1082
int AddSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to EdgeI.
Definition: network.h:2594
int GetEdges() const
Returns the number of edges in the network.
Definition: network.h:805
void DelEdge(const int &SrcNId, const int &DstNId, const bool &IsDir=true)
Deletes an edge from node IDs SrcNId to DstNId from the network.
Definition: network.h:343
int AddEdge(const TEdgeI &EdgeI)
Adds an edge between EdgeI.GetSrcNId() and EdgeI.GetDstNId() to the graph.
Definition: network.h:2188
int GetSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, TInt &ValX) const
Gets Int sparse attribute with id AttrId from NodeI.
Definition: network.h:3064
bool operator<(const TEdgeI &EdgeI) const
Definition: network.h:119
Definition: dt.h:11
TAFltI & operator++(int)
Definition: network.h:1835
const TNode & GetNode(const int &NId) const
Returns node element for the node of ID NId in the network.
Definition: network.h:190
bool IsStrAttrDeletedN(const int &NId, const TStr &attr) const
Returns true if Str attr exists for node NId and has default value.
Definition: network.cpp:145
Definition: attr.h:90
bool IsNbrEId(const int &EId) const
Definition: network.h:1012
TEdgeI(const THashIter &EdgeHIter, const TNEANet *GraphPt)
Definition: network.h:1714
TPt< TStrIntNEDNet > PStrIntNEDNet
Definition: network.h:976
THash< TInt, TNode >::TIter THashIter
Definition: network.h:486
TNodeData & GetNDat(const int &NId)
Returns node data for the node of ID NId in the network.
Definition: network.h:639
int AddEdge(const TEdgeI &EdgeI)
Adds an edge from EdgeI.GetSrcNId() to EdgeI.GetDstNId() to the network.
Definition: network.h:3465
void Del(const TSizeTy &ValN)
Removes the element at position ValN.
Definition: ds.h:1130
Edge iterator. Only forward iteration (operator++) is supported.
Definition: network.h:2830
TEdgeI EndEI() const
Returns an iterator referring to the past-the-end edge in the network.
Definition: network.h:677
int GetIdVSAttrN(const TStr &AttrName, TIntV &IdV) const
Gets a list of all nodes that have a sparse attribute with name AttrName.
Definition: network.cpp:1968
THashIter EdgeHI
Definition: network.h:1116
void AttrNameEI(const TInt &EId, TStrV &Names) const
Returns a vector of attr names for edge EId.
Definition: network.h:2080
static const T & Mx(const T &LVal, const T &RVal)
Definition: xmath.h:32
int GetSAttrVE(const TEdgeI &EdgeI, const TAttrType AttrType, TAttrPrV &AttrV) const
Gets a list of all sparse attributes of type AttrType for EdgeI.
Definition: network.h:3230
int GetOutNId(const int &NodeN) const
Definition: network.h:3287
void SortNIdByDat(const bool &Asc=true)
Sorts nodes by node data.
Definition: network.h:247
TNodeData & GetOutNDat(const int &NodeN)
Definition: network.h:100
int GetSAttrNameE(const TInt &AttrId, TStr &NameX, TAttrType &AttrTypeX) const
Gets name and type for attribute with id AttrId.
Definition: network.cpp:2613
int GetNbrNId(const int &NodeN) const
Returns ID of NodeN-th neighboring node.
Definition: network.h:2820
TStrVecIter HI
Definition: network.h:1797
void GetNIdV(TIntV &NIdV) const
Returns a vector of all node IDs in the network.
Definition: network.h:1484
int GetSAttrVE(const TInt &EId, const TAttrType AttrType, TAttrPrV &AttrV) const
Gets a list of all sparse attributes of type AttrType for edge with id EId.
Definition: network.cpp:1629
const TNodeData & GetDat() const
Definition: network.h:39
int GetSAttrNameE(const TInt &AttrId, TStr &NameX, TAttrType &AttrTypeX) const
Gets name and type for attribute with id AttrId.
Definition: network.cpp:1653
int GetId() const
Returns ID of the current node.
Definition: network.h:2799
void Save(TSOut &SOut) const
Definition: dt.h:1060
static PNEANet Load(TSIn &SIn)
Static constructor that loads the graph from a stream SIn and returns a pointer to it...
Definition: network.h:1946
TEdgeData & GetInEDat(const int &EdgeN)
Definition: network.h:539
int GetSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, TStr &ValX) const
Gets Str sparse attribute with id AttrId from EdgeI.
Definition: network.h:3719
TNode & GetNode(const int &NId)
Definition: network.h:1840
TNodeI BegNI() const
Returns an iterator referring to the first node in the network.
Definition: network.h:1200
int AddNode(const TNodeI &NodeI)
Definition: network.h:1190
void StrAttrNameNI(const TInt &NId, TStrV &Names) const
Returns a vector of str attr names for node NId.
Definition: network.h:2063
TNodeI(const TNodeI &NodeI)
Definition: network.h:1640
int AddSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to EdgeI.
Definition: network.h:3136
int AddSAttrDatE(const TInt &EId, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to the given edge with id EId.
Definition: network.cpp:1531
void DelNode(const TNode &NodeI)
Deletes node of ID NodeI.GetId() from the network.
Definition: network.h:625
void FltAttrNameNI(const TInt &NId, TStrV &Names) const
Returns a vector of int attr names for node NId.
Definition: network.h:2071
bool IsInEId(const int &EId) const
Tests whether the edge with ID EId is an in-edge of current node.
Definition: network.h:1679
TNodeI(const THashIter &NodeHIter, const TNodeEdgeNet *NetPt)
Definition: network.h:1044
TPt< TUndirNet > PNet
Definition: network.h:2751
void IntVAttrValueEI(const TInt &EId, TVec< TIntV > &Values) const
Returns a vector of attr values for edge EId.
Definition: network.h:2102
bool operator<(const TNodeI &NodeI) const
Definition: network.h:1049
void ReserveNIdInDeg(const int &NId, const int &InDeg)
Reserves memory for node ID NId having InDeg in-edges.
Definition: network.h:3497
int AddNode(int NId=-1)
Adds a node of ID NId to the network.
Definition: network.h:755
Directed network.
Definition: network.h:3267
TAttrPair SAttrE
Definition: network.h:3370
void Save(TSOut &SOut) const
Saves the network to a (binary) stream SOut. Expects data structures for sparse attributes.
Definition: network.h:2871
bool EdgeAttrIsFltDeleted(const int &EId, const TStrIntPrH::TIter &EdgeHI) const
Returns true if EId attr deleted for current edge flt attr iterator.
Definition: network.cpp:361
bool IsOutNId(const int &NId) const
Definition: network.h:477
virtual ~TNodeEDatNet()
Definition: network.h:592
int AddIntVAttrN(const TStr &attr)
Adds a new IntV node attribute to the hashmap.
Definition: network.cpp:1162
void PackOutNIdV()
Definition: network.h:3292
const TNodeData & GetOutNDat(const int &EdgeN) const
Definition: network.h:1085
TInt GetIntAttrDefaultE(const TStr &attribute) const
Gets Int edge attribute val. If not a proper attr, return default.
Definition: network.h:1853
bool IsNbrNId(const int &NId) const
Tests whether node with ID NId is a neighbor of the current node.
Definition: network.h:92
TNodeData & GetDat()
Definition: network.h:40
bool EdgeAttrIsDeleted(const int &EId, const TStrIntPrH::TIter &EdgeHI) const
Returns true if EId attr deleted for current edge attr iterator.
Definition: network.cpp:335
TNodeI(const TNodeI &NodeI)
Definition: network.h:492
TNodeEdgeNet< TFlt, TFlt > TFltNENet
Definition: network.h:1567
bool IsEdge(const int &SrcNId, const int &DstNId, const bool &IsDir=true) const
Tests whether an edge between node IDs SrcNId and DstNId exists in the graph.
Definition: network.h:2200
TFlt GetFltAttrDatE(const TEdgeI &EdgeI, const TStr &attr)
Gets the value of flt attr from the edge attr value vector.
Definition: network.h:2344
bool operator<(const TEdgeI &EdgeI) const
Definition: network.h:559
TEdgeI(const TEdgeI &EdgeI)
Definition: network.h:2837
TNodeEDatNet(const int &Nodes, const int &Edges)
Constructor that reserves enough memory for a network of Nodes nodes and Edges edges.
Definition: network.h:588
bool IsInNId(const int &NId) const
Definition: network.h:3289
THash< TInt, TNode >::TIter THashIter
Definition: network.h:1634
TNodeData & GetDat()
Definition: network.h:1006
TPt< TIntNENet > PIntNENet
Definition: network.h:1566
void DelEdge(const int &SrcNId, const int &DstNId, const bool &IsDir=true)
Deletes an edge from node IDs SrcNId to DstNId from the network.
Definition: network.h:831
int GetSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, TStr &ValX) const
Gets Str sparse attribute with id AttrId from EdgeI.
Definition: network.h:3210
int AddSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, const TInt &Val)
Adds Int sparse attribute with id AttrId to EdgeI.
Definition: network.h:3649
Tests (at compile time) if the graph is directed.
Definition: gbase.h:28
const TNEANet * Graph
Definition: network.h:1711
int AddIntVAttrDatE(const TEdgeI &EdgeI, const TIntV &value, const TStr &attr)
Attribute based add function for attr to IntV value.
Definition: network.h:2298
int GetInNId(const int &EdgeN) const
Returns ID of EdgeN-th in-node (the node pointing to the current node).
Definition: network.h:1657
TIter BegI() const
Definition: hash.h:171
TPt< TFltNNet > PFltNNet
Definition: network.h:437
bool operator<(const TNodeI &NodeI) const
Definition: network.h:64
bool IsAttrDeletedE(const int &EId, const TStr &attr) const
Returns true if attr exists for edge EId and has default value.
Definition: network.cpp:311
const TEdge & GetEdgeKId(const int &EdgeKeyId) const
Definition: network.h:1149
bool IsFltAttrDeletedE(const int &EId, const TStr &attr) const
Returns true if Flt attr exists for edge NId and has default value.
Definition: network.cpp:331
const TNode & GetNode(const int &NId) const
Definition: network.h:1145
int AddSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, const TFlt &Val)
Adds Flt sparse attribute with id AttrId to EdgeI.
Definition: network.h:3663
bool IsNbrNId(const int &NId) const
Tests whether node with ID NId is a neighbor of the current node.
Definition: network.h:3339
TPt< TDirNet > PNet
Definition: network.h:3270
bool IsInNId(const int &NId) const
Tests whether node with ID NId points to the current node.
Definition: network.h:520
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
int GetInDeg() const
Returns in-degree of the current node.
Definition: network.h:3319
TNodeI GetRndNI(TRnd &Rnd=TInt::Rnd)
Returns an interator referring to a random node in the network.
Definition: network.h:1270
TNode(const TNode &Node)
Definition: network.h:462
void GetFltAttrVal(TFltV &Val) const
Gets vector of flt attribute values.
Definition: network.h:1746
TEdgeI(const TEdgeI &EdgeI)
Definition: network.h:554
const TNEANet * Graph
Definition: network.h:1636
bool IsOutNId(const int &NId) const
Tests whether the current node points to node with ID NId.
Definition: network.h:3337
bool EdgeAttrIsIntDeleted(const int &EId, const TStrIntPrH::TIter &EdgeHI) const
Returns true if EId attr deleted for current edge int attr iterator.
Definition: network.cpp:343
int AddSAttrDatN(const TInt &NId, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to the given node with id NId.
Definition: network.cpp:2350
int GetDeg() const
Definition: network.h:1002
void SetEDat(const int &SrcNId, const int &DstNId, const TEdgeData &EdgeDat)
Sets edge data for the edge between nodes SrcNId and DstNId in the network.
Definition: network.h:853
bool operator<(const TNode &Node) const
Definition: network.h:1000
void Save(TSOut &SOut) const
Definition: hash.h:141
virtual ~TNodeEdgeNet()
Definition: network.h:1162
int GetMxNId() const
Returns an ID that is larger than any node ID in the network.
Definition: network.h:1212
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:1198
TEdge(const int &EId, const int &SourceNId, const int &DestNId, const TEdgeData &EdgeData)
Definition: network.h:1023
int DelAttrE(const TStr &attr)
Removes all the values for edge attr.
Definition: network.cpp:1309
TNodeEdgeNet(const TNodeEdgeNet &Net)
Definition: network.h:1159
void StrAttrValueNI(const TInt &NId, TStrV &Values) const
Returns a vector of attr values for node NId.
Definition: network.h:2067
static PNet New()
Static constructor that returns a pointer to the network. Call: TPt > Net = TNod...
Definition: network.h:151
int GetSAttrNameN(const TInt &AttrId, TStr &NameX, TAttrType &AttrTypeX) const
Gets name and type for attribute with id AttrId.
Definition: network.cpp:1984
TIntV GetIntVAttrDatE(const TEdgeI &EdgeI, const TStr &attr)
Gets the value of the intv attr from the edge attr value vector.
Definition: network.h:2347
const TNodeData & GetInNDat(const int &NodeN) const
Definition: network.h:97
int GetNodes() const
Returns the number of nodes in the network.
Definition: network.h:1175
TNodeI & operator++(int)
Increment iterator.
Definition: network.h:1048
TStrIntPrH KeyToIndexTypeE
Definition: network.h:1865
const TNodeData & GetInNDat(const int &NodeN) const
Definition: network.h:532
TEdgeData & GetOutEDat(const int &EdgeN)
Definition: network.h:474
int GetSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, TInt &ValX) const
Gets Int sparse attribute with id AttrId from EdgeI.
Definition: network.h:3182
int GetSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from EdgeI.
Definition: network.h:3178
TStr GetStrAttrDatE(const TEdgeI &EdgeI, const TStr &attr)
Gets the value of str attr from the edge attr value vector.
Definition: network.h:2341
Edge iterator. Only forward iteration (operator++) is supported.
Definition: network.h:107
int GetNbrNId(const int &NodeN) const
Definition: network.h:2769
void SetAllEDat(const TEdgeData &EdgeDat)
Sets edge data for all the edges in the network to EDat.
Definition: network.h:882
bool IsInNId(const int &NId) const
Definition: network.h:44
TEdgeData EdgeDat
Definition: network.h:1019
void Save(TSOut &SOut) const
Saves the network to a (binary) stream SOut. Expects data structures for sparse attributes.
Definition: network.h:3382
TNodeI & operator=(const TNodeI &NodeI)
Definition: network.h:61
TEdgeI GetEI(const int &SrcNId, const int &DstNId) const
Returns an iterator referring to edge (SrcNId, DstNId) in the graph.
Definition: network.h:2212
TNodeI EndNI() const
Returns an iterator referring to the past-the-end node in the network.
Definition: network.h:186
TNodeI(const TNodeI &NodeI)
Definition: network.h:60
int GetEdges() const
Returns the number of edges in the network.
Definition: network.h:326
int GetRndEId(TRnd &Rnd=TInt::Rnd)
Returns an ID of a random edge in the graph.
Definition: network.h:2219
int GetSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, TFlt &ValX) const
Gets Flt sparse attribute with id AttrId from NodeI.
Definition: network.h:3078
bool IsOutEId(const int &EId) const
Tests whether the edge with ID EId is an out-edge of current node.
Definition: network.h:1099
int GetOutEId(const int &EdgeN) const
Returns ID of EdgeN-th out-edge.
Definition: network.h:1675
int GetSAttrDatN(const TInt &NId, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from node with id NId.
Definition: network.cpp:2392
TNode(TSIn &SIn)
Definition: network.h:33
THash< TInt, TNode > NodeH
Definition: network.h:138
TAttr SAttrN
Definition: network.h:1876
Node iterator. Only forward iteration (operator++) is supported.
Definition: network.h:3298
TStr GetDat() const
Returns an attribute of the node.
Definition: network.h:1809
int GetOutNId(const int &NodeN) const
Definition: network.h:42
TFltVecIter HI
Definition: network.h:1820
TEdge(const TEdge &Edge)
Definition: network.h:1623
TNodeData & GetNbrNDat(const int &NodeN)
Definition: network.h:535
TNodeI & operator++(int)
Increment iterator.
Definition: network.h:63
TCRef CRef
Definition: network.h:1151
TInt GetDat() const
Returns an attribute of the node.
Definition: network.h:1766
int GetOutDeg() const
Definition: network.h:1004
TVec< TIntV >::TIter TIntVVecIter
Definition: network.h:1775
bool IsNbrNId(const int &NId) const
Definition: network.h:478
THash< TStr, TFlt > FltDefaultsN
Definition: network.h:1869
void SortNIdById(const bool &Asc=true)
Sorts nodes by node IDs.
Definition: network.h:710
void Reserve(const int &Nodes, const int &Edges)
Reserves memory for a network of Nodes nodes and Edges edges.
Definition: network.h:2986
TEdgeI GetRndEI(TRnd &Rnd=TInt::Rnd)
Returns an interator referring to a random edge in the graph.
Definition: network.h:2221
const TEdge & GetEdge(const int &EId) const
Definition: network.h:1148
bool IsEdge(const int &EId) const
Tests whether an edge with edge ID EId exists in the graph.
Definition: network.h:2198
TEdgeData TEdgeDat
Definition: network.h:447
const TNodeData & GetNbrNDat(const int &NodeN) const
Definition: network.h:534
int GetUniqEdges(const bool &IsDir=true) const
Returns the number of edges in the network with a unique pair of nodes.
Definition: network.h:1395
TNodeEDatNet< TInt, TFlt > TIntFltNEDNet
Definition: network.h:973
int AddNode(int NId=-1)
Adds a node of ID NId to the network.
Definition: network.h:1345
TAttr SAttrN
Definition: network.h:3369
TNodeData & GetNbrNDat(const int &EdgeN)
Definition: network.h:1088
TNodeData & GetInNDat(const int &NodeN)
Definition: network.h:533
const TNEANet * Graph
Definition: network.h:1779
void IntAttrValueEI(const TInt &EId, TIntV &Values) const
Returns a vector of attr values for edge EId.
Definition: network.h:2092
TEdgeI GetEI(const int &EId) const
Not supported/implemented!
static PUndirNet GetSmallGraph()
Returns a small network on 5 nodes and 5 edges.
Definition: network.cpp:1853
int AddIntAttrDatE(const TEdgeI &EdgeI, const TInt &value, const TStr &attr)
Attribute based add function for attr to Int value.
Definition: network.h:2283
TInt MxNId
Definition: network.h:1861
TIntV OutEIdV
Definition: network.h:1599
void ReserveNIdOutDeg(const int &NId, const int &OutDeg)
Reserves memory for node ID NId having OutDeg out-edges.
Definition: network.h:3499
int GetNbrNId(const int &EdgeN) const
Returns ID of EdgeN-th neighboring node.
Definition: network.h:1070
int AddSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, const TStr &Val)
Adds Str sparse attribute with id AttrId to EdgeI.
Definition: network.h:3168
int AddSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, const TInt &Val)
Adds Int sparse attribute with id AttrId to NodeI.
Definition: network.h:3531
TEdgeI(const TNodeI &NodeI, const TNodeI &EndNodeI, const int &EdgeN=0)
Definition: network.h:3349
TNodeData & GetNDat(const int &NId)
Returns node data for the node of ID NId in the network.
Definition: network.h:1208
TFlt GetDat() const
Returns an attribute of the node.
Definition: network.h:1832
int GetDeg() const
Definition: network.h:3283
int GetDeg() const
Returns degree of the current node, the sum of in-degree and out-degree.
Definition: network.h:3317
TNodeData & GetNDat(const int &NId)
Returns node data for the node of ID NId in the network.
Definition: network.h:194
bool IsOutEId(const int &EId) const
Definition: network.h:1614
TAIntI BegNAIntI(const TStr &attr) const
Returns an iterator referring to the first node's int attribute.
Definition: network.h:1993
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:220
int AddSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, const TFlt &Val)
Adds Flt sparse attribute with name AttrName to NodeI.
Definition: network.h:3032
TIntV GetIntVAttrDatN(const TNodeI &NodeI, const TStr &attr) const
Gets the value of the intv attr from the node attr value vector.
Definition: network.h:2314
Node iterator. Only forward iteration (operator++) is supported.
Definition: network.h:1632
Node/edge integer attribute iterator. Iterates through all nodes/edges for one integer attribute...
Definition: network.h:1751
int GetInNId(const int &EdgeN) const
Definition: network.h:471
TAFltI(const TAFltI &I)
Definition: network.h:1827
void AttrValueNI(const TInt &NId, TStrV &Values) const
Returns a vector of attr values for node NId.
Definition: network.h:2038
int GetSrcNId() const
Gets the source node of an edge.
Definition: network.h:124
TEdgeData & operator()()
Definition: network.h:567
void GetStrAttrNames(TStrV &Names) const
Gets vector of str attribute names.
Definition: network.h:1740
bool GetEDat(const int &SrcNId, const int &DstNId, TEdgeData &EdgeDat) const
Returns edge data in Data for the edge from node IDs SrcNId to DstNId.
Definition: network.h:860
TVec< TIntV > VecOfIntVecsE
Definition: network.h:1870
TIter EndI() const
Definition: hash.h:176
void Defrag(const bool &OnlyNodeLinks=false)
Defragments the network.
Definition: network.h:1500
TNodeI & operator=(const TNodeI &NodeI)
Definition: network.h:1046
const TEdgeData & GetInEDat(const int &EdgeN) const
Definition: network.h:540
int DelSAttrDatN(const TNodeI &NodeI, const TStr &AttrName)
Deletes sparse attribute with name AttrName from NodeI.
Definition: network.h:3102
bool IsNbrEId(const int &EId) const
Tests whether the edge with ID EId is an in or out-edge of current node.
Definition: network.h:1683
void IntAttrNameNI(const TInt &NId, TStrV &Names) const
Returns a vector of int attr names for node NId.
Definition: network.h:2043
int GetSrcNId() const
Gets the source node of an edge.
Definition: network.h:564
TNodeData NodeDat
Definition: network.h:26
TAIntVI EndNAIntVI(const TStr &attr) const
Returns an iterator referring to the past-the-end node's attribute.
Definition: network.h:2006
TNodeI GetRndNI(TRnd &Rnd=TInt::Rnd)
Returns an interator referring to a random node in the network.
Definition: network.h:233
TNode(const int &NId)
Definition: network.h:3278
int GetNodes() const
Returns the number of nodes in the network.
Definition: network.h:160
int GetInDeg() const
Definition: network.h:3284
bool IsNbrNId(const int &NId) const
Definition: network.h:3291
static PUndirNet New(const int &Nodes, const int &Edges)
Static constructor that returns a pointer to the network and reserves enough memory for Nodes nodes a...
Definition: network.h:2880
bool IsNbrNId(const int &NId) const
Definition: network.h:46
TEdgeI GetEI(const int &EId) const
Not supported/implemented!
Definition: network.h:1255
TNodeData NodeDat
Definition: network.h:992
static TRnd Rnd
Definition: dt.h:1053
TAFltI GetEAFltI(const TStr &attr, const int &EId) const
Returns an iterator referring to the edge of ID EId in the graph.
Definition: network.h:2170
TNodeI BegNI() const
Returns an iterator referring to the first node in the network.
Definition: network.h:184
int GetNbrEId(const int &EdgeN) const
Definition: network.h:1612
int AddSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, const TInt &Val)
Adds Int sparse attribute with id AttrId to NodeI.
Definition: network.h:2480
bool IsDeleted() const
Returns true if the attribute has been deleted.
Definition: network.h:1834
TDirNet TNet
Definition: network.h:3269
int GetSAttrDatN(const TInt &NId, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from node with id NId.
Definition: network.cpp:1447
int GetInDeg() const
Returns in-degree of the current node.
Definition: network.h:504
TAFltI BegEAFltI(const TStr &attr) const
Returns an iterator referring to the first edge's flt attribute.
Definition: network.h:2162
bool NodeAttrIsIntVDeleted(const int &NId, const TStrIntPrH::TIter &NodeHI) const
Returns true if NId attr deleted value for current node int vector attr iterator. ...
Definition: network.cpp:169
void SetNDat(const int &NId, const TNodeData &NodeDat)
Sets node data for the node of ID NId in the network.
Definition: network.h:320
TAStrI GetEAStrI(const TStr &attr, const int &EId) const
Returns an iterator referring to the edge of ID EId in the graph.
Definition: network.h:2158
Node/edge float attribute iterator. Iterates through all nodes/edges for one float attribute...
Definition: network.h:1817
int AddNode(const TNodeI &NodeI)
Adds a node of ID NodeI.GetId() to the graph.
Definition: network.h:1977
int GetSAttrNameN(const TInt &AttrId, TStr &NameX, TAttrType &AttrTypeX) const
Gets name and type for attribute with id AttrId.
Definition: network.cpp:2472
TIntV InNIdV
Definition: network.h:27
Node Edge Network (directed multigraph, TNEGraph with data on nodes and edges).
Definition: network.h:981
int GetSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, TFlt &ValX) const
Gets Flt sparse attribute with id AttrId from EdgeI.
Definition: network.h:3705
int GetId() const
Returns edge ID.
Definition: network.h:1722
static PUndirNet Load(TSIn &SIn)
Static constructor that loads the network from a stream SIn and returns a pointer to it...
Definition: network.h:2882
void PackNIdV()
Definition: network.h:3293
int GetOutNId(const int &EdgeN) const
Definition: network.h:472
TSizeTy AddSorted(const TVal &Val, const bool &Asc=true, const TSizeTy &_MxVals=-1)
Adds element Val to a sorted vector.
Definition: ds.h:1063
void ErrNotify(const char *NotifyCStr)
Definition: bd.h:74
TNodeEDatNet< TInt, TInt > TIntNEDNet
Definition: network.h:971
void Defrag()
Definition: hash.h:513
bool IsOutEId(const int &EId) const
Definition: network.h:1011
TAIntI BegEAIntI(const TStr &attr) const
Returns an iterator referring to the first edge's int attribute.
Definition: network.h:2125
int GetNbrNId(const int &NodeN) const
Definition: network.h:3288
virtual void Save(TSOut &SOut) const
Saves the network to a (binary) stream SOut.
Definition: network.h:1164
const TNodeData & GetNDat(const int &NId) const
Returns node data for the node of ID NId in the network.
Definition: network.h:196
int DelSAttrDatN(const TNodeI &NodeI, const TStr &AttrName)
Deletes sparse attribute with name AttrName from NodeI.
Definition: network.h:3611
bool operator==(const TEdgeI &EdgeI) const
Definition: network.h:560
Definition: dt.h:1293
TEdge(const int &EId, const int &SourceNId, const int &DestNId)
Definition: network.h:1022
TVec< TStrV > VecOfStrVecsN
Definition: network.h:1871
void GetStrAttrVal(TStrV &Val) const
Gets vector of str attribute values.
Definition: network.h:1742
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:182
TPt< TNet > PNet
Definition: network.h:449
TNodeEDatNet(const TNodeEDatNet &NodeNet)
Definition: network.h:589
int GetNbrNId(const int &NodeN) const
Returns ID of NodeN-th neighboring node.
Definition: network.h:518
Definition: fl.h:58
bool IsIntAttrDeletedE(const int &EId, const TStr &attr) const
Returns true if Int attr exists for edge EId and has default value.
Definition: network.cpp:319
void Save(TSOut &SOut) const
Definition: ds.h:903
TEdgeI & operator++(int)
Increment iterator.
Definition: network.h:117
TNodeI GetNI(const int &NId) const
Returns an iterator referring to the node of ID NId in the network.
Definition: network.h:188
int AddEdge(const int &SrcNId, const int &DstNId, int EId=-1)
Adds an edge between node IDs SrcNId and DstNId to the graph.
Definition: network.h:1407
int GetDeg() const
Returns degree of the current node, the sum of in-degree and out-degree.
Definition: network.h:1649
int GetSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, TStr &ValX) const
Gets Str sparse attribute with id AttrId from NodeI.
Definition: network.h:2550
void Dump(FILE *OutF=stdout) const
Print the graph in a human readable form to an output stream OutF.
Definition: network.cpp:729
bool IsFltAttrDeletedN(const int &NId, const TStr &attr) const
Returns true if Flt attr exists for node NId and has default value.
Definition: network.cpp:149
void DelNode(const TNode &NodeI)
Deletes node of ID NodeI.GetId() from the network.
Definition: network.h:2930
int AddFltAttrDatN(const TNodeI &NodeI, const TFlt &value, const TStr &attr)
Attribute based add function for attr to Flt value.
Definition: network.h:2267
int GetInEId(const int &EdgeN) const
Returns ID of EdgeN-th in-edge.
Definition: network.h:1673
bool NodeAttrIsFltDeleted(const int &NId, const TStrIntPrH::TIter &NodeHI) const
Returns true if NId attr deleted value for current node flt attr iterator.
Definition: network.cpp:185
int DelSAttrDatN(const TNodeI &NodeI, const TInt &AttrId)
Deletes sparse attribute with id AttrId from NodeI.
Definition: network.h:3615
void IntVAttrValueNI(const TInt &NId, TVec< TIntV > &Values) const
Returns a vector of attr values for node NId.
Definition: network.h:2057
int GetInDeg() const
Returns in-degree of the current node.
Definition: network.h:72
TEdge(TSIn &SIn)
Definition: network.h:1025
bool IsOutNId(const int &NId) const
Tests whether the current node points to node with ID NId.
Definition: network.h:522
int AddSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, const TStr &Val)
Adds Str sparse attribute with id AttrId to NodeI.
Definition: network.h:3050
THash< TInt, TEdge > EdgeH
Definition: network.h:1863
void PackNIdV()
Definition: network.h:2774
static PNet New()
Static constructor that returns a pointer to the network. Call: TPt > Net = TNodeEDatNet::New().
Definition: network.h:596
int GetSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, TStr &ValX) const
Gets Str sparse attribute with name AttrName from EdgeI.
Definition: network.h:2664
TNodeI(const THashIter &NodeHIter)
Definition: network.h:3304
TAIntI GetEAIntI(const TStr &attr, const int &EId) const
Returns an iterator referring to the edge of ID EId in the graph.
Definition: network.h:2133
void GetAttrNNames(TStrV &IntAttrNames, TStrV &FltAttrNames, TStrV &StrAttrNames) const
Fills each of the vectors with the names of node attributes of the given type.
Definition: network.cpp:1343
int DelFromIntVAttrDatN(const TNodeI &NodeI, const TInt &value, const TStr &attr)
Deletes value from the TIntV attribute for the given node.
Definition: network.h:2278
int AddIntVAttrDatN(const TNodeI &NodeI, const TIntV &value, const TStr &attr)
Attribute based add function for attr to IntV value.
Definition: network.h:2272
const TNodeData & GetSrcNDat() const
Definition: network.h:572
TAStrI EndEAStrI(const TStr &attr) const
Returns an iterator referring to the past-the-end edge's attribute.
Definition: network.h:2154
int GetDstNId() const
Returns the destination of the edge.
Definition: network.h:1726
TNode(const int &NId, const TNodeData &NodeData)
Definition: network.h:461
int GetSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, TFlt &ValX) const
Gets Flt sparse attribute with id AttrId from EdgeI.
Definition: network.h:3196
int AddSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, const TFlt &Val)
Adds Flt sparse attribute with name AttrName to EdgeI.
Definition: network.h:2608
int GetId() const
Definition: network.h:465
int GetAttrIndN(const TStr &attr)
Gets the index of the node attr value vector specified by attr.
Definition: network.cpp:1070
const TEdgeData & GetOutEDat(const int &EdgeN) const
Definition: network.h:475
TNodeI BegNI() const
Returns an iterator referring to the first node in the network.
Definition: network.h:2934
TStr GetStrAttrIndDatE(const TEdgeI &EdgeI, const int &index)
Gets the value of a string edge attr specified by edge iterator EdgeI and the attr index...
Definition: network.h:2366
bool operator==(const TNodeI &NodeI) const
Definition: network.h:65
bool operator==(const TEdgeI &EdgeI) const
Definition: network.h:1125
int AddSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, const TFlt &Val)
Adds Flt sparse attribute with name AttrName to NodeI.
Definition: network.h:2490
int GetMxNId() const
Returns an ID that is larger than any node ID in the network.
Definition: network.h:2940
TEdgeI(const TEdgeI &EdgeI)
Definition: network.h:114
TAStrI BegEAStrI(const TStr &attr) const
Returns an iterator referring to the first edge's str attribute.
Definition: network.h:2151
virtual void DelNode(const int &NId)
Deletes node of ID NId from the network.
Definition: network.h:300
int AddEdge(const int &SrcNId, const int &DstNId)
Adds an edge from node IDs SrcNId to node DstNId to the network.
Definition: network.h:813
const TNodeData & GetDat() const
Definition: network.h:1081
TNodeData & GetInNDat(const int &EdgeN)
Definition: network.h:1084
const TNode & GetNode(const int &NId) const
Definition: network.h:3373
TAStrI EndNAStrI(const TStr &attr) const
Returns an iterator referring to the past-the-end node's attribute.
Definition: network.h:2018
void Save(TSOut &SOut) const
Definition: network.h:464
TAIntVI(const TAIntVI &I)
Definition: network.h:1783
bool IsStrAttrDeletedE(const int &EId, const TStr &attr) const
Returns true if Str attr exists for edge NId and has default value.
Definition: network.cpp:327
TEdgeI(const TNodeI &NodeI, const TNodeI &EndNodeI, const int &EdgeN=0)
Definition: network.h:553
TNodeData & GetInNDat(const int &NodeN)
Definition: network.h:98
THash< TInt, TNode > NodeH
Definition: network.h:584
void Clr()
Deletes all nodes and edges from the network.
Definition: network.h:3493
int AddEdge(const TEdgeI &EdgeI)
Adds an edge between EdgeI.GetSrcNId() and EdgeI.GetDstNId() to the network.
Definition: network.h:2953
THashIter NodeHI
Definition: network.h:55
TAttr SAttrE
Definition: network.h:1877
void DelKey(const TKey &Key)
Definition: hash.h:362
Edge iterator. Only forward iteration (operator++) is supported.
Definition: network.h:1113
Definition: attr.h:4
TAIntI EndNAIntI(const TStr &attr) const
Returns an iterator referring to the past-the-end node's attribute.
Definition: network.h:1996
TNodeEDatNet * Net
Definition: network.h:488
Edge iterator. Only forward iteration (operator++) is supported.
Definition: network.h:547
TUndirNet()
Definition: network.h:2863
int GetId() const
Returns ID of the current node.
Definition: network.h:1647
static const int Mn
Definition: dt.h:1048
void GetStrAttrVal(TStrV &Val) const
Gets vector of str attribute values.
Definition: network.h:1699
bool IsOutEId(const int &EId) const
Tests whether the edge with ID EId is an out-edge of current node.
Definition: network.h:1681
int GetSAttrVN(const TNodeI &NodeI, const TAttrType AttrType, TAttrPrV &AttrV) const
Gets a list of all sparse attributes of type AttrType for NodeI.
Definition: network.h:2571
TAIntI EndEAIntI(const TStr &attr) const
Returns an iterator referring to the past-the-end edge's attribute.
Definition: network.h:2129
int GetOutDeg() const
Returns out-degree of the current node.
Definition: network.h:506
TInt MxNId
Definition: network.h:1152
int GetRndNId(TRnd &Rnd=TInt::Rnd)
Returns an ID of a random node in the network.
Definition: network.h:2975
int GetSAttrVN(const TInt &NId, const TAttrType AttrType, TAttrPrV &AttrV) const
Gets a list of all sparse attributes of type AttrType for node with id NId.
Definition: network.cpp:1503
TAFltI BegNAFltI(const TStr &attr) const
Returns an iterator referring to the first node's flt attribute.
Definition: network.h:2024
TCRef CRef
Definition: network.h:136
void Clr(const bool &DoDel=true, const bool &ResetDat=true)
Deletes all nodes and edges from the network.
Definition: network.h:705
int GetOutNId(const int &NodeN) const
Definition: network.h:2768
const TNodeData & GetDat() const
Definition: network.h:95
int GetSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, TStr &ValX) const
Gets Str sparse attribute with id AttrId from EdgeI.
Definition: network.h:2668
int AddSAttrE(const TStr &Name, const TAttrType &AttrType, TInt &AttrId)
Adds mapping for sparse attribute with name Name and type AttrType.
Definition: network.cpp:1645
TNEANet(const TNEANet &Graph, bool modeSubGraph)
Definition: network.h:1904
int DelSAttrDatN(const TInt &NId, const TStr &AttrName)
Deletes sparse attribute with name AttrName from node with id NId.
Definition: network.cpp:1946
int GetSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, TInt &ValX) const
Gets Int sparse attribute with id AttrId from EdgeI.
Definition: network.h:3691
void Clr(const bool &DoDel=true, const TSizeTy &NoDelLim=-1)
Clears the contents of the vector.
Definition: ds.h:971
Node Edge Network (directed graph, TNGraph with data on nodes and edges).
Definition: network.h:444
TVec< TFltV > VecOfFltVecsE
Definition: network.h:1872
int GetInNId(const int &NodeN) const
Returns ID of NodeN-th in-node (the node pointing to the current node).
Definition: network.h:3325
int DelSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId)
Deletes sparse attribute with id AttrId from EdgeI.
Definition: network.h:3224
TNode & GetNode(const int &NId)
Definition: network.h:579
int GetFltKeyIdE(const int &EId)
Gets keyid for edge with id EId.
Definition: network.cpp:1034
int GetId() const
Definition: network.h:1001
TStrIntPrH KeyToIndexTypeN
KeyToIndexType[N|E]: Key->(Type,Index).
Definition: network.h:1865
TAFltI EndNAFltI(const TStr &attr) const
Returns an iterator referring to the past-the-end node's attribute.
Definition: network.h:2027
TNodeI GetNI(const int &NId) const
Returns an iterator referring to the node of ID NId in the network.
Definition: network.h:633
TNodeData & GetDstNDat()
Definition: network.h:1139
TInt GetIntAttrDatE(const TEdgeI &EdgeI, const TStr &attr)
Gets the value of int attr from the edge attr value vector.
Definition: network.h:2338
virtual void Save(TSOut &SOut) const
Saves the network to a (binary) stream SOut.
Definition: network.h:149
bool IsInNId(const int &NId) const
Tests whether node with ID NId points to the current node.
Definition: network.h:2822
void Save(TSOut &SOut) const
Saves the attributes to a (binary) stream SOut.
Definition: attr.h:110
int AddStrAttrDatN(const TNodeI &NodeI, const TStr &value, const TStr &attr)
Attribute based add function for attr to Str value.
Definition: network.h:2262
TNodeI GetNI(const int &NId) const
Returns an iterator referring to the node of ID NId in the network.
Definition: network.h:3448
int DelSAttrDatN(const TNodeI &NodeI, const TInt &AttrId)
Deletes sparse attribute with id AttrId from NodeI.
Definition: network.h:3106
int AddSAttrDatN(const TInt &NId, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to the given node with id NId.
Definition: network.cpp:1862
void Gen(const int &ExpectVals)
Definition: hash.h:180
TUndirNet TNet
Definition: network.h:2750
void StrAttrValueEI(const TInt &EId, TStrV &Values) const
Returns a vector of attr values for node NId.
Definition: network.h:2112
#define HasGraphFlag(TGraph, Flag)
For quick testing of the properties of the graph/network object (see TGraphFlag). ...
Definition: gbase.h:41
TNode & GetNode(const int &NId)
Definition: network.h:1144
TEdgeI BegEI() const
Returns an iterator referring to the first edge in the network.
Definition: network.h:675
Tests (at compile time) if the graph is a network with data on edges.
Definition: gbase.h:34
TAIntI(const TIntVecIter &HIter, TStr attribute, bool isEdgeIter, const TNEANet *GraphPt)
Definition: network.h:1760
bool Empty() const
Tests whether the network is empty (has zero nodes).
Definition: network.h:703
int GetInDeg() const
Definition: network.h:2765
int GetInNId(const int &NodeN) const
Returns ID of NodeN-th in-node (the node pointing to the current node).
Definition: network.h:78
void GetIntVAttrVal(TVec< TIntV > &Val) const
Gets vector of int attribute values.
Definition: network.h:1695
void FltAttrValueEI(const TInt &EId, TFltV &Values) const
Returns a vector of attr values for node NId.
Definition: network.h:2120
TNodeI GetRndNI(TRnd &Rnd=TInt::Rnd)
Returns an interator referring to a random node in the network.
Definition: network.h:3486
TEdgeDat & GetNbrEDat(const int &EdgeN)
Definition: network.h:1107
static PNet Load(TSIn &SIn)
Static constructor that loads the network from a stream SIn and returns a pointer to it...
Definition: network.h:153
TNodeData & GetDstNDat()
Definition: network.h:128
TNodeI(const TNodeI &NodeI)
Definition: network.h:2786
int GetSAttrDatE(const TInt &EId, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from edge with id EId.
Definition: network.cpp:1573
void SortNIdByDat(const bool &Asc=true)
Sorts nodes by node data.
Definition: network.h:1290
int GetId() const
Gets edge ID. Always returns -1 since only edges in multigraphs have explicit IDs.
Definition: network.h:562
int GetNbrNId(const int &EdgeN) const
Returns ID of EdgeN-th neighboring node.
Definition: network.h:1665
int GetSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, TFlt &ValX) const
Gets Flt sparse attribute with name AttrName from NodeI.
Definition: network.h:2532
bool IsOutNId(const int &NId) const
Definition: network.h:3290
bool Empty() const
Tests whether the network is empty (has zero nodes).
Definition: network.h:3491
int GetNbrNId(const int &NodeN) const
Returns ID of NodeN-th neighboring node.
Definition: network.h:3333
int GetSAttrIdE(const TStr &Name, TInt &AttrIdX, TAttrType &AttrTypeX) const
Gets id and type for attribute with name Name.
Definition: network.cpp:1649
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:2932
void Reserve(const int &Nodes, const int &Edges)
Reserves memory for a graph of Nodes nodes and Edges edges.
Definition: network.h:2237
int GetSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from EdgeI.
Definition: network.h:3687
static PUndirNet Load_V1(TSIn &SIn)
Static constructor that loads the network from a stream SIn and returns a pointer to it...
Definition: network.h:2884
void ReserveNIdDeg(const int &NId, const int &Deg)
Reserves memory for node ID NId having Deg edges.
Definition: network.h:2988
TEdgeI & operator=(const TEdgeI &EdgeI)
Definition: network.h:555
TFltV::TIter TFltVecIter
Definition: network.h:1819
TEdgeI & operator++(int)
Increment iterator.
Definition: network.h:557
TNode & GetNode(const int &NId)
Definition: network.h:2859
int AddEdge(const int &SrcNId, const int &DstNId)
Adds an edge from node IDs SrcNId to node DstNId to the network.
Definition: network.h:334
TEdgeI GetRndEI(TRnd &Rnd=TInt::Rnd)
Returns an interator referring to a random edge in the network.
Definition: network.h:1274
int GetSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, TStr &ValX) const
Gets Str sparse attribute with name AttrName from EdgeI.
Definition: network.h:3206
int GetDstNId() const
Gets the destination node of an edge.
Definition: network.h:126
int GetId() const
Definition: network.h:1028
int AddNode(const TNodeI &NodeId)
Adds a node of ID NodeI.GetId() to the network.
Definition: network.h:3411
TCRef CRef
Definition: network.h:1859
TNode(const TNode &Node)
Definition: network.h:3279
bool operator<(const TNode &Node) const
Definition: network.h:47
int AddSAttrDatE(const int &SrcNId, const int &DstNId, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to the given edge with ids SrcId and DstId...
Definition: network.cpp:2476
bool IsEdge(const int &SrcNId, const int &DstNId, const bool &IsDir=true) const
Tests whether an edge from node IDs SrcNId to DstNId exists in the network.
Definition: network.h:846
TNode(TSIn &SIn)
Definition: network.h:463
TAStrI & operator++(int)
Definition: network.h:1812
int GetSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, TFlt &ValX) const
Gets Flt sparse attribute with name AttrName from EdgeI.
Definition: network.h:2650
int AddIntAttrN(const TStr &attr, TInt defaultValue=TInt::Mn)
Adds a new Int node attribute to the hashmap.
Definition: network.cpp:1143
const TNodeData & GetDat() const
Definition: network.h:1005
TStr GetStrAttrDefaultE(const TStr &attribute) const
Gets Str edge attribute val. If not a proper attr, return default.
Definition: network.h:1855
const TNodeData & GetSrcNDat() const
Definition: network.h:127
void SortNIdById(const bool &Asc=true)
Sorts nodes by node IDs.
Definition: network.h:245
TNEANet(const int &Nodes, const int &Edges)
Constructor that reserves enough memory for a graph of nodes and edges.
Definition: network.h:1886
TAStrI(const TAStrI &I)
Definition: network.h:1804
bool IsOutNId(const int &NId) const
Tests whether the current node points to node with ID NId.
Definition: network.h:90
TNEANet()
Definition: network.h:1880
int DelSAttrDatN(const TNodeI &NodeI, const TInt &AttrId)
Deletes sparse attribute with id AttrId from NodeI.
Definition: network.h:2564
int AddSAttrDatN(const TInt &NId, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to the given node with id NId.
Definition: network.cpp:1405
int GetMxNId() const
Returns an ID that is larger than any node ID in the network.
Definition: network.h:198
THashIter NodeHI
Definition: network.h:2782
TNodeData & GetDstNDat()
Definition: network.h:573
bool FNextKeyId(int &KeyId) const
Definition: hash.h:436
int GetSAttrDatE(const int &SrcNId, const int &DstNId, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from edge with ids SrcId and DstId.
Definition: network.cpp:2524
TNodeI(const THashIter &NodeHIter)
Definition: network.h:2785
THash< TStr, TStr > StrDefaultsN
Definition: network.h:1868
void AttrNameNI(const TInt &NId, TStrV &Names) const
Returns a vector of attr names for node NId.
Definition: network.h:2034
const TEdgeData & GetDat() const
Definition: network.h:1134
Tests (at compile time) if the graph is a multigraph with multiple edges between the same nodes...
Definition: gbase.h:30
THash< TInt, TNode > NodeH
Definition: network.h:3368
#define Assert(Cond)
Definition: bd.h:251
TAIntVI EndEAIntVI(const TStr &attr) const
Returns an iterator referring to the past-the-end edge's attribute.
Definition: network.h:2142
THash< TInt, TNode > NodeH
Definition: network.h:1153
TInt MxNId
Definition: network.h:2853
TNodeNet * Net
Definition: network.h:56
TNodeI EndNode
Definition: network.h:109
void DelNode(const TNode &NodeI)
Deletes node of ID NodeI.GetId() from the graph.
Definition: network.h:1983
int GetIdVSAttrE(const TStr &AttrName, TIntPrV &IdV) const
Gets a list of all edges that have a sparse attribute with name AttrName.
Definition: network.cpp:2116
TNodeNet(TSIn &SIn)
Constructor that loads the network from a (binary) stream SIn.
Definition: network.h:146
bool Empty() const
Tests whether the network is empty (has zero nodes).
Definition: network.h:2982
int AddStrAttrE(const TStr &attr, TStr defaultValue=TStr::GetNullStr())
Adds a new Str edge attribute to the hashmap.
Definition: network.cpp:1245
TEdgeData & GetDat()
Definition: network.h:1135
TFlt GetFltAttrDatN(const TNodeI &NodeI, const TStr &attr)
Gets the value of flt attr from the node attr value vector.
Definition: network.h:2311
TEdgeI BegEI() const
Returns an iterator referring to the first edge in the graph.
Definition: network.h:2206
TNodeEDatNet(TSIn &SIn)
Constructor that loads the network from a (binary) stream SIn.
Definition: network.h:591
int AddSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, const TStr &Val)
Adds Str sparse attribute with name AttrName to NodeI.
Definition: network.h:2504
void SortNIdByDat(const bool &Asc=true)
Sorts nodes by node data.
Definition: network.h:712
const TNodeData & operator()() const
Definition: network.h:1079
bool IsNbrNId(const int &NId) const
Tests whether node with ID NId is a neighbor of the current node.
Definition: network.h:2826
bool IsOk(const bool &ThrowExcept=true) const
Checks the network data structure for internal consistency.
Definition: network.h:923
TNodeEDatNet< TNodeData, TEdgeData > TNet
Definition: network.h:448
TNodeI(const TNodeI &NodeI)
Definition: network.h:3305
TInt GetIntAttrIndDatN(const TNodeI &NodeI, const int &index)
Gets the value of an int node attr specified by node iterator NodeI and the attr index.
Definition: network.h:2323
void IntVAttrNameEI(const TInt &EId, TStrV &Names) const
Returns a vector of int attr names for edge EId.
Definition: network.h:2098
bool IsInNId(const int &NId) const
Definition: network.h:2771
THashIter NodeHI
Definition: network.h:487
bool IsInNId(const int &NId) const
Tests whether node with ID NId points to the current node.
Definition: network.h:88
TAIntVI GetNAIntVI(const TStr &attr, const int &NId) const
Returns an iterator referring to the node of ID NId in the graph.
Definition: network.h:2009
int AddKey(const TKey &Key)
Definition: shash.h:1254
int AddSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, const TFlt &Val)
Adds Flt sparse attribute with id AttrId to EdgeI.
Definition: network.h:3154
TInt MxNId
Definition: network.h:137
int FFirstKeyId() const
Definition: hash.h:236
void Save(TSOut &SOut) const
Definition: network.h:3281
int GetId() const
Returns edge ID. Always returns -1 since only edges in multigraphs have explicit IDs.
Definition: network.h:2844
int GetId() const
Gets edge ID. Always returns -1 since only edges in multigraphs have explicit IDs.
Definition: network.h:122
TAIntI GetNAIntI(const TStr &attr, const int &NId) const
Returns an iterator referring to the node of ID NId in the graph.
Definition: network.h:1999
int GetOutEId(const int &EdgeN) const
Returns ID of EdgeN-th out-edge.
Definition: network.h:1093
TPt< TUndirNet > PUndirNet
Pointer to an undirected network (TUndirNet)
Definition: network.h:2723
int GetSAttrNameN(const TInt &AttrId, TStr &NameX, TAttrType &AttrTypeX) const
Gets name and type for attribute with id AttrId.
Definition: network.cpp:1527
int AddSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to NodeI.
Definition: network.h:3018
TEdgeI EndEI() const
Returns an iterator referring to the past-the-end edge in the graph.
Definition: network.h:2208
bool HasFlag(const TGraphFlag &Flag) const
Allows for run-time checking the type of the network (see the TGraphFlag for flags).
Definition: network.h:271
int GetInDeg() const
Returns in-degree of the current node.
Definition: network.h:1651
int GetDstNId() const
Definition: network.h:1628
TNode(const int &NId)
Definition: network.h:30
void PackOutNIdV()
Definition: network.h:2773
TNodeI(const THashIter &NodeHIter, const TNodeEDatNet *NetPt)
Definition: network.h:491
THash< TInt, TNode >::TIter THashIter
Definition: network.h:2781
TEdge(TSIn &SIn)
Definition: network.h:1624
TNodeData & GetSrcNDat()
Definition: network.h:571
TVec< TPair< TInt, TEdgeData > > TNIdDatPrV
Definition: network.h:450
TNodeData & GetDat()
Definition: network.h:96
int AddSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, const TStr &Val)
Adds Str sparse attribute with name AttrName to NodeI.
Definition: network.h:3555
TNode(const TNode &Node)
Definition: network.h:1603
TStr GetStrAttrDefaultN(const TStr &attribute) const
Gets Str node attribute val. If not a proper attr, return default.
Definition: network.h:1849
int GetSrcNId() const
Returns the source of the edge.
Definition: network.h:1724
TEdgeData & GetDat()
Definition: network.h:1032
TNodeNet()
Definition: network.h:141
TStr GetNodeAttrValue(const int &NId, const TStrIntPrH::TIter &NodeHI) const
Returns node attribute value, converted to Str type.
Definition: network.cpp:193
int GetInNId(const int &NodeN) const
Returns ID of NodeN-th in-node (the node pointing to the current node).
Definition: network.h:2810
const TNodeData & GetNDat(const int &NId) const
Returns node data for the node of ID NId in the network.
Definition: network.h:641
int GetRndNId(TRnd &Rnd=TInt::Rnd)
Returns an ID of a random node in the network.
Definition: network.h:696
Node iterator. Only forward iteration (operator++) is supported.
Definition: network.h:484
TVec< TVec< TIntV > > VecOfIntVecVecsE
Definition: network.h:1873
TNodeEdgeNet & operator=(const TNodeEdgeNet &Net)
Definition: network.h:1171
void GetAttrVal(TStrV &Val) const
Gets vector of attribute values.
Definition: network.h:1730
int GetSAttrDatE(const int &SrcNId, const int &DstNId, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from edge with ids SrcId and DstId.
Definition: network.cpp:2043
static TStr GetNullStr()
Definition: dt.cpp:1626
int AddSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, const TStr &Val)
Adds Str sparse attribute with name AttrName to EdgeI.
Definition: network.h:3164
int GetOutNId(const int &NodeN) const
Returns ID of NodeN-th out-node (the node the current node points to).
Definition: network.h:3329
int GetDstNId() const
Returns the destination of the edge. Since the network is undirected, this is the node with a greater...
Definition: network.h:2848
TNodeI EndNI() const
Returns an iterator referring to the past-the-end node in the network.
Definition: network.h:2936
int AddSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, const TFlt &Val)
Adds Flt sparse attribute with name AttrName to EdgeI.
Definition: network.h:3659
TEdgeI(const TEdgeI &EdgeI)
Definition: network.h:3350
int GetRndNId(TRnd &Rnd=TInt::Rnd)
Returns an ID of a random node in the network.
Definition: network.h:231
bool IsInNId(const int &NId) const
Definition: network.h:476
int AddSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, const TStr &Val)
Adds Str sparse attribute with id AttrId to EdgeI.
Definition: network.h:2626
THash< TInt, TEdge > EdgeH
Definition: network.h:1154
TEdgeI BegEI() const
Returns an iterator referring to the first edge in the network.
Definition: network.h:3475
void SetAllEDat(const TEdgeData &EdgeDat)
Sets edge data for all the edges in the network to EDat.
Definition: network.h:1476
bool HasFlag(const TGraphFlag &Flag) const
Allows for run-time checking the type of the network (see the TGraphFlag for flags).
Definition: network.h:737
void AttrValueEI(const TInt &EId, TStrV &Values) const
Returns a vector of attr values for edge EId.
Definition: network.h:2084
int GetOutDeg() const
Returns out-degree of the current node.
Definition: network.h:1058
void FltAttrValueNI(const TInt &NId, TFltV &Values) const
Returns a vector of attr values for node NId.
Definition: network.h:2075
TInt MxNId
Definition: network.h:583
int GetSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, TStr &ValX) const
Gets Str sparse attribute with name AttrName from NodeI.
Definition: network.h:2546
Directed multigraph with node edge attributes.
Definition: network.h:1591
Definition: fl.h:128
bool operator==(const TEdgeI &EdgeI) const
Definition: network.h:120
TPt< TNEANet > PNet
Definition: network.h:1594
TEdgeData & GetOutEDat(const int &EdgeN)
Definition: network.h:537
static PDirNet New(const int &Nodes, const int &Edges)
Static constructor that returns a pointer to the network and reserves enough memory for Nodes nodes a...
Definition: network.h:3390
void GetAttrNames(TStrV &Names) const
Gets vector of attribute names.
Definition: network.h:1685
int AddSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, const TStr &Val)
Adds Str sparse attribute with id AttrId to NodeI.
Definition: network.h:2508
void GetFltAttrVal(TFltV &Val) const
Gets vector of flt attribute values.
Definition: network.h:1703
bool Empty() const
Tests whether the graph is empty (has zero nodes).
Definition: network.h:2228
TNode(TSIn &SIn)
Definition: network.h:3280
TInt MxEId
Definition: network.h:1861
TSizeTy SearchBin(const TVal &Val) const
Returns the position of an element with value Val.
Definition: ds.h:1454
int DelSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName)
Deletes sparse attribute with name AttrName from EdgeI.
Definition: network.h:3220
TAStrI BegNAStrI(const TStr &attr) const
Returns an iterator referring to the first node's str attribute.
Definition: network.h:2014
TNodeI CurNode
Definition: network.h:3345
int AddSAttrDatE(const int &SrcNId, const int &DstNId, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to the given edge with ids SrcId and DstId...
Definition: network.cpp:1995
void GetFltAttrNames(TStrV &Names) const
Gets vector of flt attribute names.
Definition: network.h:1744
TNodeNet(const int &Nodes, const int &Edges)
Constructor that reserves enough memory for a network of Nodes nodes and Edges edges.
Definition: network.h:143
bool IsEdge(const int &EId) const
Tests whether an edge with ID EId exists in the network.
Definition: network.h:1244
bool IsDeleted() const
Returns true if the attribute has been deleted.
Definition: network.h:1811
int GetInDeg() const
Definition: network.h:1003
TStrV::TIter TStrVecIter
Definition: network.h:1796
const TNodeData & operator()() const
Definition: network.h:93
TEdgeData & GetEDat(const int &EId)
Returns edge data for the edge with ID EId.
Definition: network.h:1261
int AddNode(const TNodeI &NodeI)
Adds a node NodeI and its node data to the network.
Definition: network.h:174
int GetId() const
Definition: network.h:2763
int GetSrcNId() const
Gets the source of an edge.
Definition: network.h:1129
bool IsIntAttrE(const TStr &attr)
Checks if there is an edge attribute with name attr.
Definition: network.cpp:1395
TPt< TNet > PNet
Definition: network.h:21
int GetMxNId() const
Returns an ID that is larger than any node ID in the network.
Definition: network.h:3452
int GetSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, TFlt &ValX) const
Gets Flt sparse attribute with id AttrId from NodeI.
Definition: network.h:2536
bool IsInEId(const int &EId) const
Definition: network.h:1613
int AddSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to EdgeI.
Definition: network.h:3645
static PNEANet GetSmallGraph()
Returns a small multigraph on 5 nodes and 6 edges.
Definition: network.cpp:1334
bool IsIntVAttrDeletedE(const int &EId, const TStr &attr) const
Returns true if IntV attr exists for edge EId and is an empty vector.
Definition: network.cpp:323
int AddSAttrN(const TStr &Name, const TAttrType &AttrType, TInt &AttrId)
Adds mapping for sparse attribute with name Name and type AttrType.
Definition: network.cpp:2464
void SortByKey(const bool &Asc=true)
Definition: hash.h:249
void SetEDat(const int &EId, const TEdgeData &EdgeDat)
Sets edge data for the edge of ID NId in the network.
Definition: network.h:1470
bool IsEdge(const int &SrcNId, const int &DstNId, const bool &IsDir=true) const
Tests whether an edge from node IDs SrcNId to DstNId exists in the network.
Definition: network.h:354
Definition: dt.h:1044
int AddSAttrE(const TStr &Name, const TAttrType &AttrType, TInt &AttrId)
Adds mapping for sparse attribute with name Name and type AttrType.
Definition: network.cpp:2124
TEdge & GetEdge(const int &EId)
Definition: network.h:1842
TVal * TIter
Random access iterator to TVal.
Definition: ds.h:431
int GetOutDeg() const
Definition: network.h:1609
int GetNbrNId(const int &NodeN) const
Returns ID of NodeN-th neighboring node.
Definition: network.h:86
const TNode & GetNode(const int &NId) const
Definition: network.h:2860
TAIntVI BegEAIntVI(const TStr &attr) const
Returns an iterator referring to the first edge's int attribute.
Definition: network.h:2138
void Dump(FILE *OutF=stdout) const
Print the network in a human readable form to an output stream OutF.
Definition: network.cpp:1839
int GetNbrNId(const int &EdgeN) const
Definition: network.h:473
bool IsFltAttrE(const TStr &attr)
Checks if there is an edge attribute with name attr.
Definition: network.cpp:1390
void DelNode(const TNode &NodeI)
Deletes node of ID NodeI.GetId() from the network.
Definition: network.h:180
TNodeI GetRndNI(TRnd &Rnd=TInt::Rnd)
Returns an interator referring to a random node in the graph.
Definition: network.h:2217
int GetEId(const int &SrcNId, const int &DstNId) const
Definition: network.h:1249
int GetDeg() const
Definition: network.h:2764
int GetId() const
Returns ID of the current node.
Definition: network.h:68
int GetKeyId(const TKey &Key) const
Definition: hash.h:424
THash< TInt, TEdge >::TIter THashIter
Definition: network.h:1115
Edge iterator. Only forward iteration (operator++) is supported.
Definition: network.h:3343
void IntAttrValueNI(const TInt &NId, TIntV &Values) const
Returns a vector of attr values for node NId.
Definition: network.h:2047
TNodeI EndNI() const
Returns an iterator referring to the past-the-end node in the graph.
Definition: network.h:1989
int GetSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, TStr &ValX) const
Gets Str sparse attribute with id AttrId from NodeI.
Definition: network.h:3601
int GetRndNId(TRnd &Rnd=TInt::Rnd)
Returns an ID of a random node in the network.
Definition: network.h:1268
TAIntVI GetEAIntVI(const TStr &attr, const int &EId) const
Returns an iterator referring to the edge of ID EId in the graph.
Definition: network.h:2146
bool IsNbrNId(const int &NId) const
Definition: network.h:2770
bool EdgeAttrIsIntVDeleted(const int &EId, const TStrIntPrH::TIter &EdgeHI) const
Returns true if EId attr deleted for current edge int vector attr iterator.
Definition: network.cpp:349
TUndirNet(const TUndirNet &Graph)
Definition: network.h:2866
void GetIntAttrNames(TStrV &Names) const
Gets vector of int attribute names.
Definition: network.h:1689
int AddStrAttrN(const TStr &attr, TStr defaultValue=TStr::GetNullStr())
Adds a new Str node attribute to the hashmap.
Definition: network.cpp:1172
const TNodeData & GetOutNDat(const int &NodeN) const
Definition: network.h:99
const TEdgeData & operator()() const
Definition: network.h:1132
int GetId() const
Gets edge ID.
Definition: network.h:1127
const TEdgeDat & GetNbrEDat(const int &EdgeN) const
Definition: network.h:1108
TNode(const int &NId)
Definition: network.h:1602
int GetId() const
Definition: network.h:3282
TUndirNet(const int &Nodes, const int &Edges)
Constructor that reserves enough memory for a network of Nodes nodes and Edges edges.
Definition: network.h:2865
TNodeNet< TInt > TIntNNet
Definition: network.h:434
TNodeNet< TFlt > TFltNNet
Definition: network.h:436
TNodeData & GetDat()
Definition: network.h:529
int GetSAttrVN(const TNodeI &NodeI, const TAttrType AttrType, TAttrPrV &AttrV) const
Gets a list of all sparse attributes of type AttrType for NodeI.
Definition: network.h:3622
int AddNode(int NId=-1)
Adds a node of ID NId to the network.
Definition: network.h:276
bool IsIntAttrDeletedN(const int &NId, const TStr &attr) const
Returns true if Int attr exists for node NId and has default value.
Definition: network.cpp:137
TNodeI EndNode
Definition: network.h:3345
Edge iterator. Only forward iteration (operator++) is supported.
Definition: network.h:1707
TNode(const TNode &Node)
Definition: network.h:32
int DelAttrDatE(const TEdgeI &EdgeI, const TStr &attr)
Deletes the edge attribute for NodeI.
Definition: network.h:2374
void Reserve(const int &Nodes, const int &Edges)
Reserves memory for a network of Nodes nodes and Edges edges.
Definition: network.h:708
TNode(const int &NId)
Definition: network.h:460
int Len() const
Definition: shash.h:1121
int GetNodes() const
Returns the number of nodes in the network.
Definition: network.h:2894
TNode(const TNode &Node)
Definition: network.h:997
TPt< TStrNNet > PStrNNet
Definition: network.h:439
void SortEIdById(const bool &Asc=true)
Sorts edges by edge IDs.
Definition: network.h:1292
bool IsOutNId(const int &NId) const
Tests whether the current node points to node with ID NId.
Definition: network.h:1335
THash< TInt, TEdge >::TIter THashIter
Definition: network.h:1709
void FltAttrNameEI(const TInt &EId, TStrV &Names) const
Returns a vector of int attr names for node NId.
Definition: network.h:2116
int AddNode(const TNodeI &NodeI)
Adds a node of ID NodeI.GetId() to the network.
Definition: network.h:2902
TNode(const int &NId)
Definition: network.h:995
TNodeEdgeNet(TSIn &SIn)
Constructor that loads the network from a (binary) stream SIn.
Definition: network.h:1161
TNodeI BegNI() const
Returns an iterator referring to the first node in the network.
Definition: network.h:629
int DelSAttrDatE(const int &SrcNId, const int &DstNId, const TStr &AttrName)
Deletes sparse attribute with name AttrName from edge with ids SrcId and DstId.
Definition: network.cpp:2091
TNodeData TNodeDat
Definition: network.h:446
void Clr()
Deletes all nodes and edges from the network.
Definition: network.h:2984
TEdgeData TEdgeDat
Definition: network.h:984
TNodeEdgeNet< TNodeData, TEdgeData > TNet
Definition: network.h:985
int GetId() const
Definition: network.h:35
bool operator<(const TEdgeI &EdgeI) const
Definition: network.h:1124
THash< TStr, TStr > StrDefaultsE
Definition: network.h:1868
const TEdgeData & GetDat() const
Definition: network.h:570
int GetOutDeg() const
Definition: network.h:468
int GetInEId(const int &NodeN) const
Definition: network.h:1007
void Clr()
Clears the contents of the attribute map.
Definition: attr.h:114
void SetNDat(const int &NId, const TNodeData &NodeDat)
Sets node data for the node of ID NId in the network.
Definition: network.h:779
TNodeI GetNI(const int &NId) const
Returns an iterator referring to the node of ID NId in the network.
Definition: network.h:1204
const TNode & GetNodeKId(const int &NodeKeyId) const
Definition: network.h:1146
const TNodeData & GetSrcNDat() const
Definition: network.h:1136
void StrAttrNameEI(const TInt &EId, TStrV &Names) const
Returns a vector of str attr names for node NId.
Definition: network.h:2108
TFlt GetFltAttrDefaultE(const TStr &attribute) const
Gets Flt edge attribute val. If not a proper attr, return default.
Definition: network.h:1857
int GetEdges() const
Returns the number of edges in the graph.
Definition: network.h:2179
void Save(TSOut &SOut) const
Definition: network.h:1625
TNodeI GetRndNI(TRnd &Rnd=TInt::Rnd)
Returns an interator referring to a random node in the network.
Definition: network.h:2977
TNodeNet< TNodeData > TNet
Definition: network.h:20
static PDirNet Load_V1(TSIn &SIn)
Static constructor that loads the network from a stream SIn and returns a pointer to it...
Definition: network.h:3394
Undirected network.
Definition: network.h:2748
int GetSAttrIdN(const TStr &Name, TInt &AttrIdX, TAttrType &AttrTypeX) const
Gets id and type for attribute with name Name.
Definition: network.cpp:1523
TNodeNet< TStr > TStrNNet
Definition: network.h:438
int GetOutEId(const int &EdgeN) const
Definition: network.h:1611
THashIter NodeHI
Definition: network.h:1040
int GetInDeg() const
Returns in-degree of the current node.
Definition: network.h:1056
TNodeI CurNode
Definition: network.h:109
bool EdgeAttrIsStrDeleted(const int &EId, const TStrIntPrH::TIter &EdgeHI) const
Returns true if EId attr deleted for current edge str attr iterator.
Definition: network.cpp:355
void Save(TSOut &SOut) const
Saves the graph to a (binary) stream SOut. Expects data structures for sparse attributes.
Definition: network.h:1918
TAttrPair SAttrE
Definition: network.h:2857
TAIntVI(const TIntVVecIter &HIter, TStr attribute, bool isEdgeIter, const TNEANet *GraphPt)
Definition: network.h:1782
void GetEIdV(TIntV &EIdV) const
Returns a vector of all edge IDs in the network.
Definition: network.h:1492
bool IsInEId(const int &EId) const
Definition: network.h:1010
TEdgeI(const TEdgeI &EdgeI)
Definition: network.h:1121
int GetDstNId() const
Returns the destination node of the edge.
Definition: network.h:3362
TAIntVI BegNAIntVI(const TStr &attr) const
Returns an iterator referring to the first node's int attribute.
Definition: network.h:2003
Definition: dt.h:412
int AddStrAttrDatE(const TEdgeI &EdgeI, const TStr &value, const TStr &attr)
Attribute based add function for attr to Str value.
Definition: network.h:2288
TDirNet()
Definition: network.h:3375
void GetAttrVal(TStrV &Val) const
Gets vector of attribute values.
Definition: network.h:1687
const TEdgeDat & GetInEDat(const int &EdgeN) const
Definition: network.h:1104
const TNodeData & GetDstNDat() const
Definition: network.h:574
TNodeNet & operator=(const TNodeNet &NodeNet)
Definition: network.h:156
const TNodeData & GetNbrNDat(const int &NodeN) const
Definition: network.h:101
TNEANet(const TNEANet &Graph)
Definition: network.h:1892
static PNEANet Load_V1(TSIn &SIn)
Static constructor that loads the graph from a stream SIn and returns a pointer to it...
Definition: network.h:1948
TEdgeI(const TEdgeI &EdgeI)
Definition: network.h:1715
TIter BegI() const
Returns an iterator pointing to the first element in the vector.
Definition: ds.h:565
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
void Save(TSOut &SOut) const
Saves the attributes to a (binary) stream SOut.
Definition: attr.h:25
bool IsSorted(const bool &Asc=true) const
Checks whether the vector is sorted in ascending (if Asc=true) or descending (if Asc=false) order...
Definition: ds.h:1259
void Pack()
Reduces vector capacity (frees memory) to match its size.
Definition: ds.h:1005
static PNet New()
Static constructor that returns a pointer to the network. Call: TPt > Net = TNodeEdgeNet::New().
Definition: network.h:1166
void DelEdge(const int &EId)
Deletes an edge with ID EId from the network.
Definition: network.h:1431
enum TGraphFlag_ TGraphFlag
Graph Flags, used for quick testing of graph types.
int DelSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName)
Deletes sparse attribute with name AttrName from EdgeI.
Definition: network.h:2678
TPt< TIntNNet > PIntNNet
Definition: network.h:435
int GetOutNId(const int &NodeN) const
Returns ID of NodeN-th out-node (the node the current node points to).
Definition: network.h:82
bool operator<(const TEdge &Edge) const
Definition: network.h:1027
TNodeEdgeNet * Net
Definition: network.h:1041
int GetOutDeg() const
Returns out-degree of the current node.
Definition: network.h:3321
TNode(TSIn &SIn)
Definition: network.h:1604
const TNode & GetNode(const int &NId) const
Definition: network.h:1841
int GetOutNId(const int &NodeN) const
Returns ID of NodeN-th out-node (the node the current node points to).
Definition: network.h:514
int GetSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, TStr &ValX) const
Gets Str sparse attribute with id AttrId from NodeI.
Definition: network.h:3092
void GetWeightOutEdgesV(TFltV &OutWeights, const TFltV &AttrVal)
Fills OutWeights with the outgoing weight from each node.
Definition: network.cpp:1382
int GetMxEId() const
Returns an ID that is larger than any edge ID in the network.
Definition: network.h:2176
int GetSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, TStr &ValX) const
Gets Str sparse attribute with name AttrName from NodeI.
Definition: network.h:3597
Definition: hash.h:88
int GetEdges() const
Returns the number of edges in the network.
Definition: network.h:1216
TAttr SAttrN
Definition: network.h:2856
int GetInDeg() const
Definition: network.h:37
int GetIdVSAttrN(const TStr &AttrName, TIntV &IdV) const
Gets a list of all nodes that have a sparse attribute with name AttrName.
Definition: network.cpp:1511
int GetNbrEId(const int &EdgeN) const
Returns ID of EdgeN-th in or out-edge.
Definition: network.h:1677
int DelSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId)
Deletes sparse attribute with id AttrId from EdgeI.
Definition: network.h:3733
TAIntI & operator++(int)
Definition: network.h:1769
bool IsAttrDeletedN(const int &NId, const TStr &attr) const
Returns true if attr exists for node NId and has default value.
Definition: network.cpp:129
const TEdgeData & GetDat() const
Definition: network.h:1031
int GetDeg() const
Definition: network.h:1607
int AddSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, const TFlt &Val)
Adds Flt sparse attribute with id AttrId to NodeI.
Definition: network.h:2494
int AddSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, const TFlt &Val)
Adds Flt sparse attribute with id AttrId to EdgeI.
Definition: network.h:2612
TVec< TFltV > VecOfFltVecsN
Definition: network.h:1872
int GetSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from NodeI.
Definition: network.h:3569
int GetInDeg() const
Definition: network.h:1608
TAFltI EndEAFltI(const TStr &attr) const
Returns an iterator referring to the past-the-end edge's attribute.
Definition: network.h:2166
TIntV::TIter TIntVecIter
Definition: network.h:1753
int GetSAttrVE(const int &SrcNId, const int &DstNId, const TAttrType AttrType, TAttrPrV &AttrV) const
Gets a list of all sparse attributes of type AttrType for edge with ids SrcId and DstId...
Definition: network.cpp:2588
TAFltI GetNAFltI(const TStr &attr, const int &NId) const
Returns an iterator referring to the node of ID NId in the graph.
Definition: network.h:2030
#define EAssertR(Cond, MsgStr)
Definition: bd.h:283
int AddSAttrE(const TStr &Name, const TAttrType &AttrType, TInt &AttrId)
Adds mapping for sparse attribute with name Name and type AttrType.
Definition: network.cpp:2605
int AddSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, const TFlt &Val)
Adds Flt sparse attribute with name AttrName to EdgeI.
Definition: network.h:3150
bool HasFlag(const TGraphFlag &Flag) const
Allows for run-time checking the type of the network (see the TGraphFlag for flags).
Definition: network.h:1320
void Clr()
Deletes all nodes and edges from the graph.
Definition: network.h:2230
void Clr(const bool &DoDel=true, const bool &ResetDat=true)
Deletes all nodes and edges from the network.
Definition: network.h:240
TEdgeData & GetNbrEDat(const int &EdgeN)
Definition: network.h:541
int GetSAttrDatN(const TInt &NId, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from node with id NId.
Definition: network.cpp:1904
void Save(TSOut &SOut) const
Definition: network.h:2762
int GetId() const
Definition: network.h:1606
const TNodeData & GetNbrNDat(const int &EdgeN) const
Definition: network.h:1087
TCRef CRef
Definition: network.h:2852
int GetDeg() const
Definition: network.h:466
int AddSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, const TStr &Val)
Adds Str sparse attribute with name AttrName to EdgeI.
Definition: network.h:3673
TNodeData NodeDat
Definition: network.h:455
int GetEId(const int &SrcNId, const int &DstNId) const
Returns an edge ID between node IDs SrcNId and DstNId, if such an edge exists. Otherwise, return -1.
Definition: network.h:2204
TNodeI GetNI(const int &NId) const
Returns an iterator referring to the node of ID NId in the network.
Definition: network.h:2938
bool Empty() const
Tests whether the network is empty (has zero nodes).
Definition: network.h:1281
virtual ~TNodeNet()
Definition: network.h:147
bool IsNbrNId(const int &NId) const
Tests whether node with ID NId is a neighbor of the current node.
Definition: network.h:524
int AddSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, const TStr &Val)
Adds Str sparse attribute with name AttrName to NodeI.
Definition: network.h:3046
void GetIntVAttrNames(TStrV &Names) const
Gets vector of int attribute names.
Definition: network.h:1693
const TNodeData & GetOutNDat(const int &NodeN) const
Definition: network.h:530
void DelNode(const TNode &NodeI)
Deletes node of ID NodeI.GetId() from the network.
Definition: network.h:1196
TEdgeI GetEI(const int &SrcNId, const int &DstNId) const
Returns an iterator referring to edge (SrcNId, DstNId) in the graph.
Definition: network.h:1257
TVal2 Val2
Definition: ds.h:35
int GetSAttrNameE(const TInt &AttrId, TStr &NameX, TAttrType &AttrTypeX) const
Gets name and type for attribute with id AttrId.
Definition: network.cpp:2132
void Clr(const bool &DoDel=true, const int &NoDelLim=-1, const bool &ResetDat=true)
Definition: hash.h:319
TIntPr OrderEdgeNodes(const int &SrcNId, const int &DstNId) const
Definition: network.cpp:1988
bool IsInEId(const int &EId) const
Tests whether the edge with ID EId is an in-edge of current node.
Definition: network.h:1097
bool operator<(const TNode &Node) const
Definition: network.h:479
TVec< TFlt > & GetFltAttrVecE(const TStr &attr)
Gets Vector for the Flt Attribute attr.
Definition: network.cpp:1030
int GetSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, TFlt &ValX) const
Gets Flt sparse attribute with id AttrId from EdgeI.
Definition: network.h:2654
Definition: bd.h:196
int AddEdge(const TEdgeI &EdgeI)
Adds an edge from EdgeI.GetSrcNId() to EdgeI.GetDstNId() and its edge data to the network...
Definition: network.h:665
void GetNIdV(TIntV &NIdV) const
Gets a vector IDs of all nodes in the network.
Definition: network.h:361
THash< TStr, TInt > IntDefaultsN
Definition: network.h:1867
int GetDstNId() const
Definition: network.h:1030
TNodeI(const THashIter &NodeHIter, const TNEANet *GraphPt)
Definition: network.h:1639
TNode(const int &NId)
Definition: network.h:2759
TNodeEdgeNet * Net
Definition: network.h:1117
TIntV OutNIdV
Definition: network.h:3275
const TNode & GetNode(const int &NId) const
Returns node element for the node of ID NId in the network.
Definition: network.h:635
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:1985
int GetNodes() const
Returns the number of nodes in the network.
Definition: network.h:3403
int GetRndNId(TRnd &Rnd=TInt::Rnd)
Returns an ID of a random node in the network.
Definition: network.h:3484
bool IsInNId(const int &NId) const
Tests whether node with ID NId points to the current node.
Definition: network.h:3335
int GetOutNId(const int &NodeN) const
Returns ID of NodeN-th out-node (the node the current node points to).
Definition: network.h:2815
const TNEANet * Graph
Definition: network.h:1823
void Defrag(const bool &OnlyNodeLinks=false)
Defragments the network.
Definition: network.h:376
void Defrag(const bool &OnlyNodeLinks=false)
Defragments the network.
Definition: network.h:912
void DelNode(const int &NId)
Deletes node of ID NId from the network.
Definition: network.h:1369
bool NodeAttrIsIntDeleted(const int &NId, const TStrIntPrH::TIter &NodeHI) const
Returns true if NId attr deleted value for current node int attr iterator.
Definition: network.cpp:161
int GetOutDeg() const
Returns out-degree of the current node.
Definition: network.h:74
bool IsIntVAttrDeletedN(const int &NId, const TStr &attr) const
Returns true if IntV attr exists for node NId and is an empty vector.
Definition: network.cpp:141
THash< TInt, TNode > NodeH
Definition: network.h:1862
int AppendIntVAttrDatE(const TEdgeI &EdgeI, const TInt &value, const TStr &attr)
Appends value onto the TIntV attribute for the given node.
Definition: network.h:2301
int GetSrcNId() const
Definition: network.h:1029
int GetSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, TInt &ValX) const
Gets Int sparse attribute with id AttrId from NodeI.
Definition: network.h:2522
int GetRndKeyId(TRnd &Rnd) const
Get an index of a random element. If the hash table has many deleted keys, this may take a long time...
Definition: hash.h:402
bool IsNbrNId(const int &NId) const
Tests whether node with ID NId is a neighbor of the current node.
Definition: network.h:1077
static PDirNet New()
Static constructor that returns a pointer to the network. Call: PDirNet Graph = TDirNet::New().
Definition: network.h:3386
TEdge & GetEdge(const int &EId)
Definition: network.h:1147
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
Definition: ds.h:495
int GetSAttrVN(const TNodeI &NodeI, const TAttrType AttrType, TAttrPrV &AttrV) const
Gets a list of all sparse attributes of type AttrType for NodeI.
Definition: network.h:3113
int GetSrcNId() const
Returns the source of the edge. Since the network is undirected, this is the node with a smaller ID o...
Definition: network.h:2846
TEdgeI & operator=(const TEdgeI &EdgeI)
Definition: network.h:1122
TFlt GetFltAttrIndDatN(const TNodeI &NodeI, const int &index)
Gets the value of a float node attr specified by node iterator NodeI and the attr index...
Definition: network.h:2333
int GetDstNId() const
Gets the destination node of an edge.
Definition: network.h:566
TDirNet(TSIn &SIn)
Constructor that loads the network from a (binary) stream SIn.
Definition: network.h:3380
TEdgeI & operator=(const TEdgeI &EdgeI)
Definition: network.h:115
TPt< TNet > PNet
Definition: network.h:986
bool IsNbrEId(const int &EId) const
Tests whether the edge with ID EId is an in or out-edge of current node.
Definition: network.h:1101
TNodeI BegNI() const
Returns an iterator referring to the first node in the graph.
Definition: network.h:1987
void GetNIdV(TIntV &NIdV) const
Gets a vector IDs of all nodes in the network.
Definition: network.h:905
TVec< TVec< TIntV > > VecOfIntVecVecsN
Definition: network.h:1873
int GetInDeg() const
Definition: network.h:467
int AddIntAttrE(const TStr &attr, TInt defaultValue=TInt::Mn)
Adds a new Int edge attribute to the hashmap.
Definition: network.cpp:1211
THashIter EdgeHI
Definition: network.h:1710
TEdgeI BegEI() const
Returns an iterator referring to the first edge in the network.
Definition: network.h:222
int AddSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, const TInt &Val)
Adds Int sparse attribute with id AttrId to NodeI.
Definition: network.h:3022
int AddSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, const TStr &Val)
Adds Str sparse attribute with name AttrName to EdgeI.
Definition: network.h:2622
void Reserve(const TSizeTy &_MxVals)
Reserves enough memory for the vector to store _MxVals elements.
Definition: ds.h:515
int GetSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from EdgeI.
Definition: network.h:2636
TEdge(const int &EId, const int &SourceNId, const int &DestNId)
Definition: network.h:1622
void Dump(FILE *OutF=stdout) const
Print the network in a human readable form to an output stream OutF.
Definition: network.cpp:2325
TNodeI GetNI(const int &NId) const
Returns an iterator referring to the node of ID NId in the graph.
Definition: network.h:1991
TNodeI EndNI() const
Returns an iterator referring to the past-the-end node in the network.
Definition: network.h:631
const TEdgeData & GetOutEDat(const int &EdgeN) const
Definition: network.h:538
TFlt GetFltAttrDefaultN(const TStr &attribute) const
Gets Flt node attribute val. If not a proper attr, return default.
Definition: network.h:1851
bool IsInNId(const int &NId) const
Tests whether node with ID NId points to the current node.
Definition: network.h:1325
int GetInEId(const int &EdgeN) const
Definition: network.h:1610
TEdgeI EndEI() const
Returns an iterator referring to the past-the-end edge in the network.
Definition: network.h:2965
int GetIdVSAttrE(const TStr &AttrName, TIntPrV &IdV) const
Gets a list of all edges that have a sparse attribute with name AttrName.
Definition: network.cpp:2597
int AddSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, const TFlt &Val)
Adds Flt sparse attribute with id AttrId to NodeI.
Definition: network.h:3545
void IntAttrNameEI(const TInt &EId, TStrV &Names) const
Returns a vector of int attr names for edge EId.
Definition: network.h:2088
int GetSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, TFlt &ValX) const
Gets Flt sparse attribute with name AttrName from EdgeI.
Definition: network.h:3192
int GetIdVSAttrE(const TStr &AttrName, TIntV &IdV) const
Gets a list of all edges that have a sparse attribute with name AttrName.
Definition: network.cpp:1637
TEdgeData & GetDat()
Definition: network.h:569
TNodeI BegNI() const
Returns an iterator referring to the first node in the network.
Definition: network.h:3444
void GetIntAttrNames(TStrV &Names) const
Gets vector of int attribute names.
Definition: network.h:1732
void Reserve(const int &Nodes, const int &Edges)
Reserves memory for a network of Nodes nodes and Edges edges.
Definition: network.h:243
TNodeI & operator=(const TNodeI &NodeI)
Definition: network.h:493
TInt GetIntAttrDefaultN(const TStr &attribute) const
Gets Int node attribute val. If not a proper attr, return default.
Definition: network.h:1847
TAStrI(const TStrVecIter &HIter, TStr attribute, bool isEdgeIter, const TNEANet *GraphPt)
Definition: network.h:1803
TNodeEdgeNet< TInt, TInt > TIntNENet
Definition: network.h:1565
int GetOutDeg() const
Definition: network.h:2766
static PNet Load(TSIn &SIn)
Static constructor that loads the network from a stream SIn and returns a pointer to it...
Definition: network.h:598
TInt MxNId
Definition: network.h:3367
bool IsOk(const bool &ThrowExcept=true) const
Checks the network data structure for internal consistency.
Definition: network.h:386
int AddIntVAttrE(const TStr &attr)
Adds a new IntV edge attribute to the hashmap.
Definition: network.cpp:1231
int GetInNId(const int &NodeN) const
Definition: network.h:3286
TIntVecIter HI
Definition: network.h:1754
void DelNode(const TNode &NodeI)
Deletes node of ID NodeI.GetId() from the network.
Definition: network.h:3440
char * CStr()
Definition: dt.h:476
bool IsOutNId(const int &NId) const
Definition: network.h:2772
TDirNet(const int &Nodes, const int &Edges)
Constructor that reserves enough memory for a network of Nodes nodes and Edges edges.
Definition: network.h:3377
TNodeData & GetNbrNDat(const int &NodeN)
Definition: network.h:102
int GetInDeg() const
Returns in-degree of the current node (returns same as value GetDeg() since the network is undirected...
Definition: network.h:2803
Node iterator. Only forward iteration (operator++) is supported.
Definition: network.h:52
int GetSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, TStr &ValX) const
Gets Str sparse attribute with name AttrName from NodeI.
Definition: network.h:3088
THashIter NodeHI
Definition: network.h:1635
int DelSAttrDatN(const TNodeI &NodeI, const TStr &AttrName)
Deletes sparse attribute with name AttrName from NodeI.
Definition: network.h:2560
int AddSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, const TFlt &Val)
Adds Flt sparse attribute with name AttrName to NodeI.
Definition: network.h:3541
TPt< TNEANet > PNEANet
Pointer to a directed attribute multigraph (TNEANet)
Definition: network.h:1570
bool IsKey(const TKey &Key) const
Definition: hash.h:216
TIntV GetDat() const
Returns an attribute of the node.
Definition: network.h:1788
static PDirNet Load(TSIn &SIn)
Static constructor that loads the network from a stream SIn and returns a pointer to it...
Definition: network.h:3392
TNEANet TNet
Definition: network.h:1593
const TEdge & GetEdge(const int &EId) const
Definition: network.h:1843
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574
int GetSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, TInt &ValX) const
Gets Int sparse attribute with id AttrId from EdgeI.
Definition: network.h:2640
int GetSAttrVN(const TInt &NId, const TAttrType AttrType, TAttrPrV &AttrV) const
Gets a list of all sparse attributes of type AttrType for node with id NId.
Definition: network.cpp:1960
static PNEANet New()
Static cons returns pointer to graph. Ex: PNEANet Graph=TNEANet::New().
Definition: network.h:1940
void GetFltAttrNames(TStrV &Names) const
Gets vector of flt attribute names.
Definition: network.h:1701
int DelSAttrDatE(const TInt &EId, const TStr &AttrName)
Deletes sparse attribute with name AttrName from edge with id EId.
Definition: network.cpp:1615
int GetSAttrVE(const int &SrcNId, const int &DstNId, const TAttrType AttrType, TAttrPrV &AttrV) const
Gets a list of all sparse attributes of type AttrType for edge with ids SrcId and DstId...
Definition: network.cpp:2107
bool IsOk(const bool &ThrowExcept=true) const
Checks the network data structure for internal consistency.
Definition: network.h:1510
int GetIdVSAttrN(const TStr &AttrName, TIntV &IdV) const
Gets a list of all nodes that have a sparse attribute with name AttrName.
Definition: network.cpp:2456
int DelSAttrDatE(const int &SrcNId, const int &DstNId, const TStr &AttrName)
Deletes sparse attribute with name AttrName from edge with ids SrcId and DstId.
Definition: network.cpp:2572
bool IsStrAttrE(const TStr &attr)
Checks if there is an edge attribute with name attr.
Definition: network.cpp:1400
TIntV OutNIdV
Definition: network.h:27
TInt NEdges
Definition: network.h:2853
TAIntVI & operator++(int)
Definition: network.h:1789
TNodeI(const TNodeI &NodeI)
Definition: network.h:1045
int GetSrcNId() const
Returns the source node of the edge.
Definition: network.h:3360
int Len() const
Definition: hash.h:186
TIntVVecIter HI
Definition: network.h:1776
TNodeData & GetOutNDat(const int &NodeN)
Definition: network.h:531
int DelAttrDatN(const TNodeI &NodeI, const TStr &attr)
Deletes the node attribute for NodeI.
Definition: network.h:2371
int GetDeg() const
Returns degree of the current node, the sum of in-degree and out-degree.
Definition: network.h:1054
int DelSAttrDatN(const TInt &NId, const TStr &AttrName)
Deletes sparse attribute with name AttrName from node with id NId.
Definition: network.cpp:1489
TIter GetI(const TSizeTy &ValN) const
Returns an iterator an element at position ValN.
Definition: ds.h:569
void GetStrAttrNames(TStrV &Names) const
Gets vector of str attribute names.
Definition: network.h:1697
TNEANet(bool copyAll, const TNEANet &Graph)
Definition: network.h:1910
int GetOutDeg() const
Definition: network.h:3285
bool IsEdge(const int &SrcNId, const int &DstNId, const bool &IsDir=true) const
Tests whether an edge from node IDs SrcNId to DstNId exists in the network.
Definition: network.h:1246
TDat & AddDat(const TKey &Key)
Definition: hash.h:196
TEdgeI EndEI() const
Returns an iterator referring to the past-the-end edge in the network.
Definition: network.h:1253
bool operator==(const TNodeI &NodeI) const
Definition: network.h:497
static PDirNet GetSmallGraph()
Returns a small network on 5 nodes and 6 edges.
Definition: network.cpp:2342
THashIter NodeHI
Definition: network.h:3301
TEdgeDat & GetInEDat(const int &EdgeN)
Definition: network.h:1103
int GetSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from NodeI.
Definition: network.h:2518
void Save(TSOut &SOut) const
Definition: network.h:34
int GetSAttrVE(const TEdgeI &EdgeI, const TAttrType AttrType, TAttrPrV &AttrV) const
Gets a list of all sparse attributes of type AttrType for EdgeI.
Definition: network.h:2688
Node/edge string attribute iterator. Iterates through all nodes/edges for one string attribute...
Definition: network.h:1794
bool operator<(const TNodeI &NodeI) const
Definition: network.h:496
void GetAttrNames(TStrV &Names) const
Gets vector of attribute names.
Definition: network.h:1728
Node iterator. Only forward iteration (operator++) is supported.
Definition: network.h:1037
int AddIntAttrDatN(const TNodeI &NodeI, const TInt &value, const TStr &attr)
Attribute based add function for attr to Int value.
Definition: network.h:2257
void GetIntAttrVal(TIntV &Val) const
Gets vector of int attribute values.
Definition: network.h:1734
int GetIntAttrIndE(const TStr &attr)
Gets the index of the edge attr value vector specified by attr (same as GetAttrIndE for compatibility...
Definition: network.cpp:1102
int AddSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to NodeI.
Definition: network.h:3527
int AddSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, const TStr &Val)
Adds Str sparse attribute with id AttrId to EdgeI.
Definition: network.h:3677
void GetIntVAttrVal(TVec< TIntV > &Val) const
Gets vector of int attribute values.
Definition: network.h:1738
TAFltI(const TFltVecIter &HIter, TStr attribute, bool isEdgeIter, const TNEANet *GraphPt)
Definition: network.h:1826
const TNEANet * Graph
Definition: network.h:1757
void Save(TSOut &SOut) const
Definition: network.h:1026
TAIntI(const TAIntI &I)
Definition: network.h:1761
TStr GetStrAttrIndDatN(const TNodeI &NodeI, const int &index)
Gets the value of a string node attr specified by node iterator NodeI and the attr index...
Definition: network.h:2328
int DelSAttrDatN(const TInt &NId, const TStr &AttrName)
Deletes sparse attribute with name AttrName from node with id NId.
Definition: network.cpp:2434
THash< TInt, TNode >::TIter THashIter
Definition: network.h:54
TEdgeI(const TNodeI &NodeI, const TNodeI &EndNodeI, const int &EdgeN=0)
Definition: network.h:2836
TNodeI EndNI() const
Returns an iterator referring to the past-the-end node in the network.
Definition: network.h:1202
void GetIntAttrVal(TIntV &Val) const
Gets vector of int attribute values.
Definition: network.h:1691
TNIdDatPrV OutNIdV
Definition: network.h:457
TNodeI EndNI() const
Returns an iterator referring to the past-the-end node in the network.
Definition: network.h:3446
Node iterator. Only forward iteration (operator++) is supported.
Definition: network.h:2779
const TNEANet * Graph
Definition: network.h:1800
int GetOutEId(const int &NodeN) const
Definition: network.h:1008
static PNEANet New(const int &Nodes, const int &Edges)
Static constructor that returns a pointer to the graph and reserves enough memory for Nodes nodes and...
Definition: network.h:1944
int GetRndEId(TRnd &Rnd=TInt::Rnd)
Returns an ID of a random edge in the network.
Definition: network.h:1272
void Clr()
Clears the contents of the attribute map.
Definition: attr.h:29
const TKey & GetKey(const int &KeyId) const
Definition: hash.h:210
int AddSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, const TStr &Val)
Adds Str sparse attribute with id AttrId to NodeI.
Definition: network.h:3559
int GetMxNId() const
Returns an ID that is larger than any node ID in the network.
Definition: network.h:2174
THash< TInt, TNode >::TIter THashIter
Definition: network.h:1039
Node Network (directed graph, TNGraph with data on nodes only).
Definition: network.h:17
int GetId() const
Returns ID of the current node.
Definition: network.h:1052
int AddSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, const TInt &Val)
Adds Int sparse attribute with id AttrId to EdgeI.
Definition: network.h:2598
int GetDeg() const
Returns degree of the current node.
Definition: network.h:502
const TEdgeData & GetEDat(const int &EId) const
Returns edge data for the edge with ID EId.
Definition: network.h:1263
TNodeEDatNet< TStr, TInt > TStrIntNEDNet
Definition: network.h:975
int GetId() const
Returns ID of the current node.
Definition: network.h:3315
TEdgeI BegEI() const
Returns an iterator referring to the first edge in the network.
Definition: network.h:2963
TUndirNet(TSIn &SIn)
Constructor that loads the network from a (binary) stream SIn.
Definition: network.h:2869
const TEdgeData & GetNbrEDat(const int &EdgeN) const
Definition: network.h:542
int GetId() const
Returns ID of the current node.
Definition: network.h:500
const TNodeData & GetDstNDat() const
Definition: network.h:1138
const TNodeData & GetDat() const
Definition: network.h:528
int AddFltAttrE(const TStr &attr, TFlt defaultValue=TFlt::Mn)
Adds a new Flt edge attribute to the hashmap.
Definition: network.cpp:1264
TNode(const int &NId, const TNodeData &NodeData)
Definition: network.h:31
int GetDstNId() const
Gets destination of an edge.
Definition: network.h:1131
static const double Mn
Definition: dt.h:1297
int AddSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, const TFlt &Val)
Adds Flt sparse attribute with id AttrId to NodeI.
Definition: network.h:3036
TNodeEDatNet()
Definition: network.h:586
int GetNbrNId(const int &NodeN) const
Definition: network.h:43
void GetIntVAttrNames(TStrV &Names) const
Gets vector of int attribute names.
Definition: network.h:1736
bool operator==(const TNodeI &NodeI) const
Definition: network.h:1050
TPt< TDirNet > PDirNet
Pointer to a directed network (TDirNet)
Definition: network.h:2730
int AddSAttrN(const TStr &Name, const TAttrType &AttrType, TInt &AttrId)
Adds mapping for sparse attribute with name Name and type AttrType.
Definition: network.cpp:1519
int GetOutDeg() const
Definition: network.h:38
static PNet Load(TSIn &SIn)
Static constructor that loads the network from a stream SIn and returns a pointer to it...
Definition: network.h:1168
TFlt GetFltAttrIndDatE(const TEdgeI &EdgeI, const int &index)
Gets the value of a float edge attr specified by edge iterator EdgeI and the attr index...
Definition: network.h:2361
TNodeEdgeNet(const int &Nodes, const int &Edges)
Constructor that reserves enough memory for a network of Nodes nodes and Edges edges.
Definition: network.h:1158
int GetNodes() const
Returns the number of nodes in the network.
Definition: network.h:605
TInt GetIntAttrIndDatE(const TEdgeI &EdgeI, const int &index)
Gets the value of an int edge attr specified by edge iterator EdgeI and the attr index.
Definition: network.h:2356
TNodeI GetRndNI(TRnd &Rnd=TInt::Rnd)
Returns an interator referring to a random node in the network.
Definition: network.h:698
int AddSAttrN(const TStr &Name, const TAttrType &AttrType, TInt &AttrId)
Adds mapping for sparse attribute with name Name and type AttrType.
Definition: network.cpp:1976
TIter GetI(const TKey &Key) const
Definition: hash.h:178
void SortByDat(const bool &Asc=true)
Definition: hash.h:250
TPt< TFltNENet > PFltNENet
Definition: network.h:1568
Implements a single CrossNet consisting of edges between two TModeNets (could be the same TModeNet) ...
Definition: mmnet.h:124
int GetMxNId() const
Returns an ID that is larger than any node ID in the network.
Definition: network.h:643
void Save_V1(TSOut &SOut) const
Saves the network to a (binary) stream SOut. Available for backwards compatibility.
Definition: network.h:2874
TNodeData & GetSrcNDat()
Definition: network.h:1137
TEdgeI EndEI() const
Returns an iterator referring to the past-the-end edge in the network.
Definition: network.h:224
int AddFltAttrN(const TStr &attr, TFlt defaultValue=TFlt::Mn)
Adds a new Flt node attribute to the hashmap.
Definition: network.cpp:1191