SNAP Library 6.0, Developer Reference  2020-12-09 16:24:20
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
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  void LoadShM(TShMIn& MStream) {
48  Id = TInt(MStream);
49  NodeDat = TNodeData(MStream);
50  InNIdV.LoadShM(MStream);
51  OutNIdV.LoadShM(MStream);
52  }
53  bool operator < (const TNode& Node) const { return NodeDat < Node.NodeDat; }
54  friend class TNodeNet<TNodeData>;
55  };
56 
58  class TNodeI {
59  private:
61  THashIter NodeHI;
63  public:
64  TNodeI() : NodeHI(), Net(NULL) { }
65  TNodeI(const THashIter& NodeHIter, const TNodeNet* NetPt) : NodeHI(NodeHIter), Net((TNodeNet *) NetPt) { }
66  TNodeI(const TNodeI& NodeI) : NodeHI(NodeI.NodeHI), Net(NodeI.Net) { }
67  TNodeI& operator = (const TNodeI& NodeI) { NodeHI=NodeI.NodeHI; Net=NodeI.Net; return *this; }
69  TNodeI& operator++ (int) { NodeHI++; return *this; }
70  bool operator < (const TNodeI& NodeI) const { return NodeHI < NodeI.NodeHI; }
71  bool operator == (const TNodeI& NodeI) const { return NodeHI == NodeI.NodeHI; }
72 
74  int GetId() const { return NodeHI.GetDat().GetId(); }
76  int GetDeg() const { return NodeHI.GetDat().GetDeg(); }
78  int GetInDeg() const { return NodeHI.GetDat().GetInDeg(); }
80  int GetOutDeg() const { return NodeHI.GetDat().GetOutDeg(); }
82 
84  int GetInNId(const int& NodeN) const { return NodeHI.GetDat().GetInNId(NodeN); }
86 
88  int GetOutNId(const int& NodeN) const { return NodeHI.GetDat().GetOutNId(NodeN); }
90 
92  int GetNbrNId(const int& NodeN) const { return NodeHI.GetDat().GetNbrNId(NodeN); }
94  bool IsInNId(const int& NId) const { return NodeHI.GetDat().IsInNId(NId); }
96  bool IsOutNId(const int& NId) const { return NodeHI.GetDat().IsOutNId(NId); }
98  bool IsNbrNId(const int& NId) const { return IsOutNId(NId) || IsInNId(NId); }
99  const TNodeData& operator () () const { return NodeHI.GetDat().NodeDat; }
100  TNodeData& operator () () { return NodeHI.GetDat().GetDat(); }
101  const TNodeData& GetDat() const { return NodeHI.GetDat().GetDat(); }
102  TNodeData& GetDat() { return NodeHI.GetDat().GetDat(); }
103  const TNodeData& GetInNDat(const int& NodeN) const { return Net->GetNDat(GetInNId(NodeN)); }
104  TNodeData& GetInNDat(const int& NodeN) { return Net->GetNDat(GetInNId(NodeN)); }
105  const TNodeData& GetOutNDat(const int& NodeN) const { return Net->GetNDat(GetOutNId(NodeN)); }
106  TNodeData& GetOutNDat(const int& NodeN) { return Net->GetNDat(GetOutNId(NodeN)); }
107  const TNodeData& GetNbrNDat(const int& NodeN) const { return Net->GetNDat(GetNbrNId(NodeN)); }
108  TNodeData& GetNbrNDat(const int& NodeN) { return Net->GetNDat(GetNbrNId(NodeN)); }
109  friend class TNodeNet<TNodeData>;
110  };
111 
113  class TEdgeI {
114  private:
116  int CurEdge;
117  public:
118  TEdgeI() : CurNode(), EndNode(), CurEdge(0) { }
119  TEdgeI(const TNodeI& NodeI, const TNodeI& EndNodeI, const int& EdgeN=0) : CurNode(NodeI), EndNode(EndNodeI), CurEdge(EdgeN) { }
120  TEdgeI(const TEdgeI& EdgeI) : CurNode(EdgeI.CurNode), EndNode(EdgeI.EndNode), CurEdge(EdgeI.CurEdge) { }
121  TEdgeI& operator = (const TEdgeI& EdgeI) { if (this!=&EdgeI) { CurNode=EdgeI.CurNode; EndNode=EdgeI.EndNode; CurEdge=EdgeI.CurEdge; } return *this; }
123  TEdgeI& operator++ (int) { CurEdge++; if (CurEdge >= CurNode.GetOutDeg()) { CurEdge=0; CurNode++;
124  while (CurNode < EndNode && CurNode.GetOutDeg()==0) { CurNode++; } } return *this; }
125  bool operator < (const TEdgeI& EdgeI) const { return CurNode<EdgeI.CurNode || (CurNode==EdgeI.CurNode && CurEdge<EdgeI.CurEdge); }
126  bool operator == (const TEdgeI& EdgeI) const { return CurNode == EdgeI.CurNode && CurEdge == EdgeI.CurEdge; }
128  int GetId() const { return -1; }
130  int GetSrcNId() const { return CurNode.GetId(); }
132  int GetDstNId() const { return CurNode.GetOutNId(CurEdge); }
133  const TNodeData& GetSrcNDat() const { return CurNode.GetDat(); }
134  TNodeData& GetDstNDat() { return CurNode.GetOutNDat(CurEdge); }
135  friend class TNodeNet<TNodeData>;
136  };
137 
138 protected:
139  TNode& GetNode(const int& NId) { return NodeH.GetDat(NId); }
140 
141 protected:
145 
146 private:
147  class TNodeFunctor {
148  public:
150  void operator() (TNode* n, TShMIn& ShMIn) { n->LoadShM(ShMIn);}
151  };
152 private:
153  void LoadNetworkShM(TShMIn& ShMIn) {
154  MxNId = TInt(ShMIn);
155  TNodeFunctor f;
156  NodeH.LoadShM(ShMIn, f);
157  }
158 
159 public:
160  TNodeNet() : CRef(), MxNId(0), NodeH() { }
162  explicit TNodeNet(const int& Nodes, const int& Edges) : MxNId(0) { Reserve(Nodes, Edges); }
163  TNodeNet(const TNodeNet& NodeNet) : MxNId(NodeNet.MxNId), NodeH(NodeNet.NodeH) { }
165  TNodeNet(TSIn& SIn) : MxNId(SIn), NodeH(SIn) { }
166  virtual ~TNodeNet() { }
168  virtual void Save(TSOut& SOut) const { MxNId.Save(SOut); NodeH.Save(SOut); }
170  static PNet New() { return PNet(new TNodeNet()); }
172  static PNet Load(TSIn& SIn) { return PNet(new TNodeNet(SIn)); }
174 
178  static PNet LoadShM(TShMIn& ShMIn) {
179  TNodeNet* Network = new TNodeNet();
180  Network->LoadNetworkShM(ShMIn);
181  return PNet(Network);
182  }
184  bool HasFlag(const TGraphFlag& Flag) const;
185  TNodeNet& operator = (const TNodeNet& NodeNet) {
186  if (this!=&NodeNet) { NodeH=NodeNet.NodeH; MxNId=NodeNet.MxNId; } return *this; }
187  // nodes
189  int GetNodes() const { return NodeH.Len(); }
191 
195  int AddNode(int NId = -1);
197 
201  int AddNodeUnchecked(int NId = -1);
203 
207  int AddNode(int NId, const TNodeData& NodeDat);
209  int AddNode(const TNodeI& NodeI) { return AddNode(NodeI.GetId(), NodeI.GetDat()); }
211 
213  virtual void DelNode(const int& NId);
215  void DelNode(const TNode& NodeI) { DelNode(NodeI.GetId()); }
217  bool IsNode(const int& NId) const { return NodeH.IsKey(NId); }
219  TNodeI BegNI() const { return TNodeI(NodeH.BegI(), this); }
221  TNodeI EndNI() const { return TNodeI(NodeH.EndI(), this); }
223  TNodeI GetNI(const int& NId) const { return TNodeI(NodeH.GetI(NId), this); }
225  const TNode& GetNode(const int& NId) const { return NodeH.GetDat(NId); }
227  void SetNDat(const int& NId, const TNodeData& NodeDat);
229  TNodeData& GetNDat(const int& NId) { return NodeH.GetDat(NId).NodeDat; }
231  const TNodeData& GetNDat(const int& NId) const { return NodeH.GetDat(NId).NodeDat; }
233  int GetMxNId() const { return MxNId; }
234 
235  // edges
237  int GetEdges() const;
239 
245  int AddEdge(const int& SrcNId, const int& DstNId);
247  int AddEdge(const TEdgeI& EdgeI) { return AddEdge(EdgeI.GetSrcNId(), EdgeI.GetDstNId()); }
249 
253  void DelEdge(const int& SrcNId, const int& DstNId, const bool& IsDir = true);
255  bool IsEdge(const int& SrcNId, const int& DstNId, const bool& IsDir = true) const;
257  TEdgeI BegEI() const { TNodeI NI=BegNI(); while(NI<EndNI() && NI.GetOutDeg()==0) NI++; return TEdgeI(NI, EndNI()); }
259  TEdgeI EndEI() const { return TEdgeI(EndNI(), EndNI()); }
261  TEdgeI GetEI(const int& EId) const;
263  TEdgeI GetEI(const int& SrcNId, const int& DstNId) const;
264 
266  int GetRndNId(TRnd& Rnd=TInt::Rnd) { return NodeH.GetKey(NodeH.GetRndKeyId(Rnd, 0.8)); }
268  TNodeI GetRndNI(TRnd& Rnd=TInt::Rnd) { return GetNI(GetRndNId(Rnd)); }
270  void GetNIdV(TIntV& NIdV) const;
271 
273  bool Empty() const { return GetNodes()==0; }
275  void Clr(const bool& DoDel=true, const bool& ResetDat=true) {
276  MxNId = 0; NodeH.Clr(DoDel, -1, ResetDat); }
278  void Reserve(const int& Nodes, const int& Edges) { if (Nodes>0) { NodeH.Gen(Nodes/2); } }
280  void SortNIdById(const bool& Asc=true) { NodeH.SortByKey(Asc); }
282  void SortNIdByDat(const bool& Asc=true) { NodeH.SortByDat(Asc); }
284 
289  void Defrag(const bool& OnlyNodeLinks=false);
291 
294  bool IsOk(const bool& ThrowExcept=true) const;
295 
296  friend class TPt<TNodeNet<TNodeData> >;
297 };
298 
299 // set flags
300 namespace TSnap {
301 template <class TNodeData> struct IsDirected<TNodeNet<TNodeData> > { enum { Val = 1 }; };
302 template <class TNodeData> struct IsNodeDat<TNodeNet<TNodeData> > { enum { Val = 1 }; };
303 }
304 
305 template <class TNodeData>
306 bool TNodeNet<TNodeData>::HasFlag(const TGraphFlag& Flag) const {
307  return HasGraphFlag(typename TNet, Flag);
308 }
309 
310 template <class TNodeData>
312  if (NId == -1) {
313  NId = MxNId; MxNId++;
314  } else {
315  IAssertR(!IsNode(NId), TStr::Fmt("NodeId %d already exists", NId));
316  MxNId = TMath::Mx(NId+1, MxNId());
317  }
318  NodeH.AddDat(NId, TNode(NId));
319  return NId;
320 }
321 
322 template <class TNodeData>
324  if (NId == -1) {
325  NId = MxNId; MxNId++;
326  } else {
327  if (IsNode(NId)) { return -1;}
328  MxNId = TMath::Mx(NId+1, MxNId());
329  }
330  NodeH.AddDat(NId, TNode(NId));
331  return NId;
332 }
333 
334 template <class TNodeData>
335 int TNodeNet<TNodeData>::AddNode(int NId, const TNodeData& NodeDat) {
336  if (NId == -1) {
337  NId = MxNId; MxNId++;
338  } else {
339  IAssertR(!IsNode(NId), TStr::Fmt("NodeId %d already exists", NId));
340  MxNId = TMath::Mx(NId+1, MxNId());
341  }
342  NodeH.AddDat(NId, TNode(NId, NodeDat));
343  return NId;
344 }
345 
346 template <class TNodeData>
347 void TNodeNet<TNodeData>::DelNode(const int& NId) {
348  { TNode& Node = GetNode(NId);
349  for (int e = 0; e < Node.GetOutDeg(); e++) {
350  const int nbr = Node.GetOutNId(e);
351  if (nbr == NId) { continue; }
352  TNode& N = GetNode(nbr);
353  int n = N.InNIdV.SearchBin(NId);
354  if (n!= -1) { N.InNIdV.Del(n); }
355  }
356  for (int e = 0; e < Node.GetInDeg(); e++) {
357  const int nbr = Node.GetInNId(e);
358  if (nbr == NId) { continue; }
359  TNode& N = GetNode(nbr);
360  int n = N.OutNIdV.SearchBin(NId);
361  if (n!= -1) { N.OutNIdV.Del(n); }
362  } }
363  NodeH.DelKey(NId);
364 }
365 
366 template <class TNodeData>
367 void TNodeNet<TNodeData>::SetNDat(const int& NId, const TNodeData& NodeDat) {
368  IAssertR(IsNode(NId), TStr::Fmt("NodeId %d does not exist.", NId).CStr());
369  NodeH.GetDat(NId).NodeDat = NodeDat;
370 }
371 
372 template <class TNodeData>
374  int edges=0;
375  for (int N=NodeH.FFirstKeyId(); NodeH.FNextKeyId(N);) {
376  edges+=NodeH[N].GetOutDeg(); }
377  return edges;
378 }
379 
380 template <class TNodeData>
381 int TNodeNet<TNodeData>::AddEdge(const int& SrcNId, const int& DstNId) {
382  IAssertR(IsNode(SrcNId) && IsNode(DstNId), TStr::Fmt("%d or %d not a node.", SrcNId, DstNId).CStr());
383  if (IsEdge(SrcNId, DstNId)) { return -2; }
384  GetNode(SrcNId).OutNIdV.AddSorted(DstNId);
385  GetNode(DstNId).InNIdV.AddSorted(SrcNId);
386  return -1; // no edge id
387 }
388 
389 template <class TNodeData>
390 void TNodeNet<TNodeData>::DelEdge(const int& SrcNId, const int& DstNId, const bool& IsDir) {
391  IAssertR(IsNode(SrcNId) && IsNode(DstNId), TStr::Fmt("%d or %d not a node.", SrcNId, DstNId).CStr());
392  GetNode(SrcNId).OutNIdV.DelIfIn(DstNId);
393  GetNode(DstNId).InNIdV.DelIfIn(SrcNId);
394  if (! IsDir) {
395  GetNode(DstNId).OutNIdV.DelIfIn(SrcNId);
396  GetNode(SrcNId).InNIdV.DelIfIn(DstNId);
397  }
398 }
399 
400 template <class TNodeData>
401 bool TNodeNet<TNodeData>::IsEdge(const int& SrcNId, const int& DstNId, const bool& IsDir) const {
402  if (! IsNode(SrcNId) || ! IsNode(DstNId)) { return false; }
403  if (IsDir) { return GetNode(SrcNId).IsOutNId(DstNId); }
404  else { return GetNode(SrcNId).IsOutNId(DstNId) || GetNode(DstNId).IsOutNId(SrcNId); }
405 }
406 
407 template <class TNodeData>
409  NIdV.Reserve(GetNodes(), 0);
410  for (int N=NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
411  NIdV.Add(NodeH.GetKey(N)); }
412 }
413 
414 template <class TNodeData>
415 typename TNodeNet<TNodeData>::TEdgeI TNodeNet<TNodeData>::GetEI(const int& SrcNId, const int& DstNId) const {
416  const TNodeI SrcNI = GetNI(SrcNId);
417  const int NodeN = SrcNI.NodeHI.GetDat().OutNIdV.SearchBin(DstNId);
418  if (NodeN == -1) { return EndEI(); }
419  return TEdgeI(SrcNI, EndNI(), NodeN);
420 }
421 
422 template <class TNodeData>
423 void TNodeNet<TNodeData>::Defrag(const bool& OnlyNodeLinks) {
424  for (int n = NodeH.FFirstKeyId(); NodeH.FNextKeyId(n); ) {
425  TNode& Node = NodeH[n];
426  Node.InNIdV.Pack(); Node.OutNIdV.Pack();
427  }
428  if (! OnlyNodeLinks && ! NodeH.IsKeyIdEqKeyN()) {
429  NodeH.Defrag(); }
430 }
431 
432 template <class TNodeData>
433 bool TNodeNet<TNodeData>::IsOk(const bool& ThrowExcept) const {
434  bool RetVal = true;
435  for (int N = NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
436  const TNode& Node = NodeH[N];
437  if (! Node.OutNIdV.IsSorted()) {
438  const TStr Msg = TStr::Fmt("Out-neighbor list of node %d is not sorted.", Node.GetId());
439  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
440  }
441  if (! Node.InNIdV.IsSorted()) {
442  const TStr Msg = TStr::Fmt("In-neighbor list of node %d is not sorted.", Node.GetId());
443  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
444  }
445  // check out-edges
446  int prevNId = -1;
447  for (int e = 0; e < Node.GetOutDeg(); e++) {
448  if (! IsNode(Node.GetOutNId(e))) {
449  const TStr Msg = TStr::Fmt("Out-edge %d --> %d: node %d does not exist.",
450  Node.GetId(), Node.GetOutNId(e), Node.GetOutNId(e));
451  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
452  }
453  if (e > 0 && prevNId == Node.GetOutNId(e)) {
454  const TStr Msg = TStr::Fmt("Node %d has duplidate out-edge %d --> %d.",
455  Node.GetId(), Node.GetId(), Node.GetOutNId(e));
456  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
457  }
458  prevNId = Node.GetOutNId(e);
459  }
460  // check in-edges
461  prevNId = -1;
462  for (int e = 0; e < Node.GetInDeg(); e++) {
463  if (! IsNode(Node.GetInNId(e))) {
464  const TStr Msg = TStr::Fmt("In-edge %d <-- %d: node %d does not exist.",
465  Node.GetId(), Node.GetInNId(e), Node.GetInNId(e));
466  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
467  }
468  if (e > 0 && prevNId == Node.GetInNId(e)) {
469  const TStr Msg = TStr::Fmt("Node %d has duplidate in-edge %d <-- %d.",
470  Node.GetId(), Node.GetId(), Node.GetInNId(e));
471  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
472  }
473  prevNId = Node.GetInNId(e);
474  }
475  }
476  return RetVal;
477 }
478 
480 // Common network types
487 
488 //#//////////////////////////////////////////////
490 template <class TNodeData, class TEdgeData>
492 public:
493  typedef TNodeData TNodeDat;
494  typedef TEdgeData TEdgeDat;
496  typedef TPt<TNet> PNet;
498 public:
499  class TNode {
500  private:
502  TNodeData NodeDat;
504  TNIdDatPrV OutNIdV;
505  public:
506  TNode() : Id(-1), NodeDat(), InNIdV(), OutNIdV() { }
507  TNode(const int& NId) : Id(NId), NodeDat(), InNIdV(), OutNIdV() { }
508  TNode(const int& NId, const TNodeData& NodeData) : Id(NId), NodeDat(NodeData), InNIdV(), OutNIdV() { }
509  TNode(const TNode& Node) : Id(Node.Id), NodeDat(Node.NodeDat), InNIdV(Node.InNIdV), OutNIdV(Node.OutNIdV) { }
510  TNode(TSIn& SIn) : Id(SIn), NodeDat(SIn), InNIdV(SIn), OutNIdV(SIn) { }
511  void Save(TSOut& SOut) const { Id.Save(SOut); NodeDat.Save(SOut); InNIdV.Save(SOut); OutNIdV.Save(SOut); }
512  int GetId() const { return Id; }
513  int GetDeg() const { return GetInDeg() + GetOutDeg(); }
514  int GetInDeg() const { return InNIdV.Len(); }
515  int GetOutDeg() const { return OutNIdV.Len(); }
516  const TNodeData& GetDat() const { return NodeDat; }
517  TNodeData& GetDat() { return NodeDat; }
518  int GetInNId(const int& EdgeN) const { return InNIdV[EdgeN]; }
519  int GetOutNId(const int& EdgeN) const { return OutNIdV[EdgeN].Val1; }
520  int GetNbrNId(const int& EdgeN) const { return EdgeN<GetOutDeg() ? GetOutNId(EdgeN):GetInNId(EdgeN-GetOutDeg()); }
521  TEdgeData& GetOutEDat(const int& EdgeN) { return OutNIdV[EdgeN].Val2; }
522  const TEdgeData& GetOutEDat(const int& EdgeN) const { return OutNIdV[EdgeN].Val2; }
523  bool IsInNId(const int& NId) const { return InNIdV.SearchBin(NId)!=-1; }
524  bool IsOutNId(const int& NId) const { return TNodeEDatNet::GetNIdPos(OutNIdV, NId)!=-1; }
525  bool IsNbrNId(const int& NId) const { return IsOutNId(NId) || IsInNId(NId); }
526  void LoadShM(TShMIn& MStream) {
527  Id = TInt(MStream);
528  NodeDat = TNodeData(MStream);
529  InNIdV.LoadShM(MStream);
530  OutNIdV.LoadShM(MStream);
531  }
532  bool operator < (const TNode& Node) const { return NodeDat < Node.NodeDat; }
533  friend class TNodeEDatNet<TNodeData, TEdgeData>;
534  };
535 
537  class TNodeI {
538  private:
540  THashIter NodeHI;
542  public:
543  TNodeI() : NodeHI(), Net(NULL) { }
544  TNodeI(const THashIter& NodeHIter, const TNodeEDatNet* NetPt) : NodeHI(NodeHIter), Net((TNodeEDatNet *) NetPt) { }
545  TNodeI(const TNodeI& NodeI) : NodeHI(NodeI.NodeHI), Net(NodeI.Net) { }
546  TNodeI& operator = (const TNodeI& NodeI) { NodeHI=NodeI.NodeHI; Net=NodeI.Net; return *this; }
548  TNodeI& operator++ (int) { NodeHI++; return *this; }
549  bool operator < (const TNodeI& NodeI) const { return NodeHI < NodeI.NodeHI; }
550  bool operator == (const TNodeI& NodeI) const { return NodeHI == NodeI.NodeHI; }
551 
553  int GetId() const { return NodeHI.GetDat().GetId(); }
555  int GetDeg() const { return NodeHI.GetDat().GetDeg(); }
557  int GetInDeg() const { return NodeHI.GetDat().GetInDeg(); }
559  int GetOutDeg() const { return NodeHI.GetDat().GetOutDeg(); }
561 
563  int GetInNId(const int& NodeN) const { return NodeHI.GetDat().GetInNId(NodeN); }
565 
567  int GetOutNId(const int& NodeN) const { return NodeHI.GetDat().GetOutNId(NodeN); }
569 
571  int GetNbrNId(const int& NodeN) const { return NodeHI.GetDat().GetNbrNId(NodeN); }
573  bool IsInNId(const int& NId) const { return NodeHI.GetDat().IsInNId(NId); }
575  bool IsOutNId(const int& NId) const { return NodeHI.GetDat().IsOutNId(NId); }
577  bool IsNbrNId(const int& NId) const { return IsOutNId(NId) || IsInNId(NId); }
578  // node data
579  const TNodeData& operator () () const { return NodeHI.GetDat().NodeDat; }
580  TNodeData& operator () () { return NodeHI.GetDat().GetDat(); }
581  const TNodeData& GetDat() const { return NodeHI.GetDat().GetDat(); }
582  TNodeData& GetDat() { return NodeHI.GetDat().GetDat(); }
583  const TNodeData& GetOutNDat(const int& NodeN) const { return Net->GetNDat(GetOutNId(NodeN)); }
584  TNodeData& GetOutNDat(const int& NodeN) { return Net->GetNDat(GetOutNId(NodeN)); }
585  const TNodeData& GetInNDat(const int& NodeN) const { return Net->GetNDat(GetInNId(NodeN)); }
586  TNodeData& GetInNDat(const int& NodeN) { return Net->GetNDat(GetInNId(NodeN)); }
587  const TNodeData& GetNbrNDat(const int& NodeN) const { return Net->GetNDat(GetNbrNId(NodeN)); }
588  TNodeData& GetNbrNDat(const int& NodeN) { return Net->GetNDat(GetNbrNId(NodeN)); }
589  // edge data
590  TEdgeData& GetOutEDat(const int& EdgeN) { return NodeHI.GetDat().GetOutEDat(EdgeN); }
591  const TEdgeData& GetOutEDat(const int& EdgeN) const { return NodeHI.GetDat().GetOutEDat(EdgeN); }
592  TEdgeData& GetInEDat(const int& EdgeN) { return Net->GetEDat(GetInNId(EdgeN), GetId()); }
593  const TEdgeData& GetInEDat(const int& EdgeN) const { return Net->GetEDat(GetInNId(EdgeN), GetId()); }
594  TEdgeData& GetNbrEDat(const int& EdgeN) { return EdgeN<GetOutDeg() ? GetOutEDat(EdgeN) : GetInEDat(EdgeN-GetOutDeg()); }
595  const TEdgeData& GetNbrEDat(const int& EdgeN) const { return EdgeN<GetOutDeg() ? GetOutEDat(EdgeN) : GetInEDat(EdgeN-GetOutDeg()); }
596  friend class TNodeEDatNet<TNodeData, TEdgeData>;
597  };
598 
600  class TEdgeI {
601  private:
603  int CurEdge;
604  public:
605  TEdgeI() : CurNode(), EndNode(), CurEdge(0) { }
606  TEdgeI(const TNodeI& NodeI, const TNodeI& EndNodeI, const int& EdgeN=0) : CurNode(NodeI), EndNode(EndNodeI), CurEdge(EdgeN) { }
607  TEdgeI(const TEdgeI& EdgeI) : CurNode(EdgeI.CurNode), EndNode(EdgeI.EndNode), CurEdge(EdgeI.CurEdge) { }
608  TEdgeI& operator = (const TEdgeI& EdgeI) { if (this!=&EdgeI) { CurNode=EdgeI.CurNode; EndNode=EdgeI.EndNode; CurEdge=EdgeI.CurEdge; } return *this; }
610  TEdgeI& operator++ (int) { CurEdge++; if (CurEdge >= CurNode.GetOutDeg()) { CurEdge=0; CurNode++;
611  while (CurNode < EndNode && CurNode.GetOutDeg()==0) { CurNode++; } } return *this; }
612  bool operator < (const TEdgeI& EdgeI) const { return CurNode<EdgeI.CurNode || (CurNode==EdgeI.CurNode && CurEdge<EdgeI.CurEdge); }
613  bool operator == (const TEdgeI& EdgeI) const { return CurNode == EdgeI.CurNode && CurEdge == EdgeI.CurEdge; }
615  int GetId() const { return -1; }
617  int GetSrcNId() const { return CurNode.GetId(); }
619  int GetDstNId() const { return CurNode.GetOutNId(CurEdge); }
620  TEdgeData& operator () () { return CurNode.GetOutEDat(CurEdge); }
621  const TEdgeData& operator () () const { return CurNode.GetOutEDat(CurEdge); }
622  TEdgeData& GetDat() { return CurNode.GetOutEDat(CurEdge); }
623  const TEdgeData& GetDat() const { return CurNode.GetOutEDat(CurEdge); }
624  TNodeData& GetSrcNDat() { return CurNode(); }
625  const TNodeData& GetSrcNDat() const { return CurNode(); }
626  TNodeData& GetDstNDat() { return CurNode.GetOutNDat(CurEdge); }
627  const TNodeData& GetDstNDat() const { return CurNode.GetOutNDat(CurEdge); }
628  friend class TNodeEDatNet<TNodeData, TEdgeData>;
629  };
630 
631 protected:
632  TNode& GetNode(const int& NId) { return NodeH.GetDat(NId); }
633  static int GetNIdPos(const TVec<TPair<TInt, TEdgeData> >& NIdV, const int& NId);
634 protected:
638 private:
639  class TNodeFunctor {
640  public:
642  void operator() (TNode* n, TShMIn& ShMIn) { n->LoadShM(ShMIn);}
643  };
644 private:
645  void LoadNetworkShM(TShMIn& ShMIn) {
646  MxNId = TInt(ShMIn);
647  TNodeFunctor f;
648  NodeH.LoadShM(ShMIn, f);
649  }
650 public:
651  TNodeEDatNet() : CRef(), MxNId(0), NodeH() { }
653  explicit TNodeEDatNet(const int& Nodes, const int& Edges) : MxNId(0) { Reserve(Nodes, Edges); }
654  TNodeEDatNet(const TNodeEDatNet& NodeNet) : MxNId(NodeNet.MxNId), NodeH(NodeNet.NodeH) { }
656  TNodeEDatNet(TSIn& SIn) : MxNId(SIn), NodeH(SIn) { }
657  virtual ~TNodeEDatNet() { }
659  virtual void Save(TSOut& SOut) const { MxNId.Save(SOut); NodeH.Save(SOut); }
661  static PNet New() { return PNet(new TNet()); }
663  static PNet Load(TSIn& SIn) { return PNet(new TNet(SIn)); }
665 
669  static PNet LoadShM(TShMIn& ShMIn) {
670  TNet* Network = new TNet();
671  Network->LoadNetworkShM(ShMIn);
672  return PNet(Network);
673  }
675  bool HasFlag(const TGraphFlag& Flag) const;
676  TNodeEDatNet& operator = (const TNodeEDatNet& NodeNet) { if (this!=&NodeNet) {
677  NodeH=NodeNet.NodeH; MxNId=NodeNet.MxNId; } return *this; }
678  // nodes
680  int GetNodes() const { return NodeH.Len(); }
682 
686  int AddNode(int NId = -1);
688 
692  int AddNodeUnchecked(int NId = -1);
694 
698  int AddNode(int NId, const TNodeData& NodeDat);
700  int AddNode(const TNodeI& NodeI) { return AddNode(NodeI.GetId(), NodeI.GetDat()); }
702 
704  void DelNode(const int& NId);
706  void DelNode(const TNode& NodeI) { DelNode(NodeI.GetId()); }
708  bool IsNode(const int& NId) const { return NodeH.IsKey(NId); }
710  TNodeI BegNI() const { return TNodeI(NodeH.BegI(), this); }
712  TNodeI EndNI() const { return TNodeI(NodeH.EndI(), this); }
714  TNodeI GetNI(const int& NId) const { return TNodeI(NodeH.GetI(NId), this); }
716  const TNode& GetNode(const int& NId) const { return NodeH.GetDat(NId); }
718  void SetNDat(const int& NId, const TNodeData& NodeDat);
720  TNodeData& GetNDat(const int& NId) { return NodeH.GetDat(NId).NodeDat; }
722  const TNodeData& GetNDat(const int& NId) const { return NodeH.GetDat(NId).NodeDat; }
724  int GetMxNId() const { return MxNId; }
725 
726  // edges
728  int GetEdges() const;
730 
736  int AddEdge(const int& SrcNId, const int& DstNId);
738 
744  int AddEdge(const int& SrcNId, const int& DstNId, const TEdgeData& EdgeDat);
746  int AddEdge(const TEdgeI& EdgeI) { return AddEdge(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), EdgeI()); }
748 
752  void DelEdge(const int& SrcNId, const int& DstNId, const bool& IsDir = true);
754  bool IsEdge(const int& SrcNId, const int& DstNId, const bool& IsDir = true) const;
756  TEdgeI BegEI() const { TNodeI NI=BegNI(); while(NI<EndNI() && NI.GetOutDeg()==0) NI++; return TEdgeI(NI, EndNI()); }
758  TEdgeI EndEI() const { return TEdgeI(EndNI(), EndNI()); }
760  TEdgeI GetEI(const int& EId) const; // not supported
762  TEdgeI GetEI(const int& SrcNId, const int& DstNId) const;
764  void SetEDat(const int& SrcNId, const int& DstNId, const TEdgeData& EdgeDat);
766 
768  bool GetEDat(const int& SrcNId, const int& DstNId, TEdgeData& EdgeDat) const;
770  TEdgeData& GetEDat(const int& SrcNId, const int& DstNId);
772  const TEdgeData& GetEDat(const int& SrcNId, const int& DstNId) const;
774  void SetAllEDat(const TEdgeData& EdgeDat);
775 
777  int GetRndNId(TRnd& Rnd=TInt::Rnd) { return NodeH.GetKey(NodeH.GetRndKeyId(Rnd, 0.8)); }
779  TNodeI GetRndNI(TRnd& Rnd=TInt::Rnd) { return GetNI(GetRndNId(Rnd)); }
781  void GetNIdV(TIntV& NIdV) const;
782 
784  bool Empty() const { return GetNodes()==0; }
786  void Clr(const bool& DoDel=true, const bool& ResetDat=true) {
787  MxNId = 0; NodeH.Clr(DoDel, -1, ResetDat); }
789  void Reserve(const int& Nodes, const int& Edges) { if (Nodes>0) { NodeH.Gen(Nodes/2); } }
791  void SortNIdById(const bool& Asc=true) { NodeH.SortByKey(Asc); }
793  void SortNIdByDat(const bool& Asc=true) { NodeH.SortByDat(Asc); }
795 
800  void Defrag(const bool& OnlyNodeLinks=false);
802 
805  bool IsOk(const bool& ThrowExcept=true) const;
806 
807  friend class TPt<TNodeEDatNet<TNodeData, TEdgeData> >;
808 };
809 
810 // set flags
811 namespace TSnap {
812 template <class TNodeData, class TEdgeData> struct IsDirected<TNodeEDatNet<TNodeData, TEdgeData> > { enum { Val = 1 }; };
813 template <class TNodeData, class TEdgeData> struct IsNodeDat<TNodeEDatNet<TNodeData, TEdgeData> > { enum { Val = 1 }; };
814 template <class TNodeData, class TEdgeData> struct IsEdgeDat<TNodeEDatNet<TNodeData, TEdgeData> > { enum { Val = 1 }; };
815 }
816 
817 template <class TNodeData, class TEdgeData>
819  return HasGraphFlag(typename TNet, Flag);
820 }
821 
822 template <class TNodeData, class TEdgeData>
824  int LValN=0, RValN = NIdV.Len()-1;
825  while (RValN >= LValN) {
826  const int ValN = (LValN+RValN)/2;
827  const int CurNId = NIdV[ValN].Val1;
828  if (NId == CurNId) { return ValN; }
829  if (NId < CurNId) { RValN=ValN-1; }
830  else { LValN=ValN+1; }
831  }
832  return -1;
833 }
834 
835 template <class TNodeData, class TEdgeData>
837  if (NId == -1) {
838  NId = MxNId; MxNId++;
839  } else {
840  IAssertR(!IsNode(NId), TStr::Fmt("NodeId %d already exists", NId));
841  MxNId = TMath::Mx(NId+1, MxNId());
842  }
843  NodeH.AddDat(NId, TNode(NId));
844  return NId;
845 }
846 
847 template <class TNodeData, class TEdgeData>
849  if (NId == -1) {
850  NId = MxNId; MxNId++;
851  } else {
852  if (IsNode(NId)) { return -1;}
853  MxNId = TMath::Mx(NId+1, MxNId());
854  }
855  NodeH.AddDat(NId, TNode(NId));
856  return NId;
857 }
858 
859 template <class TNodeData, class TEdgeData>
860 int TNodeEDatNet<TNodeData, TEdgeData>::AddNode(int NId, const TNodeData& NodeDat) {
861  if (NId == -1) {
862  NId = MxNId; MxNId++;
863  } else {
864  IAssertR(!IsNode(NId), TStr::Fmt("NodeId %d already exists", NId));
865  MxNId = TMath::Mx(NId+1, MxNId());
866  }
867  NodeH.AddDat(NId, TNode(NId, NodeDat));
868  return NId;
869 }
870 
871 template <class TNodeData, class TEdgeData>
872 void TNodeEDatNet<TNodeData, TEdgeData>::SetNDat(const int& NId, const TNodeData& NodeDat) {
873  IAssertR(IsNode(NId), TStr::Fmt("NodeId %d does not exist.", NId).CStr());
874  NodeH.GetDat(NId).NodeDat = NodeDat;
875 }
876 
877 template <class TNodeData, class TEdgeData>
879  const TNode& Node = GetNode(NId);
880  for (int out = 0; out < Node.GetOutDeg(); out++) {
881  const int nbr = Node.GetOutNId(out);
882  if (nbr == NId) { continue; }
883  TIntV& NIdV = GetNode(nbr).InNIdV;
884  const int pos = NIdV.SearchBin(NId);
885  if (pos != -1) { NIdV.Del(pos); }
886  }
887  for (int in = 0; in < Node.GetInDeg(); in++) {
888  const int nbr = Node.GetInNId(in);
889  if (nbr == NId) { continue; }
890  TNIdDatPrV& NIdDatV = GetNode(nbr).OutNIdV;
891  const int pos = GetNIdPos(NIdDatV, NId);
892  if (pos != -1) { NIdDatV.Del(pos); }
893  }
894  NodeH.DelKey(NId);
895 }
896 
897 template <class TNodeData, class TEdgeData>
899  int edges=0;
900  for (int N=NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
901  edges+=NodeH[N].GetOutDeg(); }
902  return edges;
903 }
904 
905 template <class TNodeData, class TEdgeData>
906 int TNodeEDatNet<TNodeData, TEdgeData>::AddEdge(const int& SrcNId, const int& DstNId) {
907  return AddEdge(SrcNId, DstNId, TEdgeData());
908 }
909 
910 template <class TNodeData, class TEdgeData>
911 int TNodeEDatNet<TNodeData, TEdgeData>::AddEdge(const int& SrcNId, const int& DstNId, const TEdgeData& EdgeDat) {
912  IAssertR(IsNode(SrcNId) && IsNode(DstNId), TStr::Fmt("%d or %d not a node.", SrcNId, DstNId).CStr());
913  //IAssert(! IsEdge(SrcNId, DstNId));
914  if (IsEdge(SrcNId, DstNId)) {
915  GetEDat(SrcNId, DstNId) = EdgeDat;
916  return -2;
917  }
918  GetNode(SrcNId).OutNIdV.AddSorted(TPair<TInt, TEdgeData>(DstNId, EdgeDat));
919  GetNode(DstNId).InNIdV.AddSorted(SrcNId);
920  return -1; // no edge id
921 }
922 
923 template <class TNodeData, class TEdgeData>
924 void TNodeEDatNet<TNodeData, TEdgeData>::DelEdge(const int& SrcNId, const int& DstNId, const bool& IsDir) {
925  IAssertR(IsNode(SrcNId) && IsNode(DstNId), TStr::Fmt("%d or %d not a node.", SrcNId, DstNId).CStr());
926  int pos = GetNIdPos(GetNode(SrcNId).OutNIdV, DstNId);
927  if (pos != -1) { GetNode(SrcNId).OutNIdV.Del(pos); }
928  pos = GetNode(DstNId).InNIdV.SearchBin(SrcNId);
929  if (pos != -1) { GetNode(DstNId).InNIdV.Del(pos); }
930  if (! IsDir) {
931  pos = GetNIdPos(GetNode(DstNId).OutNIdV, SrcNId);
932  if (pos != -1) { GetNode(DstNId).OutNIdV.Del(pos); }
933  pos = GetNode(SrcNId).InNIdV.SearchBin(DstNId);
934  if (pos != -1) { GetNode(SrcNId).InNIdV.Del(pos); }
935  }
936 }
937 
938 template <class TNodeData, class TEdgeData>
939 bool TNodeEDatNet<TNodeData, TEdgeData>::IsEdge(const int& SrcNId, const int& DstNId, const bool& IsDir) const {
940  if (! IsNode(SrcNId) || ! IsNode(DstNId)) { return false; }
941  if (IsDir) { return GetNode(SrcNId).IsOutNId(DstNId); }
942  else { return GetNode(SrcNId).IsOutNId(DstNId) || GetNode(DstNId).IsOutNId(SrcNId); }
943 }
944 
945 template <class TNodeData, class TEdgeData>
946 void TNodeEDatNet<TNodeData, TEdgeData>::SetEDat(const int& SrcNId, const int& DstNId, const TEdgeData& EdgeDat) {
947  IAssertR(IsNode(SrcNId) && IsNode(DstNId), TStr::Fmt("%d or %d not a node.", SrcNId, DstNId).CStr());
948  IAssertR(IsEdge(SrcNId, DstNId), TStr::Fmt("Edge between %d and %d does not exist.", SrcNId, DstNId).CStr());
949  GetEDat(SrcNId, DstNId) = EdgeDat;
950 }
951 
952 template <class TNodeData, class TEdgeData>
953 bool TNodeEDatNet<TNodeData, TEdgeData>::GetEDat(const int& SrcNId, const int& DstNId, TEdgeData& EdgeDat) const {
954  if (! IsEdge(SrcNId, DstNId)) { return false; }
955  const TNode& N = GetNode(SrcNId);
956  EdgeDat = N.GetOutEDat(GetNIdPos(N.OutNIdV, DstNId));
957  return true;
958 }
959 
960 template <class TNodeData, class TEdgeData>
961 TEdgeData& TNodeEDatNet<TNodeData, TEdgeData>::GetEDat(const int& SrcNId, const int& DstNId) {
962  Assert(IsEdge(SrcNId, DstNId));
963  TNode& N = GetNode(SrcNId);
964  return N.GetOutEDat(GetNIdPos(N.OutNIdV, DstNId));
965 }
966 
967 template <class TNodeData, class TEdgeData>
968 const TEdgeData& TNodeEDatNet<TNodeData, TEdgeData>::GetEDat(const int& SrcNId, const int& DstNId) const {
969  Assert(IsEdge(SrcNId, DstNId));
970  const TNode& N = GetNode(SrcNId);
971  return N.GetOutEDat(GetNIdPos(N.OutNIdV, DstNId));
972 }
973 
974 template <class TNodeData, class TEdgeData>
975 void TNodeEDatNet<TNodeData, TEdgeData>::SetAllEDat(const TEdgeData& EdgeDat) {
976  for (TEdgeI EI = BegEI(); EI < EndEI(); EI++) {
977  EI() = EdgeDat;
978  }
979 }
980 
981 template <class TNodeData, class TEdgeData>
982 typename TNodeEDatNet<TNodeData, TEdgeData>::TEdgeI TNodeEDatNet<TNodeData, TEdgeData>::GetEI(const int& SrcNId, const int& DstNId) const {
983  const TNodeI SrcNI = GetNI(SrcNId);
984  int NodeN = -1;
985  //SrcNI.NodeHI.GetDat().OutNIdV.SearchBin(DstNId);
986  const TNIdDatPrV& NIdDatV = SrcNI.NodeHI.GetDat().OutNIdV;
987  int LValN=0, RValN=NIdDatV.Len()-1;
988  while (RValN>=LValN){
989  int ValN=(LValN+RValN)/2;
990  if (DstNId==NIdDatV[ValN].Val1){ NodeN=ValN; break; }
991  if (DstNId<NIdDatV[ValN].Val1){RValN=ValN-1;} else {LValN=ValN+1;}
992  }
993  if (NodeN == -1) { return EndEI(); }
994  else { return TEdgeI(SrcNI, EndNI(), NodeN); }
995 }
996 
997 template <class TNodeData, class TEdgeData>
999  NIdV.Reserve(GetNodes(), 0);
1000  for (int N=NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
1001  NIdV.Add(NodeH.GetKey(N)); }
1002 }
1003 
1004 template <class TNodeData, class TEdgeData>
1005 void TNodeEDatNet<TNodeData, TEdgeData>::Defrag(const bool& OnlyNodeLinks) {
1006  for (int n = NodeH.FFirstKeyId(); NodeH.FNextKeyId(n);) {
1007  TNode& Node = NodeH[n];
1008  Node.InNIdV.Pack(); Node.OutNIdV.Pack();
1009  }
1010  if (! OnlyNodeLinks && ! NodeH.IsKeyIdEqKeyN()) {
1011  NodeH.Defrag();
1012  }
1013 }
1014 
1015 template <class TNodeData, class TEdgeData>
1016 bool TNodeEDatNet<TNodeData, TEdgeData>::IsOk(const bool& ThrowExcept) const {
1017  bool RetVal = true;
1018  for (int N = NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
1019  const TNode& Node = NodeH[N];
1020  if (! Node.OutNIdV.IsSorted()) {
1021  const TStr Msg = TStr::Fmt("Out-neighbor list of node %d is not sorted.", Node.GetId());
1022  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
1023  }
1024  if (! Node.InNIdV.IsSorted()) {
1025  const TStr Msg = TStr::Fmt("In-neighbor list of node %d is not sorted.", Node.GetId());
1026  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
1027  }
1028  // check out-edges
1029  int prevNId = -1;
1030  for (int e = 0; e < Node.GetOutDeg(); e++) {
1031  if (! IsNode(Node.GetOutNId(e))) {
1032  const TStr Msg = TStr::Fmt("Out-edge %d --> %d: node %d does not exist.",
1033  Node.GetId(), Node.GetOutNId(e), Node.GetOutNId(e));
1034  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
1035  }
1036  if (e > 0 && prevNId == Node.GetOutNId(e)) {
1037  const TStr Msg = TStr::Fmt("Node %d has duplidate out-edge %d --> %d.",
1038  Node.GetId(), Node.GetId(), Node.GetOutNId(e));
1039  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
1040  }
1041  prevNId = Node.GetOutNId(e);
1042  }
1043  // check in-edges
1044  prevNId = -1;
1045  for (int e = 0; e < Node.GetInDeg(); e++) {
1046  if (! IsNode(Node.GetInNId(e))) {
1047  const TStr Msg = TStr::Fmt("In-edge %d <-- %d: node %d does not exist.",
1048  Node.GetId(), Node.GetInNId(e), Node.GetInNId(e));
1049  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
1050  }
1051  if (e > 0 && prevNId == Node.GetInNId(e)) {
1052  const TStr Msg = TStr::Fmt("Node %d has duplidate in-edge %d <-- %d.",
1053  Node.GetId(), Node.GetId(), Node.GetInNId(e));
1054  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
1055  }
1056  prevNId = Node.GetInNId(e);
1057  }
1058  }
1059  return RetVal;
1060 }
1061 
1063 // Common network types
1070 
1071 //#//////////////////////////////////////////////
1073 template <class TNodeData, class TEdgeData>
1075 public:
1076  typedef TNodeData TNodeDat;
1077  typedef TEdgeData TEdgeDat;
1079  typedef TPt<TNet> PNet;
1080 public:
1081  class TNode {
1082  private:
1085  TNodeData NodeDat;
1086  public:
1087  TNode() : Id(-1), InEIdV(), OutEIdV(), NodeDat() { }
1088  TNode(const int& NId) : Id(NId), InEIdV(), OutEIdV(), NodeDat() { }
1089  TNode(const int& NId, const TNodeData& NodeData) : Id(NId), InEIdV(), OutEIdV(), NodeDat(NodeData) { }
1090  TNode(const TNode& Node) : Id(Node.Id), InEIdV(Node.InEIdV), OutEIdV(Node.OutEIdV), NodeDat(Node.NodeDat) { }
1091  TNode(TSIn& SIn) : Id(SIn), InEIdV(SIn), OutEIdV(SIn), NodeDat(SIn) { }
1092  void Save(TSOut& SOut) const { Id.Save(SOut); InEIdV.Save(SOut); OutEIdV.Save(SOut); NodeDat.Save(SOut); }
1093  bool operator < (const TNode& Node) const { return NodeDat < Node.NodeDat; }
1094  int GetId() const { return Id; }
1095  int GetDeg() const { return GetInDeg() + GetOutDeg(); }
1096  int GetInDeg() const { return InEIdV.Len(); }
1097  int GetOutDeg() const { return OutEIdV.Len(); }
1098  const TNodeData& GetDat() const { return NodeDat; }
1099  TNodeData& GetDat() { return NodeDat; }
1100  int GetInEId(const int& NodeN) const { return InEIdV[NodeN]; }
1101  int GetOutEId(const int& NodeN) const { return OutEIdV[NodeN]; }
1102  int GetNbrEId(const int& EdgeN) const { return EdgeN<GetOutDeg()?GetOutEId(EdgeN):GetInEId(EdgeN-GetOutDeg()); }
1103  bool IsInEId(const int& EId) const { return InEIdV.SearchBin(EId) != -1; }
1104  bool IsOutEId(const int& EId) const { return OutEIdV.SearchBin(EId) != -1; }
1105  bool IsNbrEId(const int& EId) const { return IsInEId(EId) || IsOutEId(EId); }
1106  void LoadShM(TShMIn& MStream) {
1107  Id = TInt(MStream);
1108  InEIdV.LoadShM(MStream);
1109  OutEIdV.LoadShM(MStream);
1110  NodeDat = TNodeData(MStream);
1111  }
1112  friend class TNodeEdgeNet<TNodeData, TEdgeData>;
1113  };
1114 
1115  class TEdge {
1116  private:
1118  TEdgeData EdgeDat;
1119  public:
1120  TEdge() : Id(-1), SrcNId(-1), DstNId(-1), EdgeDat() { }
1121  TEdge(const int& EId, const int& SourceNId, const int& DestNId) : Id(EId), SrcNId(SourceNId), DstNId(DestNId), EdgeDat() { }
1122  TEdge(const int& EId, const int& SourceNId, const int& DestNId, const TEdgeData& EdgeData) : Id(EId), SrcNId(SourceNId), DstNId(DestNId), EdgeDat(EdgeData) { }
1123  TEdge(const TEdge& Edge) : Id(Edge.Id), SrcNId(Edge.SrcNId), DstNId(Edge.DstNId), EdgeDat(Edge.EdgeDat) { }
1124  TEdge(TSIn& SIn) : Id(SIn), SrcNId(SIn), DstNId(SIn), EdgeDat(SIn) { }
1125  void Save(TSOut& SOut) const { Id.Save(SOut); SrcNId.Save(SOut); DstNId.Save(SOut); EdgeDat.Save(SOut); }
1126  bool operator < (const TEdge& Edge) const { return EdgeDat < Edge.EdgeDat; }
1127  int GetId() const { return Id; }
1128  int GetSrcNId() const { return SrcNId; }
1129  int GetDstNId() const { return DstNId; }
1130  void Load(TSIn& InStream) {
1131  Id = TInt(InStream);
1132  SrcNId = TInt(InStream);
1133  DstNId = TInt(InStream);
1134  EdgeDat = TEdgeData(InStream);
1135 
1136  }
1137  const TEdgeData& GetDat() const { return EdgeDat; }
1138  TEdgeData& GetDat() { return EdgeDat; }
1139  friend class TNodeEdgeNet;
1140  };
1141 
1143  class TNodeI {
1144  private:
1146  THashIter NodeHI;
1148  public:
1149  TNodeI() : NodeHI(), Net(NULL) { }
1150  TNodeI(const THashIter& NodeHIter, const TNodeEdgeNet* NetPt) : NodeHI(NodeHIter), Net((TNodeEdgeNet *)NetPt) { }
1151  TNodeI(const TNodeI& NodeI) : NodeHI(NodeI.NodeHI), Net(NodeI.Net) { }
1152  TNodeI& operator = (const TNodeI& NodeI) { NodeHI = NodeI.NodeHI; Net=NodeI.Net; return *this; }
1154  TNodeI& operator++ (int) { NodeHI++; return *this; }
1155  bool operator < (const TNodeI& NodeI) const { return NodeHI < NodeI.NodeHI; }
1156  bool operator == (const TNodeI& NodeI) const { return NodeHI == NodeI.NodeHI; }
1158  int GetId() const { return NodeHI.GetDat().GetId(); }
1160  int GetDeg() const { return NodeHI.GetDat().GetDeg(); }
1162  int GetInDeg() const { return NodeHI.GetDat().GetInDeg(); }
1164  int GetOutDeg() const { return NodeHI.GetDat().GetOutDeg(); }
1166 
1168  int GetInNId(const int& EdgeN) const { return Net->GetEdge(NodeHI.GetDat().GetInEId(EdgeN)).GetSrcNId(); }
1170 
1172  int GetOutNId(const int& EdgeN) const { return Net->GetEdge(NodeHI.GetDat().GetOutEId(EdgeN)).GetDstNId(); }
1174 
1176  int GetNbrNId(const int& EdgeN) const { const TEdge& E = Net->GetEdge(NodeHI.GetDat().GetNbrEId(EdgeN));
1177  return GetId()==E.GetSrcNId() ? E.GetDstNId():E.GetSrcNId(); }
1179  bool IsInNId(const int& NId) const;
1181  bool IsOutNId(const int& NId) const;
1183  bool IsNbrNId(const int& NId) const { return IsOutNId(NId) || IsInNId(NId); }
1184  // node data
1185  const TNodeData& operator () () const { return NodeHI.GetDat().GetDat(); }
1186  TNodeData& operator () () { return NodeHI.GetDat().GetDat(); }
1187  const TNodeData& GetDat() const { return NodeHI.GetDat().GetDat(); }
1188  TNodeData& GetDat() { return NodeHI.GetDat().GetDat(); }
1189  const TNodeData& GetInNDat(const int& EdgeN) const { return Net->GetNDat(GetInNId(EdgeN)); }
1190  TNodeData& GetInNDat(const int& EdgeN) { return Net->GetNDat(GetInNId(EdgeN)); }
1191  const TNodeData& GetOutNDat(const int& EdgeN) const { return Net->GetNDat(GetOutNId(EdgeN)); }
1192  TNodeData& GetOutNDat(const int& EdgeN) { return Net->GetNDat(GetOutNId(EdgeN)); }
1193  const TNodeData& GetNbrNDat(const int& EdgeN) const { return Net->GetNDat(GetNbrNId(EdgeN)); }
1194  TNodeData& GetNbrNDat(const int& EdgeN) { return Net->GetNDat(GetNbrNId(EdgeN)); }
1195  // edges
1197  int GetInEId(const int& EdgeN) const { return NodeHI.GetDat().GetInEId(EdgeN); }
1199  int GetOutEId(const int& EdgeN) const { return NodeHI.GetDat().GetOutEId(EdgeN); }
1201  int GetNbrEId(const int& EdgeN) const { return NodeHI.GetDat().GetNbrEId(EdgeN); }
1203  bool IsInEId(const int& EId) const { return NodeHI.GetDat().IsInEId(EId); }
1205  bool IsOutEId(const int& EId) const { return NodeHI.GetDat().IsOutEId(EId); }
1207  bool IsNbrEId(const int& EId) const { return NodeHI.GetDat().IsNbrEId(EId); }
1208  // edge data
1209  TEdgeDat& GetInEDat(const int& EdgeN) { return Net->GetEDat(GetInEId(EdgeN)); }
1210  const TEdgeDat& GetInEDat(const int& EdgeN) const { return Net->GetEDat(GetInEId(EdgeN)); }
1211  TEdgeDat& GetOutEDat(const int& EdgeN) { return Net->GetEDat(GetOutEId(EdgeN)); }
1212  const TEdgeDat& GetOutEDat(const int& EdgeN) const { return Net->GetEDat(GetOutEId(EdgeN)); }
1213  TEdgeDat& GetNbrEDat(const int& EdgeN) { return Net->GetEDat(GetNbrEId(EdgeN)); }
1214  const TEdgeDat& GetNbrEDat(const int& EdgeN) const { return Net->GetEDat(GetNbrEId(EdgeN)); }
1215  friend class TNodeEdgeNet;
1216  };
1217 
1219  class TEdgeI {
1220  private:
1222  THashIter EdgeHI;
1224  public:
1225  TEdgeI() : EdgeHI(), Net(NULL) { }
1226  TEdgeI(const THashIter& EdgeHIter, const TNodeEdgeNet *NetPt) : EdgeHI(EdgeHIter), Net((TNodeEdgeNet *) NetPt) { }
1227  TEdgeI(const TEdgeI& EdgeI) : EdgeHI(EdgeI.EdgeHI), Net(EdgeI.Net) { }
1228  TEdgeI& operator = (const TEdgeI& EdgeI) { if (this!=&EdgeI) { EdgeHI=EdgeI.EdgeHI; Net=EdgeI.Net; } return *this; }
1229  TEdgeI& operator++ (int) { EdgeHI++; return *this; }
1230  bool operator < (const TEdgeI& EdgeI) const { return EdgeHI < EdgeI.EdgeHI; }
1231  bool operator == (const TEdgeI& EdgeI) const { return EdgeHI == EdgeI.EdgeHI; }
1233  int GetId() const { return EdgeHI.GetDat().GetId(); }
1235  int GetSrcNId() const { return EdgeHI.GetDat().GetSrcNId(); }
1237  int GetDstNId() const { return EdgeHI.GetDat().GetDstNId(); }
1238  const TEdgeData& operator () () const { return EdgeHI.GetDat().GetDat(); }
1239  TEdgeData& operator () () { return EdgeHI.GetDat().GetDat(); }
1240  const TEdgeData& GetDat() const { return EdgeHI.GetDat().GetDat(); }
1241  TEdgeData& GetDat() { return EdgeHI.GetDat().GetDat(); }
1242  const TNodeData& GetSrcNDat() const { return Net->GetNDat(GetSrcNId()); }
1243  TNodeData& GetSrcNDat() { return Net->GetNDat(GetSrcNId()); }
1244  const TNodeData& GetDstNDat() const { return Net->GetNDat(GetDstNId()); }
1245  TNodeData& GetDstNDat() { return Net->GetNDat(GetDstNId()); }
1246  friend class TNodeEdgeNet;
1247  };
1248 
1249 private:
1250  TNode& GetNode(const int& NId) { return NodeH.GetDat(NId); }
1251  const TNode& GetNode(const int& NId) const { return NodeH.GetDat(NId); }
1252  const TNode& GetNodeKId(const int& NodeKeyId) const { return NodeH[NodeKeyId]; }
1253  TEdge& GetEdge(const int& EId) { return EdgeH.GetDat(EId); }
1254  const TEdge& GetEdge(const int& EId) const { return EdgeH.GetDat(EId); }
1255  const TEdge& GetEdgeKId(const int& EdgeKeyId) const { return EdgeH[EdgeKeyId]; }
1256 protected:
1261 private:
1263  public:
1265  void operator() (TNode* n, TShMIn& ShMIn) { n->LoadShM(ShMIn);}
1266  };
1267 private:
1268  void LoadNetworkShM(TShMIn& ShMIn) {
1269  MxNId = TInt(ShMIn);
1270  MxEId = TInt(ShMIn);
1271  LoadTNodeFunctor fn;
1272  NodeH.LoadShM(ShMIn, fn);
1273  EdgeH.LoadShM(ShMIn);
1274  }
1275 public:
1276  TNodeEdgeNet() : CRef(), MxNId(0), MxEId(0) { }
1278  explicit TNodeEdgeNet(const int& Nodes, const int& Edges) : CRef(), MxNId(0), MxEId(0) { Reserve(Nodes, Edges); }
1279  TNodeEdgeNet(const TNodeEdgeNet& Net) : MxNId(Net.MxNId), MxEId(Net.MxEId), NodeH(Net.NodeH), EdgeH(Net.EdgeH) { }
1281  TNodeEdgeNet(TSIn& SIn) : MxNId(SIn), MxEId(SIn), NodeH(SIn), EdgeH(SIn) { }
1282  virtual ~TNodeEdgeNet() { }
1284  virtual void Save(TSOut& SOut) const { MxNId.Save(SOut); MxEId.Save(SOut); NodeH.Save(SOut); EdgeH.Save(SOut); }
1286 
1288  static PNet New() { return PNet(new TNet()); }
1290  static PNet Load(TSIn& SIn) { return PNet(new TNet(SIn)); }
1292 
1296  static PNet LoadShM(TShMIn& ShMIn) {
1297  TNet* Network = new TNet();
1298  Network->LoadNetworkShM(ShMIn);
1299  return PNet(Network);
1300  }
1302  bool HasFlag(const TGraphFlag& Flag) const;
1304  if (this!=&Net) { NodeH=Net.NodeH; EdgeH=Net.EdgeH; MxNId=Net.MxNId; MxEId=Net.MxEId; } return *this; }
1305  // nodes
1307  int GetNodes() const { return NodeH.Len(); }
1309 
1313  int AddNode(int NId = -1);
1315 
1319  int AddNodeUnchecked(int NId = -1);
1321 
1325  int AddNode(int NId, const TNodeData& NodeDat);
1327  friend class TCrossNet;
1328  int AddNode(const TNodeI& NodeI) { return AddNode(NodeI.GetId(), NodeI.GetDat()); }
1330 
1332  void DelNode(const int& NId);
1334  void DelNode(const TNode& NodeI) { DelNode(NodeI.GetId()); }
1336  bool IsNode(const int& NId) const { return NodeH.IsKey(NId); }
1338  TNodeI BegNI() const { return TNodeI(NodeH.BegI(), this); }
1340  TNodeI EndNI() const { return TNodeI(NodeH.EndI(), this); }
1342  TNodeI GetNI(const int& NId) const { return TNodeI(NodeH.GetI(NId), this); }
1344  void SetNDat(const int& NId, const TNodeData& NodeDat);
1346  TNodeData& GetNDat(const int& NId) { return NodeH.GetDat(NId).NodeDat; }
1348  const TNodeData& GetNDat(const int& NId) const { return NodeH.GetDat(NId).NodeDat; }
1350  int GetMxNId() const { return MxNId; }
1351 
1352  // edges
1354  int GetEdges() const { return EdgeH.Len(); }
1356  int GetUniqEdges(const bool& IsDir=true) const;
1358 
1363  int AddEdge(const int& SrcNId, const int& DstNId, int EId = -1);
1365 
1370  int AddEdge(const int& SrcNId, const int& DstNId, int EId, const TEdgeData& EdgeDat);
1372  int AddEdge(const TEdgeI& EdgeI) { return AddEdge(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), EdgeI.GetId(), EdgeI.GetDat()); }
1374  void DelEdge(const int& EId);
1376 
1380  void DelEdge(const int& SrcNId, const int& DstNId, const bool& IsDir = true);
1382  bool IsEdge(const int& EId) const { return EdgeH.IsKey(EId); }
1384  bool IsEdge(const int& SrcNId, const int& DstNId, const bool& IsDir = true) const { int EId; return IsEdge(SrcNId, DstNId, EId, IsDir); }
1386  bool IsEdge(const int& SrcNId, const int& DstNId, int& EId, const bool& IsDir = true) const;
1387  int GetEId(const int& SrcNId, const int& DstNId) const { int EId; return IsEdge(SrcNId, DstNId, EId)?EId:-1; }
1389  TEdgeI BegEI() const { return TEdgeI(EdgeH.BegI(), this); }
1391  TEdgeI EndEI() const { return TEdgeI(EdgeH.EndI(), this); }
1393  TEdgeI GetEI(const int& EId) const { return TEdgeI(EdgeH.GetI(EId), this); }
1395  TEdgeI GetEI(const int& SrcNId, const int& DstNId) const { return GetEI(GetEId(SrcNId, DstNId)); }
1397  void SetEDat(const int& EId, const TEdgeData& EdgeDat);
1399  TEdgeData& GetEDat(const int& EId) { return EdgeH.GetDat(EId).EdgeDat; }
1401  const TEdgeData& GetEDat(const int& EId) const { return EdgeH.GetDat(EId).EdgeDat; }
1403  void SetAllEDat(const TEdgeData& EdgeDat);
1404 
1406  int GetRndNId(TRnd& Rnd=TInt::Rnd) { return NodeH.GetKey(NodeH.GetRndKeyId(Rnd, 0.8)); }
1408  TNodeI GetRndNI(TRnd& Rnd=TInt::Rnd) { return GetNI(GetRndNId(Rnd)); }
1410  int GetRndEId(TRnd& Rnd=TInt::Rnd) { return EdgeH.GetKey(EdgeH.GetRndKeyId(Rnd, 0.8)); }
1412  TEdgeI GetRndEI(TRnd& Rnd=TInt::Rnd) { return GetEI(GetRndEId(Rnd)); }
1414  void GetNIdV(TIntV& NIdV) const;
1416  void GetEIdV(TIntV& EIdV) const;
1417 
1419  bool Empty() const { return GetNodes()==0; }
1421  void Clr() { MxNId=0; MxEId=0; NodeH.Clr(); EdgeH.Clr(); }
1423  void Reserve(const int& Nodes, const int& Edges) {
1424  if (Nodes>0) { NodeH.Gen(Nodes/2); } if (Edges>0) { EdgeH.Gen(Edges/2); } }
1426  void SortNIdById(const bool& Asc=true) { NodeH.SortByKey(Asc); }
1428  void SortNIdByDat(const bool& Asc=true) { NodeH.SortByDat(Asc); }
1430  void SortEIdById(const bool& Asc=true) { EdgeH.SortByKey(Asc); }
1432  void SortEIdByDat(const bool& Asc=true) { EdgeH.SortByDat(Asc); }
1434 
1439  void Defrag(const bool& OnlyNodeLinks=false);
1441 
1444  bool IsOk(const bool& ThrowExcept=true) const;
1445 
1446  friend class TPt<TNodeEdgeNet<TNodeData, TEdgeData> >;
1447 };
1448 
1449 // set flags
1450 namespace TSnap {
1451 template <class TNodeData, class TEdgeData> struct IsMultiGraph<TNodeEdgeNet<TNodeData, TEdgeData> > { enum { Val = 1 }; };
1452 template <class TNodeData, class TEdgeData> struct IsDirected<TNodeEdgeNet<TNodeData, TEdgeData> > { enum { Val = 1 }; };
1453 template <class TNodeData, class TEdgeData> struct IsNodeDat<TNodeEdgeNet<TNodeData, TEdgeData> > { enum { Val = 1 }; };
1454 template <class TNodeData, class TEdgeData> struct IsEdgeDat<TNodeEdgeNet<TNodeData, TEdgeData> > { enum { Val = 1 }; };
1455 }
1456 
1457 template <class TNodeData, class TEdgeData>
1459  return HasGraphFlag(typename TNet, Flag);
1460 }
1461 
1462 template <class TNodeData, class TEdgeData>
1464  const TNode& Node = NodeHI.GetDat();
1465  for (int edge = 0; edge < Node.GetInDeg(); edge++) {
1466  if (NId == Net->GetEdge(Node.GetInEId(edge)).GetSrcNId())
1467  return true;
1468  }
1469  return false;
1470 }
1471 
1472 template <class TNodeData, class TEdgeData>
1474  const TNode& Node = NodeHI.GetDat();
1475  for (int edge = 0; edge < Node.GetOutDeg(); edge++) {
1476  if (NId == Net->GetEdge(Node.GetOutEId(edge)).GetDstNId())
1477  return true;
1478  }
1479  return false;
1480 }
1481 
1482 template <class TNodeData, class TEdgeData>
1484  if (NId == -1) {
1485  NId = MxNId; MxNId++;
1486  } else {
1487  IAssertR(!IsNode(NId), TStr::Fmt("NodeId %d already exists", NId));
1488  MxNId = TMath::Mx(NId+1, MxNId());
1489  }
1490  NodeH.AddDat(NId, TNode(NId));
1491  return NId;
1492 }
1493 
1494 template <class TNodeData, class TEdgeData>
1496  if (NId == -1) {
1497  NId = MxNId; MxNId++;
1498  } else {
1499  if (IsNode(NId)) { return -1;}
1500  MxNId = TMath::Mx(NId+1, MxNId());
1501  }
1502  NodeH.AddDat(NId, TNode(NId));
1503  return NId;
1504 }
1505 
1506 template <class TNodeData, class TEdgeData>
1507 int TNodeEdgeNet<TNodeData, TEdgeData>::AddNode(int NId, const TNodeData& NodeDat) {
1508  if (NId == -1) {
1509  NId = MxNId; MxNId++;
1510  } else {
1511  IAssertR(!IsNode(NId), TStr::Fmt("NodeId %d already exists", NId));
1512  MxNId = TMath::Mx(NId+1, MxNId());
1513  }
1514  NodeH.AddDat(NId, TNode(NId, NodeDat));
1515  return NId;
1516 }
1517 
1518 template <class TNodeData, class TEdgeData>
1520  const TNode& Node = GetNode(NId);
1521  for (int out = 0; out < Node.GetOutDeg(); out++) {
1522  const int EId = Node.GetOutEId(out);
1523  const TEdge& Edge = GetEdge(EId);
1524  IAssert(Edge.GetSrcNId() == NId);
1525  GetNode(Edge.GetDstNId()).InEIdV.DelIfIn(EId);
1526  EdgeH.DelKey(EId);
1527  }
1528  for (int in = 0; in < Node.GetInDeg(); in++) {
1529  const int EId = Node.GetInEId(in);
1530  const TEdge& Edge = GetEdge(EId);
1531  IAssert(Edge.GetDstNId() == NId);
1532  GetNode(Edge.GetSrcNId()).OutEIdV.DelIfIn(EId);
1533  EdgeH.DelKey(EId);
1534  }
1535  NodeH.DelKey(NId);
1536 }
1537 
1538 template <class TNodeData, class TEdgeData>
1539 void TNodeEdgeNet<TNodeData, TEdgeData>::SetNDat(const int& NId, const TNodeData& NodeDat) {
1540  IAssertR(IsNode(NId), TStr::Fmt("NodeId %d does not exist.", NId).CStr());
1541  NodeH.GetDat(NId).NodeDat = NodeDat;
1542 }
1543 
1544 template <class TNodeData, class TEdgeData>
1546  TIntPrSet UniqESet(GetEdges());
1547  for (TEdgeI EI = BegEI(); EI < EndEI(); EI++) {
1548  const int Src = EI.GetSrcNId();
1549  const int Dst = EI.GetDstNId();
1550  if (IsDir) { UniqESet.AddKey(TIntPr(Src, Dst)); }
1551  else { UniqESet.AddKey(TIntPr(TMath::Mn(Src, Dst), TMath::Mx(Src, Dst))); }
1552  }
1553  return UniqESet.Len();
1554 }
1555 
1556 template <class TNodeData, class TEdgeData>
1557 int TNodeEdgeNet<TNodeData, TEdgeData>::AddEdge(const int& SrcNId, const int& DstNId, int EId) {
1558  if (EId == -1) { EId = MxEId; MxEId++; }
1559  else { MxEId = TMath::Mx(EId+1, MxEId()); }
1560  IAssertR(!IsEdge(EId), TStr::Fmt("EdgeId %d already exists", EId));
1561  IAssertR(IsNode(SrcNId) && IsNode(DstNId), TStr::Fmt("%d or %d not a node.", SrcNId, DstNId).CStr());
1562  EdgeH.AddDat(EId, TEdge(EId, SrcNId, DstNId));
1563  GetNode(SrcNId).OutEIdV.AddSorted(EId);
1564  GetNode(DstNId).InEIdV.AddSorted(EId);
1565  return EId;
1566 }
1567 
1568 template <class TNodeData, class TEdgeData>
1569 int TNodeEdgeNet<TNodeData, TEdgeData>::AddEdge(const int& SrcNId, const int& DstNId, int EId, const TEdgeData& EdgeDat) {
1570  if (EId == -1) { EId = MxEId; MxEId++; }
1571  else { MxEId = TMath::Mx(EId+1, MxEId()); }
1572  IAssertR(!IsEdge(EId), TStr::Fmt("EdgeId %d already exists", EId));
1573  IAssertR(IsNode(SrcNId) && IsNode(DstNId), TStr::Fmt("%d or %d not a node.", SrcNId, DstNId).CStr());
1574  EdgeH.AddDat(EId, TEdge(EId, SrcNId, DstNId, EdgeDat));
1575  GetNode(SrcNId).OutEIdV.AddSorted(EId);
1576  GetNode(DstNId).InEIdV.AddSorted(EId);
1577  return EId;
1578 }
1579 
1580 template <class TNodeData, class TEdgeData>
1582  IAssert(IsEdge(EId));
1583  const int SrcNId = GetEdge(EId).GetSrcNId();
1584  const int DstNId = GetEdge(EId).GetDstNId();
1585  GetNode(SrcNId).OutEIdV.DelIfIn(EId);
1586  GetNode(DstNId).InEIdV.DelIfIn(EId);
1587  EdgeH.DelKey(EId);
1588 }
1589 
1590 template <class TNodeData, class TEdgeData>
1591 void TNodeEdgeNet<TNodeData, TEdgeData>::DelEdge(const int& SrcNId, const int& DstNId, const bool& IsDir) {
1592  int EId;
1593  IAssert(IsEdge(SrcNId, DstNId, EId, IsDir));
1594  GetNode(SrcNId).OutEIdV.DelIfIn(EId);
1595  GetNode(DstNId).InEIdV.DelIfIn(EId);
1596  EdgeH.DelKey(EId);
1597 }
1598 
1599 template <class TNodeData, class TEdgeData>
1600 bool TNodeEdgeNet<TNodeData, TEdgeData>::IsEdge(const int& SrcNId, const int& DstNId, int& EId, const bool& IsDir) const {
1601  if (! IsNode(SrcNId)) { return false; }
1602  if (! IsNode(DstNId)) { return false; }
1603  const TNode& SrcNode = GetNode(SrcNId);
1604  for (int edge = 0; edge < SrcNode.GetOutDeg(); edge++) {
1605  const TEdge& Edge = GetEdge(SrcNode.GetOutEId(edge));
1606  if (DstNId == Edge.GetDstNId()) {
1607  EId = Edge.GetId(); return true; }
1608  }
1609  if (! IsDir) {
1610  for (int edge = 0; edge < SrcNode.GetInDeg(); edge++) {
1611  const TEdge& Edge = GetEdge(SrcNode.GetInEId(edge));
1612  if (DstNId == Edge.GetSrcNId()) {
1613  EId = Edge.GetId(); return true; }
1614  }
1615  }
1616  return false;
1617 }
1618 
1619 template <class TNodeData, class TEdgeData>
1620 void TNodeEdgeNet<TNodeData, TEdgeData>::SetEDat(const int& EId, const TEdgeData& EdgeDat) {
1621  IAssertR(IsEdge(EId), TStr::Fmt("EdgeId %d does not exist.", EId).CStr());
1622  GetEI(EId).GetDat() = EdgeDat;
1623 }
1624 
1625 template <class TNodeData, class TEdgeData>
1626 void TNodeEdgeNet<TNodeData, TEdgeData>::SetAllEDat(const TEdgeData& EdgeDat) {
1627  for (TEdgeI EI = BegEI(); EI < EndEI(); EI++) {
1628  EI() = EdgeDat;
1629  }
1630 }
1631 
1632 
1633 template <class TNodeData, class TEdgeData>
1635  NIdV.Gen(GetNodes(), 0);
1636  for (int N=NodeH.FFirstKeyId(); NodeH.FNextKeyId(N);) {
1637  NIdV.Add(NodeH.GetKey(N));
1638  }
1639 }
1640 
1641 template <class TNodeData, class TEdgeData>
1643  EIdV.Gen(GetEdges(), 0);
1644  for (int E=EdgeH.FFirstKeyId(); EdgeH.FNextKeyId(E);) {
1645  EIdV.Add(EdgeH.GetKey(E));
1646  }
1647 }
1648 
1649 template <class TNodeData, class TEdgeData>
1650 void TNodeEdgeNet<TNodeData, TEdgeData>::Defrag(const bool& OnlyNodeLinks) {
1651  for (int kid = NodeH.FFirstKeyId(); NodeH.FNextKeyId(kid);) {
1652  TNode& Node = NodeH[kid];
1653  Node.InEIdV.Pack(); Node.OutEIdV.Pack();
1654  }
1655  if (! OnlyNodeLinks && ! NodeH.IsKeyIdEqKeyN()) { NodeH.Defrag(); }
1656  if (! OnlyNodeLinks && ! EdgeH.IsKeyIdEqKeyN()) { EdgeH.Defrag(); }
1657 }
1658 
1659 template <class TNodeData, class TEdgeData>
1660 bool TNodeEdgeNet<TNodeData, TEdgeData>::IsOk(const bool& ThrowExcept) const {
1661  bool RetVal = true;
1662  for (int N = NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
1663  const TNode& Node = NodeH[N];
1664  if (! Node.OutEIdV.IsSorted()) {
1665  const TStr Msg = TStr::Fmt("Out-edge list of node %d is not sorted.", Node.GetId());
1666  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
1667  }
1668  if (! Node.InEIdV.IsSorted()) {
1669  const TStr Msg = TStr::Fmt("In-edge list of node %d is not sorted.", Node.GetId());
1670  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
1671  }
1672  // check out-edge ids
1673  int prevEId = -1;
1674  for (int e = 0; e < Node.GetOutDeg(); e++) {
1675  if (! IsEdge(Node.GetOutEId(e))) {
1676  const TStr Msg = TStr::Fmt("Out-edge id %d of node %d does not exist.", Node.GetOutEId(e), Node.GetId());
1677  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
1678  }
1679  if (e > 0 && prevEId == Node.GetOutEId(e)) {
1680  const TStr Msg = TStr::Fmt("Node %d has duplidate out-edge id %d.", Node.GetId(), Node.GetOutEId(e));
1681  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
1682  }
1683  prevEId = Node.GetOutEId(e);
1684  }
1685  // check in-edge ids
1686  prevEId = -1;
1687  for (int e = 0; e < Node.GetInDeg(); e++) {
1688  if (! IsEdge(Node.GetInEId(e))) {
1689  const TStr Msg = TStr::Fmt("Out-edge id %d of node %d does not exist.", Node.GetInEId(e), Node.GetId());
1690  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
1691  }
1692  if (e > 0 && prevEId == Node.GetInEId(e)) {
1693  const TStr Msg = TStr::Fmt("Node %d has duplidate out-edge id %d.", Node.GetId(), Node.GetInEId(e));
1694  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
1695  }
1696  prevEId = Node.GetInEId(e);
1697  }
1698  }
1699  for (int E = EdgeH.FFirstKeyId(); EdgeH.FNextKeyId(E); ) {
1700  const TEdge& Edge = EdgeH[E];
1701  if (! IsNode(Edge.GetSrcNId())) {
1702  const TStr Msg = TStr::Fmt("Edge %d source node %d does not exist.", Edge.GetId(), Edge.GetSrcNId());
1703  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
1704  }
1705  if (! IsNode(Edge.GetDstNId())) {
1706  const TStr Msg = TStr::Fmt("Edge %d destination node %d does not exist.", Edge.GetId(), Edge.GetDstNId());
1707  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
1708  }
1709  }
1710  return RetVal;
1711 }
1712 
1714 // Common Node-Edge Network Types
1719 
1720 class TNEANet;
1722 typedef TPt<TNEANet> PNEANet;
1723 
1724 //#//////////////////////////////////////////////
1726 
1741 class TNEANet {
1742 public:
1743  typedef TNEANet TNet;
1745 public:
1746  class TNode {
1747  private:
1749  TIntV InEIdV, OutEIdV;
1750  public:
1751  TNode() : Id(-1), InEIdV(), OutEIdV() { }
1752  TNode(const int& NId) : Id(NId), InEIdV(), OutEIdV() { }
1753  TNode(const TNode& Node) : Id(Node.Id), InEIdV(Node.InEIdV), OutEIdV(Node.OutEIdV) { }
1754  TNode(TSIn& SIn) : Id(SIn), InEIdV(SIn), OutEIdV(SIn) { }
1755  void Save(TSOut& SOut) const { Id.Save(SOut); InEIdV.Save(SOut); OutEIdV.Save(SOut); }
1756  int GetId() const { return Id; }
1757  int GetDeg() const { return GetInDeg() + GetOutDeg(); }
1758  int GetInDeg() const { return InEIdV.Len(); }
1759  int GetOutDeg() const { return OutEIdV.Len(); }
1760  int GetInEId(const int& EdgeN) const { return InEIdV[EdgeN]; }
1761  int GetOutEId(const int& EdgeN) const { return OutEIdV[EdgeN]; }
1762  int GetNbrEId(const int& EdgeN) const { return EdgeN<GetOutDeg()?GetOutEId(EdgeN):GetInEId(EdgeN-GetOutDeg()); }
1763  bool IsInEId(const int& EId) const { return InEIdV.SearchBin(EId) != -1; }
1764  bool IsOutEId(const int& EId) const { return OutEIdV.SearchBin(EId) != -1; }
1765  void LoadShM(TShMIn& MStream) {
1766  Id = TInt(MStream);
1767  InEIdV.LoadShM(MStream);
1768  OutEIdV.LoadShM(MStream);
1769  }
1770  friend class TNEANet;
1771  };
1772  class TEdge {
1773  private:
1774  TInt Id, SrcNId, DstNId;
1775  public:
1776  TEdge() : Id(-1), SrcNId(-1), DstNId(-1) { }
1777  TEdge(const int& EId, const int& SourceNId, const int& DestNId) : Id(EId), SrcNId(SourceNId), DstNId(DestNId) { }
1778  TEdge(const TEdge& Edge) : Id(Edge.Id), SrcNId(Edge.SrcNId), DstNId(Edge.DstNId) { }
1779  TEdge(TSIn& SIn) : Id(SIn), SrcNId(SIn), DstNId(SIn) { }
1780  void Save(TSOut& SOut) const { Id.Save(SOut); SrcNId.Save(SOut); DstNId.Save(SOut); }
1781  int GetId() const { return Id; }
1782  int GetSrcNId() const { return SrcNId; }
1783  int GetDstNId() const { return DstNId; }
1784  void Load(TSIn& InStream) {
1785  Id = TInt(InStream);
1786  SrcNId = TInt(InStream);
1787  DstNId = TInt(InStream);
1788  }
1789  friend class TNEANet;
1790  };
1792  class TNodeI {
1793  protected:
1795  THashIter NodeHI;
1796  const TNEANet *Graph;
1797  public:
1798  TNodeI() : NodeHI(), Graph(NULL) { }
1799  TNodeI(const THashIter& NodeHIter, const TNEANet* GraphPt) : NodeHI(NodeHIter), Graph(GraphPt) { }
1800  TNodeI(const TNodeI& NodeI) : NodeHI(NodeI.NodeHI), Graph(NodeI.Graph) { }
1801  TNodeI& operator = (const TNodeI& NodeI) { NodeHI = NodeI.NodeHI; Graph=NodeI.Graph; return *this; }
1803  TNodeI& operator++ (int) { NodeHI++; return *this; }
1804  bool operator < (const TNodeI& NodeI) const { return NodeHI < NodeI.NodeHI; }
1805  bool operator == (const TNodeI& NodeI) const { return NodeHI == NodeI.NodeHI; }
1807  int GetId() const { return NodeHI.GetDat().GetId(); }
1809  int GetDeg() const { return NodeHI.GetDat().GetDeg(); }
1811  int GetInDeg() const { return NodeHI.GetDat().GetInDeg(); }
1813  int GetOutDeg() const { return NodeHI.GetDat().GetOutDeg(); }
1815 
1817  int GetInNId(const int& EdgeN) const { return Graph->GetEdge(NodeHI.GetDat().GetInEId(EdgeN)).GetSrcNId(); }
1819 
1821  int GetOutNId(const int& EdgeN) const { return Graph->GetEdge(NodeHI.GetDat().GetOutEId(EdgeN)).GetDstNId(); }
1823 
1825  int GetNbrNId(const int& EdgeN) const { const TEdge& E = Graph->GetEdge(NodeHI.GetDat().GetNbrEId(EdgeN)); return GetId()==E.GetSrcNId() ? E.GetDstNId():E.GetSrcNId(); }
1827  bool IsInNId(const int& NId) const;
1829  bool IsOutNId(const int& NId) const;
1831  bool IsNbrNId(const int& NId) const { return IsOutNId(NId) || IsInNId(NId); }
1833  int GetInEId(const int& EdgeN) const { return NodeHI.GetDat().GetInEId(EdgeN); }
1835  int GetOutEId(const int& EdgeN) const { return NodeHI.GetDat().GetOutEId(EdgeN); }
1837  int GetNbrEId(const int& EdgeN) const { return NodeHI.GetDat().GetNbrEId(EdgeN); }
1839  bool IsInEId(const int& EId) const { return NodeHI.GetDat().IsInEId(EId); }
1841  bool IsOutEId(const int& EId) const { return NodeHI.GetDat().IsOutEId(EId); }
1843  bool IsNbrEId(const int& EId) const { return IsInEId(EId) || IsOutEId(EId); }
1845  void GetAttrNames(TStrV& Names) const { Graph->AttrNameNI(GetId(), Names); }
1847  void GetAttrVal(TStrV& Val) const { Graph->AttrValueNI(GetId(), Val); }
1849  void GetIntAttrNames(TStrV& Names) const { Graph->IntAttrNameNI(GetId(), Names); }
1851  void GetIntAttrVal(TIntV& Val) const { Graph->IntAttrValueNI(GetId(), Val); }
1853  void GetIntVAttrNames(TStrV& Names) const { Graph->IntVAttrNameNI(GetId(), Names); }
1855  void GetIntVAttrVal(TVec<TIntV>& Val) const { Graph->IntVAttrValueNI(GetId(), Val); }
1857  void GetStrAttrNames(TStrV& Names) const { Graph->StrAttrNameNI(GetId(), Names); }
1859  void GetStrAttrVal(TStrV& Val) const { Graph->StrAttrValueNI(GetId(), Val); }
1861  void GetFltAttrNames(TStrV& Names) const { Graph->FltAttrNameNI(GetId(), Names); }
1863  void GetFltAttrVal(TFltV& Val) const { Graph->FltAttrValueNI(GetId(), Val); }
1864  friend class TNEANet;
1865  };
1867  class TEdgeI {
1868  private:
1870  THashIter EdgeHI;
1871  const TNEANet *Graph;
1872  public:
1873  TEdgeI() : EdgeHI(), Graph(NULL) { }
1874  TEdgeI(const THashIter& EdgeHIter, const TNEANet *GraphPt) : EdgeHI(EdgeHIter), Graph(GraphPt) { }
1875  TEdgeI(const TEdgeI& EdgeI) : EdgeHI(EdgeI.EdgeHI), Graph(EdgeI.Graph) { }
1876  TEdgeI& operator = (const TEdgeI& EdgeI) { if (this!=&EdgeI) { EdgeHI=EdgeI.EdgeHI; Graph=EdgeI.Graph; } return *this; }
1878  TEdgeI& operator++ (int) { EdgeHI++; return *this; }
1879  bool operator < (const TEdgeI& EdgeI) const { return EdgeHI < EdgeI.EdgeHI; }
1880  bool operator == (const TEdgeI& EdgeI) const { return EdgeHI == EdgeI.EdgeHI; }
1882  int GetId() const { return EdgeHI.GetDat().GetId(); }
1884  int GetSrcNId() const { return EdgeHI.GetDat().GetSrcNId(); }
1886  int GetDstNId() const { return EdgeHI.GetDat().GetDstNId(); }
1888  void GetAttrNames(TStrV& Names) const { Graph->AttrNameEI(GetId(), Names); }
1890  void GetAttrVal(TStrV& Val) const { Graph->AttrValueEI(GetId(), Val); }
1892  void GetIntAttrNames(TStrV& Names) const { Graph->IntAttrNameEI(GetId(), Names); }
1894  void GetIntAttrVal(TIntV& Val) const { Graph->IntAttrValueEI(GetId(), Val); }
1896  void GetIntVAttrNames(TStrV& Names) const { Graph->IntVAttrNameEI(GetId(), Names); }
1898  void GetIntVAttrVal(TVec<TIntV>& Val) const { Graph->IntVAttrValueEI(GetId(), Val); }
1900  void GetStrAttrNames(TStrV& Names) const { Graph->StrAttrNameEI(GetId(), Names); }
1902  void GetStrAttrVal(TStrV& Val) const { Graph->StrAttrValueEI(GetId(), Val); }
1904  void GetFltAttrNames(TStrV& Names) const { Graph->FltAttrNameEI(GetId(), Names); }
1906  void GetFltAttrVal(TFltV& Val) const { Graph->FltAttrValueEI(GetId(), Val); }
1907  friend class TNEANet;
1908  };
1909 
1911  class TAIntI {
1912  private:
1914  TIntVecIter HI;
1915  bool isNode;
1917  const TNEANet *Graph;
1918  public:
1919  TAIntI() : HI(), attr(), Graph(NULL) { }
1920  TAIntI(const TIntVecIter& HIter, TStr attribute, bool isEdgeIter, const TNEANet* GraphPt) : HI(HIter), attr(), Graph(GraphPt) { isNode = !isEdgeIter; attr = attribute; }
1921  TAIntI(const TAIntI& I) : HI(I.HI), attr(I.attr), Graph(I.Graph) { isNode = I.isNode; }
1922  TAIntI& operator = (const TAIntI& I) { HI = I.HI; Graph=I.Graph; isNode = I.isNode; attr = I.attr; return *this; }
1923  bool operator < (const TAIntI& I) const { return HI < I.HI; }
1924  bool operator == (const TAIntI& I) const { return HI == I.HI; }
1926  TInt GetDat() const { return HI[0]; }
1928  bool IsDeleted() const { return isNode ? GetDat() == Graph->GetIntAttrDefaultN(attr) : GetDat() == Graph->GetIntAttrDefaultE(attr); };
1929  TAIntI& operator++(int) { HI++; return *this; }
1930  friend class TNEANet;
1931  };
1932 
1933  class TAIntVI {
1934  private:
1936  TIntVVecIter HI;
1937  bool IsDense;
1939  TIntHVecIter HHI;
1940  bool isNode;
1942  const TNEANet *Graph;
1943  public:
1944  TAIntVI() : HI(), IsDense(), HHI(), attr(), Graph(NULL) { }
1945  TAIntVI(const TIntVVecIter& HIter, const TIntHVecIter& HHIter, TStr attribute, bool isEdgeIter, const TNEANet* GraphPt, bool is_dense) : HI(HIter), IsDense(is_dense), HHI(HHIter), attr(), Graph(GraphPt) {
1946  isNode = !isEdgeIter; attr = attribute;
1947  }
1948  TAIntVI(const TAIntVI& I) : HI(I.HI), IsDense(I.IsDense), HHI(I.HHI), attr(I.attr), Graph(I.Graph) { isNode = I.isNode; }
1949  TAIntVI& operator = (const TAIntVI& I) { HI = I.HI; HHI = I.HHI, Graph=I.Graph; isNode = I.isNode; attr = I.attr; return *this; }
1950  bool operator < (const TAIntVI& I) const { return HI == I.HI ? HHI < I.HHI : HI < I.HI; }
1951  bool operator == (const TAIntVI& I) const { return HI == I.HI && HHI == I.HHI; }
1953  TIntV GetDat() const { return IsDense? HI[0] : HHI.GetDat(); }
1954  TAIntVI& operator++(int) { if (IsDense) {HI++;} else {HHI++;} return *this; }
1955  friend class TNEANet;
1956  };
1957 
1958  class TAFltVI {
1959  private:
1961  TFltVVecIter HI;
1962  bool IsDense;
1964  TFltHVecIter HHI;
1965  bool isNode;
1967  const TNEANet *Graph;
1968  public:
1969  TAFltVI() : HI(), IsDense(), HHI(), attr(), Graph(NULL) { }
1970  TAFltVI(const TFltVVecIter& HIter, const TFltHVecIter& HHIter, TStr attribute, bool isEdgeIter, const TNEANet* GraphPt, bool is_dense) : HI(HIter), IsDense(is_dense), HHI(HHIter), attr(), Graph(GraphPt) {
1971  isNode = !isEdgeIter; attr = attribute;
1972  }
1973  TAFltVI(const TAFltVI& I) : HI(I.HI), IsDense(I.IsDense), HHI(I.HHI), attr(I.attr), Graph(I.Graph) { isNode = I.isNode; }
1974  TAFltVI& operator = (const TAFltVI& I) { HI = I.HI; HHI = I.HHI, Graph=I.Graph; isNode = I.isNode; attr = I.attr; return *this; }
1975  bool operator < (const TAFltVI& I) const { return HI == I.HI ? HHI < I.HHI : HI < I.HI; }
1976  bool operator == (const TAFltVI& I) const { return HI == I.HI && HHI == I.HHI; }
1978  TFltV GetDat() const { return IsDense? HI[0] : HHI.GetDat(); }
1979  TAFltVI& operator++(int) { if (IsDense) {HI++;} else {HHI++;} return *this; }
1980  friend class TNEANet;
1981  };
1982 
1984  class TAStrI {
1985  private:
1987  TStrVecIter HI;
1988  bool isNode;
1990  const TNEANet *Graph;
1991  public:
1992  TAStrI() : HI(), attr(), Graph(NULL) { }
1993  TAStrI(const TStrVecIter& HIter, TStr attribute, bool isEdgeIter, const TNEANet* GraphPt) : HI(HIter), attr(), Graph(GraphPt) { isNode = !isEdgeIter; attr = attribute; }
1994  TAStrI(const TAStrI& I) : HI(I.HI), attr(I.attr), Graph(I.Graph) { isNode = I.isNode; }
1995  TAStrI& operator = (const TAStrI& I) { HI = I.HI; Graph=I.Graph; isNode = I.isNode; attr = I.attr; return *this; }
1996  bool operator < (const TAStrI& I) const { return HI < I.HI; }
1997  bool operator == (const TAStrI& I) const { return HI == I.HI; }
1999  TStr GetDat() const { return HI[0]; }
2001  bool IsDeleted() const { return isNode ? GetDat() == Graph->GetStrAttrDefaultN(attr) : GetDat() == Graph->GetStrAttrDefaultE(attr); };
2002  TAStrI& operator++(int) { HI++; return *this; }
2003  friend class TNEANet;
2004  };
2005 
2007  class TAFltI {
2008  private:
2010  TFltVecIter HI;
2011  bool isNode;
2013  const TNEANet *Graph;
2014  public:
2015  TAFltI() : HI(), attr(), Graph(NULL) { }
2016  TAFltI(const TFltVecIter& HIter, TStr attribute, bool isEdgeIter, const TNEANet* GraphPt) : HI(HIter), attr(), Graph(GraphPt) { isNode = !isEdgeIter; attr = attribute; }
2017  TAFltI(const TAFltI& I) : HI(I.HI), attr(I.attr), Graph(I.Graph) { isNode = I.isNode; }
2018  TAFltI& operator = (const TAFltI& I) { HI = I.HI; Graph=I.Graph; isNode = I.isNode; attr = I.attr; return *this; }
2019  bool operator < (const TAFltI& I) const { return HI < I.HI; }
2020  bool operator == (const TAFltI& I) const { return HI == I.HI; }
2022  TFlt GetDat() const { return HI[0]; }
2024  bool IsDeleted() const { return isNode ? GetDat() == Graph->GetFltAttrDefaultN(attr) : GetDat() == Graph->GetFltAttrDefaultE(attr); };
2025  TAFltI& operator++(int) { HI++; return *this; }
2026  friend class TNEANet;
2027  };
2028 
2029 protected:
2030  TNode& GetNode(const int& NId) { return NodeH.GetDat(NId); }
2031  const TNode& GetNode(const int& NId) const { return NodeH.GetDat(NId); }
2032  TEdge& GetEdge(const int& EId) { return EdgeH.GetDat(EId); }
2033  const TEdge& GetEdge(const int& EId) const { return EdgeH.GetDat(EId); }
2034  int AddAttributes(const int NId);
2035 
2036 protected:
2038  TInt GetIntAttrDefaultN(const TStr& attribute) const { return IntDefaultsN.IsKey(attribute) ? IntDefaultsN.GetDat(attribute) : (TInt) TInt::Mn; }
2040  TStr GetStrAttrDefaultN(const TStr& attribute) const { return StrDefaultsN.IsKey(attribute) ? StrDefaultsN.GetDat(attribute) : (TStr) TStr::GetNullStr(); }
2042  TFlt GetFltAttrDefaultN(const TStr& attribute) const { return FltDefaultsN.IsKey(attribute) ? FltDefaultsN.GetDat(attribute) : (TFlt) TFlt::Mn; }
2044  TInt GetIntAttrDefaultE(const TStr& attribute) const { return IntDefaultsE.IsKey(attribute) ? IntDefaultsE.GetDat(attribute) : (TInt) TInt::Mn; }
2046  TStr GetStrAttrDefaultE(const TStr& attribute) const { return StrDefaultsE.IsKey(attribute) ? StrDefaultsE.GetDat(attribute) : (TStr) TStr::GetNullStr(); }
2048  TFlt GetFltAttrDefaultE(const TStr& attribute) const { return FltDefaultsE.IsKey(attribute) ? FltDefaultsE.GetDat(attribute) : (TFlt) TFlt::Mn; }
2049 public:
2051 protected:
2059 
2071 
2074 private:
2076  public:
2078  void operator() (TNode* n, TShMIn& ShMIn) { n->LoadShM(ShMIn);}
2079  };
2081  public:
2083  template<typename TElem>
2084  void operator() (TVec<TElem>* n, TShMIn& ShMIn) {
2085  n->LoadShM(ShMIn);
2086  }
2087  };
2089  public:
2091  template<typename TElem>
2092  void operator() (TVec<TVec<TElem> >* n, TShMIn& ShMIn) {
2093  LoadVecFunctor f;
2094  n->LoadShM(ShMIn, f);
2095  }
2096  };
2097 
2099  public:
2101  template<typename TElem>
2102  void operator() (THash<TInt, TVec<TElem> >* n, TShMIn& ShMIn) {
2103  LoadVecFunctor f;
2104  n->LoadShM(ShMIn, f);
2105  }
2106  };
2107 
2108 protected:
2110  TInt CheckDenseOrSparseN(const TStr& attr) const {
2111  if (!KeyToDenseN.IsKey(attr)) return -1;
2112  if (KeyToDenseN.GetDat(attr)) return 1;
2113  return 0;
2114  }
2115 
2116  TInt CheckDenseOrSparseE(const TStr& attr) const {
2117  if (!KeyToDenseE.IsKey(attr)) return -1;
2118  if (KeyToDenseE.GetDat(attr)) return 1;
2119  return 0;
2120  }
2121 
2122 
2123 public:
2124  TNEANet() : CRef(), MxNId(0), MxEId(0), NodeH(), EdgeH(),
2125  KeyToIndexTypeN(), KeyToIndexTypeE(), KeyToDenseN(), KeyToDenseE(), IntDefaultsN(), IntDefaultsE(),
2126  StrDefaultsN(), StrDefaultsE(), FltDefaultsN(), FltDefaultsE(),
2127  VecOfIntVecsN(), VecOfIntVecsE(), VecOfStrVecsN(), VecOfStrVecsE(),
2128  VecOfFltVecsN(), VecOfFltVecsE(), VecOfIntVecVecsN(), VecOfIntVecVecsE(),
2129  VecOfFltVecVecsN(), VecOfFltVecVecsE(),
2130  VecOfIntHashVecsN(), VecOfIntHashVecsE(),
2131  VecOfFltHashVecsN(), VecOfFltHashVecsE(),
2132  SAttrN(), SAttrE(){ }
2134  explicit TNEANet(const int& Nodes, const int& Edges) : CRef(),
2135  MxNId(0), MxEId(0), NodeH(), EdgeH(), KeyToIndexTypeN(), KeyToIndexTypeE(), KeyToDenseN(), KeyToDenseE(),
2136  IntDefaultsN(), IntDefaultsE(), StrDefaultsN(), StrDefaultsE(),
2137  FltDefaultsN(), FltDefaultsE(), VecOfIntVecsN(), VecOfIntVecsE(),
2138  VecOfStrVecsN(), VecOfStrVecsE(), VecOfFltVecsN(), VecOfFltVecsE(), VecOfIntVecVecsN(), VecOfIntVecVecsE(),
2139  VecOfFltVecVecsN(), VecOfFltVecVecsE(),
2140  VecOfIntHashVecsN(), VecOfIntHashVecsE(),
2141  VecOfFltHashVecsN(), VecOfFltHashVecsE(),
2142  SAttrN(), SAttrE()
2143  { Reserve(Nodes, Edges); }
2144  TNEANet(const TNEANet& Graph) : MxNId(Graph.MxNId), MxEId(Graph.MxEId),
2145  NodeH(Graph.NodeH), EdgeH(Graph.EdgeH), KeyToIndexTypeN(), KeyToIndexTypeE(), KeyToDenseN(), KeyToDenseE(),
2146  IntDefaultsN(), IntDefaultsE(), StrDefaultsN(), StrDefaultsE(),
2147  FltDefaultsN(), FltDefaultsE(), VecOfIntVecsN(), VecOfIntVecsE(),
2148  VecOfStrVecsN(), VecOfStrVecsE(), VecOfFltVecsN(), VecOfFltVecsE(), VecOfIntVecVecsN(), VecOfIntVecVecsE(),
2149  VecOfFltVecVecsN(), VecOfFltVecVecsE(),
2150  VecOfIntHashVecsN(), VecOfIntHashVecsE(),
2151  VecOfFltHashVecsN(), VecOfFltHashVecsE(),
2152  SAttrN(), SAttrE() { }
2154  TNEANet(TSIn& SIn) : MxNId(SIn), MxEId(SIn), NodeH(SIn), EdgeH(SIn),
2155  KeyToIndexTypeN(SIn), KeyToIndexTypeE(SIn), KeyToDenseN(SIn), KeyToDenseE(SIn), IntDefaultsN(SIn), IntDefaultsE(SIn),
2156  StrDefaultsN(SIn), StrDefaultsE(SIn), FltDefaultsN(SIn), FltDefaultsE(SIn),
2157  VecOfIntVecsN(SIn), VecOfIntVecsE(SIn), VecOfStrVecsN(SIn),VecOfStrVecsE(SIn),
2158  VecOfFltVecsN(SIn), VecOfFltVecsE(SIn), VecOfIntVecVecsN(SIn), VecOfIntVecVecsE(SIn),
2159  VecOfFltVecVecsN(SIn), VecOfFltVecVecsE(SIn),
2160  VecOfIntHashVecsN(SIn), VecOfIntHashVecsE(SIn),
2161  VecOfFltHashVecsN(SIn), VecOfFltHashVecsE(SIn),
2162  SAttrN(SIn), SAttrE(SIn) { }
2163 protected:
2164  TNEANet(const TNEANet& Graph, bool modeSubGraph) : MxNId(Graph.MxNId), MxEId(Graph.MxEId),
2165  NodeH(Graph.NodeH), EdgeH(Graph.EdgeH), KeyToIndexTypeN(), KeyToIndexTypeE(Graph.KeyToIndexTypeE), KeyToDenseN(), KeyToDenseE(Graph.KeyToDenseE),
2166  IntDefaultsN(Graph.IntDefaultsN), IntDefaultsE(Graph.IntDefaultsE), StrDefaultsN(Graph.StrDefaultsN), StrDefaultsE(Graph.StrDefaultsE),
2167  FltDefaultsN(Graph.FltDefaultsN), FltDefaultsE(Graph.FltDefaultsE), VecOfIntVecsN(Graph.VecOfIntVecsN), VecOfIntVecsE(Graph.VecOfIntVecsE),
2168  VecOfStrVecsN(Graph.VecOfStrVecsN), VecOfStrVecsE(Graph.VecOfStrVecsE), VecOfFltVecsN(Graph.VecOfFltVecsN), VecOfFltVecsE(Graph.VecOfFltVecsE),
2169  VecOfIntVecVecsN(), VecOfIntVecVecsE(Graph.VecOfIntVecVecsE),
2170  VecOfFltVecVecsN(), VecOfFltVecVecsE(Graph.VecOfFltVecVecsE),
2171  VecOfIntHashVecsN(), VecOfIntHashVecsE(Graph.VecOfIntHashVecsE),
2172  VecOfFltHashVecsN(), VecOfFltHashVecsE(Graph.VecOfFltHashVecsE)
2173  { }
2174  TNEANet(bool copyAll, const TNEANet& Graph) : MxNId(Graph.MxNId), MxEId(Graph.MxEId),
2175  NodeH(Graph.NodeH), EdgeH(Graph.EdgeH), KeyToIndexTypeN(Graph.KeyToIndexTypeN), KeyToIndexTypeE(Graph.KeyToIndexTypeE), KeyToDenseN(Graph.KeyToDenseN), KeyToDenseE(Graph.KeyToDenseE),
2176  IntDefaultsN(Graph.IntDefaultsN), IntDefaultsE(Graph.IntDefaultsE), StrDefaultsN(Graph.StrDefaultsN), StrDefaultsE(Graph.StrDefaultsE),
2177  FltDefaultsN(Graph.FltDefaultsN), FltDefaultsE(Graph.FltDefaultsE), VecOfIntVecsN(Graph.VecOfIntVecsN), VecOfIntVecsE(Graph.VecOfIntVecsE),
2178  VecOfStrVecsN(Graph.VecOfStrVecsN), VecOfStrVecsE(Graph.VecOfStrVecsE), VecOfFltVecsN(Graph.VecOfFltVecsN), VecOfFltVecsE(Graph.VecOfFltVecsE),
2179  VecOfIntVecVecsN(Graph.VecOfIntVecVecsN), VecOfIntVecVecsE(Graph.VecOfIntVecVecsE),
2180  VecOfFltVecVecsN(Graph.VecOfFltVecVecsN), VecOfFltVecVecsE(Graph.VecOfFltVecVecsE),
2181  VecOfIntHashVecsN(Graph.VecOfIntHashVecsN), VecOfIntHashVecsE(Graph.VecOfIntHashVecsE),
2182  VecOfFltHashVecsN(Graph.VecOfFltHashVecsN), VecOfFltHashVecsE(Graph.VecOfFltHashVecsE),
2183  SAttrN(Graph.SAttrN), SAttrE(Graph.SAttrE) { }
2184  // virtual ~TNEANet() { }cd ..
2185 public:
2187  void Save(TSOut& SOut) const {
2188  MxNId.Save(SOut); MxEId.Save(SOut); NodeH.Save(SOut); EdgeH.Save(SOut);
2189  KeyToIndexTypeN.Save(SOut); KeyToIndexTypeE.Save(SOut);
2190  KeyToDenseN.Save(SOut); KeyToDenseE.Save(SOut);
2191  IntDefaultsN.Save(SOut); IntDefaultsE.Save(SOut);
2192  StrDefaultsN.Save(SOut); StrDefaultsE.Save(SOut);
2193  FltDefaultsN.Save(SOut); FltDefaultsE.Save(SOut);
2194  VecOfIntVecsN.Save(SOut); VecOfIntVecsE.Save(SOut);
2195  VecOfStrVecsN.Save(SOut); VecOfStrVecsE.Save(SOut);
2196  VecOfFltVecsN.Save(SOut); VecOfFltVecsE.Save(SOut);
2197  VecOfIntVecVecsN.Save(SOut); VecOfIntVecVecsE.Save(SOut);
2198  VecOfFltVecVecsN.Save(SOut); VecOfFltVecVecsE.Save(SOut);
2199  VecOfIntHashVecsN.Save(SOut); VecOfIntHashVecsE.Save(SOut);
2200  VecOfFltHashVecsN.Save(SOut); VecOfFltHashVecsE.Save(SOut);
2201  SAttrN.Save(SOut); SAttrE.Save(SOut); }
2203  void Save_V1(TSOut& SOut) const {
2204  MxNId.Save(SOut); MxEId.Save(SOut); NodeH.Save(SOut); EdgeH.Save(SOut);
2205  KeyToIndexTypeN.Save(SOut); KeyToIndexTypeE.Save(SOut);
2206  IntDefaultsN.Save(SOut); IntDefaultsE.Save(SOut);
2207  StrDefaultsN.Save(SOut); StrDefaultsE.Save(SOut);
2208  FltDefaultsN.Save(SOut); FltDefaultsE.Save(SOut);
2209  VecOfIntVecsN.Save(SOut); VecOfIntVecsE.Save(SOut);
2210  VecOfStrVecsN.Save(SOut); VecOfStrVecsE.Save(SOut);
2211  VecOfFltVecsN.Save(SOut); VecOfFltVecsE.Save(SOut); }
2213  void Save_V2(TSOut& SOut) const {
2214  MxNId.Save(SOut); MxEId.Save(SOut); NodeH.Save(SOut); EdgeH.Save(SOut);
2215  KeyToIndexTypeN.Save(SOut); KeyToIndexTypeE.Save(SOut);
2216  IntDefaultsN.Save(SOut); IntDefaultsE.Save(SOut);
2217  StrDefaultsN.Save(SOut); StrDefaultsE.Save(SOut);
2218  FltDefaultsN.Save(SOut); FltDefaultsE.Save(SOut);
2219  VecOfIntVecsN.Save(SOut); VecOfIntVecsE.Save(SOut);
2220  VecOfStrVecsN.Save(SOut); VecOfStrVecsE.Save(SOut);
2221  VecOfFltVecsN.Save(SOut); VecOfFltVecsE.Save(SOut);
2222  VecOfIntVecVecsN.Save(SOut); VecOfIntVecVecsE.Save(SOut);
2223  VecOfFltVecVecsN.Save(SOut); VecOfFltVecVecsE.Save(SOut);
2224  SAttrN.Save(SOut); SAttrE.Save(SOut); }
2226  static PNEANet New() { return PNEANet(new TNEANet()); }
2228 
2230  static PNEANet New(const int& Nodes, const int& Edges) { return PNEANet(new TNEANet(Nodes, Edges)); }
2232  static PNEANet Load(TSIn& SIn) { return PNEANet(new TNEANet(SIn)); }
2234  static PNEANet Load_V1(TSIn& SIn) {
2235  PNEANet Graph = PNEANet(new TNEANet());
2236  Graph->MxNId.Load(SIn); Graph->MxEId.Load(SIn);
2237  Graph->NodeH.Load(SIn); Graph->EdgeH.Load(SIn);
2238  Graph->KeyToIndexTypeN.Load(SIn); Graph->KeyToIndexTypeE.Load(SIn);
2239  Graph->IntDefaultsN.Load(SIn); Graph->IntDefaultsE.Load(SIn);
2240  Graph->StrDefaultsN.Load(SIn); Graph->StrDefaultsE.Load(SIn);
2241  Graph->FltDefaultsN.Load(SIn); Graph->FltDefaultsE.Load(SIn);
2242  Graph->VecOfIntVecsN.Load(SIn); Graph->VecOfIntVecsE.Load(SIn);
2243  Graph->VecOfStrVecsN.Load(SIn); Graph->VecOfStrVecsE.Load(SIn);
2244  Graph->VecOfFltVecsN.Load(SIn); Graph->VecOfFltVecsE.Load(SIn);
2245  return Graph;
2246  }
2247 
2249  static PNEANet Load_V2(TSIn& SIn) {
2250  PNEANet Graph = PNEANet(new TNEANet());
2251  Graph->MxNId.Load(SIn); Graph->MxEId.Load(SIn);
2252  Graph->NodeH.Load(SIn); Graph->EdgeH.Load(SIn);
2253  Graph->KeyToIndexTypeN.Load(SIn); Graph->KeyToIndexTypeE.Load(SIn);
2254  Graph->IntDefaultsN.Load(SIn); Graph->IntDefaultsE.Load(SIn);
2255  Graph->StrDefaultsN.Load(SIn); Graph->StrDefaultsE.Load(SIn);
2256  Graph->FltDefaultsN.Load(SIn); Graph->FltDefaultsE.Load(SIn);
2257  Graph->VecOfIntVecsN.Load(SIn); Graph->VecOfIntVecsE.Load(SIn);
2258  Graph->VecOfStrVecsN.Load(SIn); Graph->VecOfStrVecsE.Load(SIn);
2259  Graph->VecOfFltVecsN.Load(SIn); Graph->VecOfFltVecsE.Load(SIn);
2260  Graph->VecOfIntVecVecsN.Load(SIn); Graph->VecOfIntVecVecsE.Load(SIn);
2261  Graph->VecOfFltVecVecsN.Load(SIn); Graph->VecOfFltVecVecsE.Load(SIn);
2262  Graph->SAttrN.Load(SIn); Graph->SAttrE.Load(SIn);
2263  return Graph;
2264  }
2265 
2267  void LoadNetworkShM(TShMIn& ShMIn);
2269 
2273  static PNEANet LoadShM(TShMIn& ShMIn) {
2274  TNEANet* Network = new TNEANet();
2275  Network->LoadNetworkShM(ShMIn);
2276  return PNEANet(Network);
2277  }
2278 
2280  TInt VecLength = VecOfIntVecVecsN.Len();
2282  if (VecLength != 0) {
2283  VecOfIntHashVecsN = TVec<THash<TInt, TIntV> >(VecLength);
2284  for (iter = KeyToIndexTypeN.BegI(); !iter.IsEnd(); iter=iter.Next()) {
2285  if (iter.GetDat().Val1 == IntVType) {
2286  TStr attribute = iter.GetKey();
2287  TInt index = iter.GetDat().Val2();
2288  for (int i=0; i<VecOfIntVecVecsN[index].Len(); i++) {
2289  if(VecOfIntVecVecsN[index][i].Len() > 0) {
2290  VecOfIntHashVecsN[index].AddDat(TInt(i), VecOfIntVecVecsN[index][i]);
2291  }
2292  }
2293  KeyToDenseN.AddDat(attribute, TBool(false));
2294  }
2295  }
2296  }
2297  VecOfIntVecVecsN.Clr();
2298 
2299  VecLength = VecOfIntVecVecsE.Len();
2300  if (VecLength != 0) {
2301  VecOfIntHashVecsE = TVec<THash<TInt, TIntV> >(VecLength);
2302  for (iter = KeyToIndexTypeE.BegI(); !iter.IsEnd(); iter=iter.Next()) {
2303  if (iter.GetDat().Val1 == IntVType) {
2304  TStr attribute = iter.GetKey();
2305  TInt index = iter.GetDat().Val2();
2306  for (int i=0; i<VecOfIntVecVecsE[index].Len(); i++) {
2307  if(VecOfIntVecVecsE[index][i].Len() > 0) {
2308  VecOfIntHashVecsE[index].AddDat(TInt(i), VecOfIntVecVecsE[index][i]);
2309  }
2310  }
2311  KeyToDenseE.AddDat(attribute, TBool(false));
2312  }
2313  }
2314  }
2315  VecOfIntVecVecsE.Clr();
2316 
2317  VecLength = VecOfFltVecVecsN.Len();
2318  if (VecLength != 0) {
2319  VecOfFltHashVecsN = TVec<THash<TInt, TFltV> >(VecLength);
2320  for (iter = KeyToIndexTypeN.BegI(); !iter.IsEnd(); iter=iter.Next()) {
2321  if (iter.GetDat().Val1 == FltVType) {
2322  TStr attribute = iter.GetKey();
2323  TInt index = iter.GetDat().Val2();
2324  for (int i=0; i<VecOfFltVecVecsN[index].Len(); i++) {
2325  if(VecOfFltVecVecsN[index][i].Len() > 0) {
2326  VecOfFltHashVecsN[index].AddDat(TInt(i), VecOfFltVecVecsN[index][i]);
2327  }
2328  }
2329  KeyToDenseN.AddDat(attribute, TBool(false));
2330  }
2331  }
2332  }
2333  VecOfFltVecVecsN.Clr();
2334 
2335  VecLength = VecOfFltVecVecsE.Len();
2336  if (VecLength != 0) {
2337  VecOfFltHashVecsE = TVec<THash<TInt, TFltV> >(VecLength);
2338  for (iter = KeyToIndexTypeE.BegI(); !iter.IsEnd(); iter=iter.Next()) {
2339  if (iter.GetDat().Val1 == FltVType) {
2340  TStr attribute = iter.GetKey();
2341  TInt index = iter.GetDat().Val2();
2342  for (int i=0; i<VecOfFltVecVecsE[index].Len(); i++) {
2343  if(VecOfFltVecVecsE[index][i].Len() > 0) {
2344  VecOfFltHashVecsE[index].AddDat(TInt(i), VecOfFltVecVecsE[index][i]);
2345  }
2346  }
2347  KeyToDenseE.AddDat(attribute, TBool(false));
2348  }
2349  }
2350  }
2351  VecOfFltVecVecsE.Clr();
2352  }
2353 
2354 
2356  bool HasFlag(const TGraphFlag& Flag) const;
2357 
2358  TNEANet& operator = (const TNEANet& Graph) { if (this!=&Graph) {
2359  MxNId=Graph.MxNId; MxEId=Graph.MxEId; NodeH=Graph.NodeH; EdgeH=Graph.EdgeH; }
2360  return *this; }
2361 
2363  int GetNodes() const { return NodeH.Len(); }
2365 
2369  int AddNode(int NId = -1);
2371 
2375  int AddNodeUnchecked(int NId = -1);
2377  int AddNode(const TNodeI& NodeI) { return AddNode(NodeI.GetId()); }
2379 
2381  virtual void DelNode(const int& NId);
2383  void DelNode(const TNode& NodeI) { DelNode(NodeI.GetId()); }
2385  bool IsNode(const int& NId) const { return NodeH.IsKey(NId); }
2387  TNodeI BegNI() const { return TNodeI(NodeH.BegI(), this); }
2389  TNodeI EndNI() const { return TNodeI(NodeH.EndI(), this); }
2391  TNodeI GetNI(const int& NId) const { return TNodeI(NodeH.GetI(NId), this); }
2393  TAIntI BegNAIntI(const TStr& attr) const {
2394  return TAIntI(VecOfIntVecsN[KeyToIndexTypeN.GetDat(attr).Val2].BegI(), attr, false, this); }
2396  TAIntI EndNAIntI(const TStr& attr) const {
2397  return TAIntI(VecOfIntVecsN[KeyToIndexTypeN.GetDat(attr).Val2].EndI(), attr, false, this); }
2399  TAIntI GetNAIntI(const TStr& attr, const int& NId) const {
2400  return TAIntI(VecOfIntVecsN[KeyToIndexTypeN.GetDat(attr).Val2].GetI(NodeH.GetKeyId(NId)), attr, false, this); }
2401 
2403  TAIntVI BegNAIntVI(const TStr& attr) const {
2404  TVec<TIntV>::TIter HI = NULL;
2406  TInt location = CheckDenseOrSparseN(attr);
2407  TBool IsDense = true;
2408  if (location != -1) {
2409  TInt index = KeyToIndexTypeN.GetDat(attr).Val2;
2410  if (location == 1) {
2411  HI = VecOfIntVecVecsN[index].BegI();
2412  } else {
2413  IsDense = false;
2414  HHI = VecOfIntHashVecsN[index].BegI();
2415  }
2416  }
2417  return TAIntVI(HI, HHI, attr, false, this, IsDense);
2418  }
2420  TAIntVI EndNAIntVI(const TStr& attr) const {
2421  TVec<TIntV>::TIter HI = NULL;
2423  TInt location = CheckDenseOrSparseN(attr);
2424  TBool IsDense = true;
2425  if (location != -1) {
2426  TInt index = KeyToIndexTypeN.GetDat(attr).Val2;
2427  if (location == 1) {
2428  HI = VecOfIntVecVecsN[index].EndI();
2429  } else {
2430  IsDense = false;
2431  HHI = VecOfIntHashVecsN[index].EndI();
2432  }
2433  }
2434  return TAIntVI(HI, HHI, attr, false, this, IsDense);
2435  }
2436 
2437 
2439  TAIntVI GetNAIntVI(const TStr& attr, const int& NId) const {
2440  TVec<TIntV>::TIter HI = NULL;
2442  TInt location = CheckDenseOrSparseN(attr);
2443  TBool IsDense = true;
2444  if (location != -1) {
2445  TInt index = KeyToIndexTypeN.GetDat(attr).Val2;
2446  if (location == 1) {
2447  HI = VecOfIntVecVecsN[index].GetI(NodeH.GetKeyId(NId));
2448  } else {
2449  IsDense = false;
2450  HHI = VecOfIntHashVecsN[index].GetI(NodeH.GetKeyId(NId));
2451  }
2452  }
2453  return TAIntVI(HI, HHI, attr, false, this, IsDense);
2454  }
2455 
2457  TAFltVI BegNAFltVI(const TStr& attr) const {
2458  TVec<TFltV>::TIter HI = NULL;
2460  TInt location = CheckDenseOrSparseN(attr);
2461  TBool IsDense = true;
2462  if (location != -1) {
2463  TInt index = KeyToIndexTypeN.GetDat(attr).Val2;
2464  if (location == 1) {
2465  HI = VecOfFltVecVecsN[index].BegI();
2466  } else {
2467  IsDense = false;
2468  HHI = VecOfFltHashVecsN[index].BegI();
2469  }
2470  }
2471  return TAFltVI(HI, HHI, attr, false, this, IsDense);
2472  }
2474  TAFltVI EndNAFltVI(const TStr& attr) const {
2475  TVec<TFltV>::TIter HI = NULL;
2477  TInt location = CheckDenseOrSparseN(attr);
2478  TBool IsDense = true;
2479  if (location != -1) {
2480  TInt index = KeyToIndexTypeN.GetDat(attr).Val2;
2481  if (location == 1) {
2482  HI = VecOfFltVecVecsN[index].EndI();
2483  } else {
2484  IsDense = false;
2485  HHI = VecOfFltHashVecsN[index].EndI();
2486  }
2487  }
2488  return TAFltVI(HI, HHI, attr, false, this, IsDense);
2489  }
2490 
2491 
2493  TAFltVI GetNAFltVI(const TStr& attr, const int& NId) const {
2494  TVec<TFltV>::TIter HI = NULL;
2496  TInt location = CheckDenseOrSparseN(attr);
2497  TBool IsDense = true;
2498  if (location != -1) {
2499  TInt index = KeyToIndexTypeN.GetDat(attr).Val2;
2500  if (location == 1) {
2501  HI = VecOfFltVecVecsN[index].GetI(NodeH.GetKeyId(NId));
2502  } else {
2503  IsDense = false;
2504  HHI = VecOfFltHashVecsN[index].GetI(NodeH.GetKeyId(NId));
2505  }
2506  }
2507  return TAFltVI(HI, HHI, attr, false, this, IsDense);
2508  }
2509 
2511  TAStrI BegNAStrI(const TStr& attr) const {
2512 
2513  return TAStrI(VecOfStrVecsN[KeyToIndexTypeN.GetDat(attr).Val2].BegI(), attr, false, this); }
2515  TAStrI EndNAStrI(const TStr& attr) const {
2516  return TAStrI(VecOfStrVecsN[KeyToIndexTypeN.GetDat(attr).Val2].EndI(), attr, false, this); }
2518  TAStrI GetNAStrI(const TStr& attr, const int& NId) const {
2519  return TAStrI(VecOfStrVecsN[KeyToIndexTypeN.GetDat(attr).Val2].GetI(NodeH.GetKeyId(NId)), attr, false, this); }
2521  TAFltI BegNAFltI(const TStr& attr) const {
2522  return TAFltI(VecOfFltVecsN[KeyToIndexTypeN.GetDat(attr).Val2].BegI(), attr, false, this); }
2524  TAFltI EndNAFltI(const TStr& attr) const {
2525  return TAFltI(VecOfFltVecsN[KeyToIndexTypeN.GetDat(attr).Val2].EndI(), attr, false, this); }
2527  TAFltI GetNAFltI(const TStr& attr, const int& NId) const {
2528  return TAFltI(VecOfFltVecsN[KeyToIndexTypeN.GetDat(attr).Val2].GetI(NodeH.GetKeyId(NId)), attr, false, this); }
2529 
2531  void AttrNameNI(const TInt& NId, TStrV& Names) const {
2532  AttrNameNI(NId, KeyToIndexTypeN.BegI(), Names);}
2533  void AttrNameNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TStrV& Names) const;
2535  void AttrValueNI(const TInt& NId, TStrV& Values) const {
2536  AttrValueNI(NId, KeyToIndexTypeN.BegI(), Values);}
2537  void AttrValueNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TStrV& Values) const;
2538 
2540  void IntAttrNameNI(const TInt& NId, TStrV& Names) const {
2541  IntAttrNameNI(NId, KeyToIndexTypeN.BegI(), Names);}
2542  void IntAttrNameNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TStrV& Names) const;
2544  void IntAttrValueNI(const TInt& NId, TIntV& Values) const {
2545  IntAttrValueNI(NId, KeyToIndexTypeN.BegI(), Values);}
2546  void IntAttrValueNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TIntV& Values) const;
2547 
2548 
2550  void IntVAttrNameNI(const TInt& NId, TStrV& Names) const {
2551  IntVAttrNameNI(NId, KeyToIndexTypeN.BegI(), Names);}
2552  void IntVAttrNameNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TStrV& Names) const;
2554  void IntVAttrValueNI(const TInt& NId, TVec<TIntV>& Values) const {
2555  IntVAttrValueNI(NId, KeyToIndexTypeN.BegI(), Values);}
2556  void IntVAttrValueNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TVec<TIntV>& Values) const;
2557 
2559  void FltVAttrNameNI(const TInt& NId, TStrV& Names) const {
2560  FltVAttrNameNI(NId, KeyToIndexTypeN.BegI(), Names);}
2561  void FltVAttrNameNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TStrV& Names) const;
2563  void FltVAttrValueNI(const TInt& NId, TVec<TFltV>& Values) const {
2564  FltVAttrValueNI(NId, KeyToIndexTypeN.BegI(), Values);}
2565  void FltVAttrValueNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TVec<TFltV>& Values) const;
2566 
2567 
2569  void StrAttrNameNI(const TInt& NId, TStrV& Names) const {
2570  StrAttrNameNI(NId, KeyToIndexTypeN.BegI(), Names);}
2571  void StrAttrNameNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TStrV& Names) const;
2573  void StrAttrValueNI(const TInt& NId, TStrV& Values) const {
2574  StrAttrValueNI(NId, KeyToIndexTypeN.BegI(), Values);}
2575  void StrAttrValueNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TStrV& Values) const;
2577  void FltAttrNameNI(const TInt& NId, TStrV& Names) const {
2578  FltAttrNameNI(NId, KeyToIndexTypeN.BegI(), Names);}
2579  void FltAttrNameNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TStrV& Names) const;
2581  void FltAttrValueNI(const TInt& NId, TFltV& Values) const {
2582  FltAttrValueNI(NId, KeyToIndexTypeN.BegI(), Values);}
2583  void FltAttrValueNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TFltV& Values) const;
2584 
2586  void AttrNameEI(const TInt& EId, TStrV& Names) const {
2587  AttrNameEI(EId, KeyToIndexTypeE.BegI(), Names);}
2588  void AttrNameEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TStrV& Names) const;
2590  void AttrValueEI(const TInt& EId, TStrV& Values) const {
2591  AttrValueEI(EId, KeyToIndexTypeE.BegI(), Values);}
2592  void AttrValueEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TStrV& Values) const;
2594  void IntAttrNameEI(const TInt& EId, TStrV& Names) const {
2595  IntAttrNameEI(EId, KeyToIndexTypeE.BegI(), Names);}
2596  void IntAttrNameEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TStrV& Names) const;
2598  void IntAttrValueEI(const TInt& EId, TIntV& Values) const {
2599  IntAttrValueEI(EId, KeyToIndexTypeE.BegI(), Values);}
2600  void IntAttrValueEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TIntV& Values) const;
2601 
2602 
2604  void IntVAttrNameEI(const TInt& EId, TStrV& Names) const {
2605  IntVAttrNameEI(EId, KeyToIndexTypeE.BegI(), Names);}
2606  void IntVAttrNameEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TStrV& Names) const;
2608  void IntVAttrValueEI(const TInt& EId, TVec<TIntV>& Values) const {
2609  IntVAttrValueEI(EId, KeyToIndexTypeE.BegI(), Values);}
2610  void IntVAttrValueEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TVec<TIntV>& Values) const;
2611 
2613  void FltVAttrNameEI(const TInt& EId, TStrV& Names) const {
2614  FltVAttrNameEI(EId, KeyToIndexTypeE.BegI(), Names);}
2615  void FltVAttrNameEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TStrV& Names) const;
2617  void FltVAttrValueEI(const TInt& EId, TVec<TFltV>& Values) const {
2618  FltVAttrValueEI(EId, KeyToIndexTypeE.BegI(), Values);}
2619  void FltVAttrValueEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TVec<TFltV>& Values) const;
2620 
2621 
2623  void StrAttrNameEI(const TInt& EId, TStrV& Names) const {
2624  StrAttrNameEI(EId, KeyToIndexTypeE.BegI(), Names);}
2625  void StrAttrNameEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TStrV& Names) const;
2627  void StrAttrValueEI(const TInt& EId, TStrV& Values) const {
2628  StrAttrValueEI(EId, KeyToIndexTypeE.BegI(), Values);}
2629  void StrAttrValueEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TStrV& Values) const;
2631  void FltAttrNameEI(const TInt& EId, TStrV& Names) const {
2632  FltAttrNameEI(EId, KeyToIndexTypeE.BegI(), Names);}
2633  void FltAttrNameEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TStrV& Names) const;
2635  void FltAttrValueEI(const TInt& EId, TFltV& Values) const {
2636  FltAttrValueEI(EId, KeyToIndexTypeE.BegI(), Values);}
2637  void FltAttrValueEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TFltV& Values) const;
2638 
2640  TAIntI BegEAIntI(const TStr& attr) const {
2641  return TAIntI(VecOfIntVecsE[KeyToIndexTypeE.GetDat(attr).Val2].BegI(), attr, true, this);
2642  }
2644  TAIntI EndEAIntI(const TStr& attr) const {
2645  return TAIntI(VecOfIntVecsE[KeyToIndexTypeE.GetDat(attr).Val2].EndI(), attr, true, this);
2646  }
2648  TAIntI GetEAIntI(const TStr& attr, const int& EId) const {
2649  return TAIntI(VecOfIntVecsE[KeyToIndexTypeE.GetDat(attr).Val2].GetI(EdgeH.GetKeyId(EId)), attr, true, this);
2650  }
2651 
2653  TAIntVI BegEAIntVI(const TStr& attr) const {
2654  TVec<TIntV>::TIter HI = NULL;
2656  TInt location = CheckDenseOrSparseE(attr);
2657  TBool IsDense = true;
2658  if (location != -1) {
2659  TInt index = KeyToIndexTypeE.GetDat(attr).Val2;
2660  if (location == 1) {
2661  HI = VecOfIntVecVecsE[index].BegI();
2662  } else {
2663  IsDense = false;
2664  HHI = VecOfIntHashVecsE[index].BegI();
2665  }
2666  }
2667  return TAIntVI(HI, HHI, attr, true, this, IsDense);
2668  }
2670  TAIntVI EndEAIntVI(const TStr& attr) const {
2671  TVec<TIntV>::TIter HI = NULL;
2673  TInt location = CheckDenseOrSparseE(attr);
2674  TBool IsDense = true;
2675  if (location != -1) {
2676  TInt index = KeyToIndexTypeE.GetDat(attr).Val2;
2677  if (location == 1) {
2678  HI = VecOfIntVecVecsE[index].EndI();
2679  } else {
2680  IsDense = false;
2681  HHI = VecOfIntHashVecsE[index].EndI();
2682  }
2683  }
2684  return TAIntVI(HI, HHI, attr, true, this, IsDense);
2685  }
2687  TAIntVI GetEAIntVI(const TStr& attr, const int& EId) const {
2688  TVec<TIntV>::TIter HI = NULL;
2690  TInt location = CheckDenseOrSparseE(attr);
2691  TBool IsDense = true;
2692  if (location != -1) {
2693  TInt index = KeyToIndexTypeE.GetDat(attr).Val2;
2694  if (location == 1) {
2695  HI = VecOfIntVecVecsE[index].GetI(EdgeH.GetKeyId(EId));
2696  } else {
2697  IsDense = false;
2698  HHI = VecOfIntHashVecsE[index].GetI(EdgeH.GetKeyId(EId));
2699  }
2700  }
2701  return TAIntVI(HI, HHI, attr, true, this, IsDense);
2702  }
2703 
2705  TAFltVI BegEAFltVI(const TStr& attr) const {
2706  TVec<TFltV>::TIter HI = NULL;
2708  TInt location = CheckDenseOrSparseE(attr);
2709  TBool IsDense = true;
2710  if (location != -1) {
2711  TInt index = KeyToIndexTypeE.GetDat(attr).Val2;
2712  if (location == 1) {
2713  HI = VecOfFltVecVecsE[index].BegI();
2714  } else {
2715  IsDense = false;
2716  HHI = VecOfFltHashVecsE[index].BegI();
2717  }
2718  }
2719  return TAFltVI(HI, HHI, attr, true, this, IsDense);
2720  }
2722  TAFltVI EndEAFltVI(const TStr& attr) const {
2723  TVec<TFltV>::TIter HI = NULL;
2725  TInt location = CheckDenseOrSparseE(attr);
2726  TBool IsDense = true;
2727  if (location != -1) {
2728  TInt index = KeyToIndexTypeE.GetDat(attr).Val2;
2729  if (location == 1) {
2730  HI = VecOfFltVecVecsE[index].EndI();
2731  } else {
2732  IsDense = false;
2733  HHI = VecOfFltHashVecsE[index].EndI();
2734  }
2735  }
2736  return TAFltVI(HI, HHI, attr, true, this, IsDense);
2737  }
2739  TAFltVI GetEAFltVI(const TStr& attr, const int& EId) const {
2740  TVec<TFltV>::TIter HI = NULL;
2742  TInt location = CheckDenseOrSparseE(attr);
2743  TBool IsDense = true;
2744  if (location != -1) {
2745  TInt index = KeyToIndexTypeE.GetDat(attr).Val2;
2746  if (location == 1) {
2747  HI = VecOfFltVecVecsE[index].GetI(EdgeH.GetKeyId(EId));
2748  } else {
2749  IsDense = false;
2750  HHI = VecOfFltHashVecsE[index].GetI(EdgeH.GetKeyId(EId));
2751  }
2752  }
2753  return TAFltVI(HI, HHI, attr, true, this, IsDense);
2754  }
2755 
2757  TAStrI BegEAStrI(const TStr& attr) const {
2758  return TAStrI(VecOfStrVecsE[KeyToIndexTypeE.GetDat(attr).Val2].BegI(), attr, true, this); }
2760  TAStrI EndEAStrI(const TStr& attr) const {
2761  return TAStrI(VecOfStrVecsE[KeyToIndexTypeE.GetDat(attr).Val2].EndI(), attr, true, this);
2762  }
2764  TAStrI GetEAStrI(const TStr& attr, const int& EId) const {
2765  return TAStrI(VecOfStrVecsE[KeyToIndexTypeE.GetDat(attr).Val2].GetI(EdgeH.GetKeyId(EId)), attr, true, this);
2766  }
2768  TAFltI BegEAFltI(const TStr& attr) const {
2769  return TAFltI(VecOfFltVecsE[KeyToIndexTypeE.GetDat(attr).Val2].BegI(), attr, true, this);
2770  }
2772  TAFltI EndEAFltI(const TStr& attr) const {
2773  return TAFltI(VecOfFltVecsE[KeyToIndexTypeE.GetDat(attr).Val2].EndI(), attr, true, this);
2774  }
2776  TAFltI GetEAFltI(const TStr& attr, const int& EId) const {
2777  return TAFltI(VecOfFltVecsE[KeyToIndexTypeE.GetDat(attr).Val2].GetI(EdgeH.GetKeyId(EId)), attr, true, this);
2778  }
2780  int GetMxNId() const { return MxNId; }
2782  int GetMxEId() const { return MxEId; }
2783 
2785  int GetEdges() const { return EdgeH.Len(); }
2787 
2792  int AddEdge(const int& SrcNId, const int& DstNId, int EId = -1);
2794  int AddEdge(const TEdgeI& EdgeI) { return AddEdge(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), EdgeI.GetId()); }
2796  void DelEdge(const int& EId);
2798 
2802  void DelEdge(const int& SrcNId, const int& DstNId, const bool& IsDir = true);
2804  bool IsEdge(const int& EId) const { return EdgeH.IsKey(EId); }
2806  bool IsEdge(const int& SrcNId, const int& DstNId, const bool& IsDir = true) const { int EId; return IsEdge(SrcNId, DstNId, EId, IsDir); }
2808  bool IsEdge(const int& SrcNId, const int& DstNId, int& EId, const bool& IsDir = true) const;
2810  int GetEId(const int& SrcNId, const int& DstNId) const { int EId; return IsEdge(SrcNId, DstNId, EId)?EId:-1; }
2812  TEdgeI BegEI() const { return TEdgeI(EdgeH.BegI(), this); }
2814  TEdgeI EndEI() const { return TEdgeI(EdgeH.EndI(), this); }
2816  TEdgeI GetEI(const int& EId) const { return TEdgeI(EdgeH.GetI(EId), this); }
2818  TEdgeI GetEI(const int& SrcNId, const int& DstNId) const { return GetEI(GetEId(SrcNId, DstNId)); }
2819 
2821  int GetRndNId(TRnd& Rnd=TInt::Rnd) { return NodeH.GetKey(NodeH.GetRndKeyId(Rnd, 0.8)); }
2823  TNodeI GetRndNI(TRnd& Rnd=TInt::Rnd) { return GetNI(GetRndNId(Rnd)); }
2825  int GetRndEId(TRnd& Rnd=TInt::Rnd) { return EdgeH.GetKey(EdgeH.GetRndKeyId(Rnd, 0.8)); }
2827  TEdgeI GetRndEI(TRnd& Rnd=TInt::Rnd) { return GetEI(GetRndEId(Rnd)); }
2829  void GetNIdV(TIntV& NIdV) const;
2831  void GetEIdV(TIntV& EIdV) const;
2832 
2834  bool Empty() const { return GetNodes()==0; }
2836  void Clr() { MxNId=0; MxEId=0; NodeH.Clr(); EdgeH.Clr();
2837  KeyToIndexTypeN.Clr(); KeyToIndexTypeE.Clr(); IntDefaultsN.Clr(); IntDefaultsE.Clr();
2838  StrDefaultsN.Clr(); StrDefaultsE.Clr(); FltDefaultsN.Clr(); FltDefaultsE.Clr();
2839  VecOfIntVecsN.Clr(); VecOfIntVecsE.Clr(); VecOfStrVecsN.Clr(); VecOfStrVecsE.Clr();
2840  VecOfFltVecsN.Clr(); VecOfFltVecsE.Clr(); VecOfIntVecVecsN.Clr(); VecOfIntVecVecsE.Clr();
2841  VecOfFltVecVecsN.Clr(); VecOfFltVecVecsE.Clr();
2842  SAttrN.Clr(); SAttrE.Clr();}
2844  void Reserve(const int& Nodes, const int& Edges) {
2845  if (Nodes>0) { NodeH.Gen(Nodes/2); } if (Edges>0) { EdgeH.Gen(Edges/2); } }
2847 
2852  void Defrag(const bool& OnlyNodeLinks=false);
2854 
2857  bool IsOk(const bool& ThrowExcept=true) const;
2859  void Dump(FILE *OutF=stdout) const;
2860 
2862  int AddIntAttrDatN(const TNodeI& NodeI, const TInt& value, const TStr& attr) { return AddIntAttrDatN(NodeI.GetId(), value, attr); }
2863  int AddIntAttrDatN(const int& NId, const TInt& value, const TStr& attr);
2865  int AddStrAttrDatN(const TNodeI& NodeI, const TStr& value, const TStr& attr) { return AddStrAttrDatN(NodeI.GetId(), value, attr); }
2866  int AddStrAttrDatN(const int& NId, const TStr& value, const TStr& attr);
2868  int AddFltAttrDatN(const TNodeI& NodeI, const TFlt& value, const TStr& attr) { return AddFltAttrDatN(NodeI.GetId(), value, attr); }
2869  int AddFltAttrDatN(const int& NId, const TFlt& value, const TStr& attr);
2871  int AddIntVAttrDatN(const TNodeI& NodeI, const TIntV& value, const TStr& attr) { return AddIntVAttrDatN(NodeI.GetId(), value, attr); }
2872  int AddIntVAttrDatN(const int& NId, const TIntV& value, const TStr& attr, TBool UseDense=true);
2874  int AddFltVAttrDatN(const TNodeI& NodeI, const TFltV& value, const TStr& attr) { return AddFltVAttrDatN(NodeI.GetId(), value, attr); }
2875  int AddFltVAttrDatN(const int& NId, const TFltV& value, const TStr& attr, TBool UseDense=true);
2876 
2877 
2878 
2880  int AppendIntVAttrDatN(const TNodeI& NodeI, const TInt& value, const TStr& attr) { return AppendIntVAttrDatN(NodeI.GetId(), value, attr); }
2881  int AppendIntVAttrDatN(const int& NId, const TInt& value, const TStr& attr, TBool UseDense=true);
2883  int DelFromIntVAttrDatN(const TNodeI& NodeI, const TInt& value, const TStr& attr) { return DelFromIntVAttrDatN(NodeI.GetId(), value, attr); }
2884  int DelFromIntVAttrDatN(const int& NId, const TInt& value, const TStr& attr);
2885 
2887  int AppendFltVAttrDatN(const TNodeI& NodeI, const TFlt& value, const TStr& attr) { return AppendFltVAttrDatN(NodeI.GetId(), value, attr); }
2888  int AppendFltVAttrDatN(const int& NId, const TFlt& value, const TStr& attr, TBool UseDense=true);
2890  int DelFromFltVAttrDatN(const TNodeI& NodeI, const TFlt& value, const TStr& attr) { return DelFromFltVAttrDatN(NodeI.GetId(), value, attr); }
2891  int DelFromFltVAttrDatN(const int& NId, const TFlt& value, const TStr& attr);
2892 
2893 
2894 
2896 
2898  int AddIntAttrDatE(const TEdgeI& EdgeI, const TInt& value, const TStr& attr) { return AddIntAttrDatE(EdgeI.GetId(), value, attr); }
2899  int AddIntAttrDatE(const int& EId, const TInt& value, const TStr& attr);
2901 
2903  int AddStrAttrDatE(const TEdgeI& EdgeI, const TStr& value, const TStr& attr) { return AddStrAttrDatE(EdgeI.GetId(), value, attr); }
2904  int AddStrAttrDatE(const int& EId, const TStr& value, const TStr& attr);
2906 
2908  int AddFltAttrDatE(const TEdgeI& EdgeI, const TFlt& value, const TStr& attr) { return AddFltAttrDatE(EdgeI.GetId(), value, attr); }
2909  int AddFltAttrDatE(const int& EId, const TFlt& value, const TStr& attr);
2910 
2911 
2913 
2915  int AddIntVAttrDatE(const TEdgeI& EdgeI, const TIntV& value, const TStr& attr) { return AddIntVAttrDatE(EdgeI.GetId(), value, attr); }
2916  int AddIntVAttrDatE(const int& EId, const TIntV& value, const TStr& attr, TBool UseDense=true);
2918  int AppendIntVAttrDatE(const TEdgeI& EdgeI, const TInt& value, const TStr& attr) { return AppendIntVAttrDatE(EdgeI.GetId(), value, attr); }
2919  int AppendIntVAttrDatE(const int& EId, const TInt& value, const TStr& attr, TBool UseDense=true);
2920 
2922 
2924  int AddFltVAttrDatE(const TEdgeI& EdgeI, const TFltV& value, const TStr& attr) { return AddFltVAttrDatE(EdgeI.GetId(), value, attr); }
2925  int AddFltVAttrDatE(const int& EId, const TFltV& value, const TStr& attr, TBool UseDense=true);
2927  int AppendFltVAttrDatE(const TEdgeI& EdgeI, const TFlt& value, const TStr& attr) { return AppendFltVAttrDatE(EdgeI.GetId(), value, attr); }
2928  int AppendFltVAttrDatE(const int& EId, const TFlt& value, const TStr& attr, TBool UseDense=true);
2929 
2931  TInt GetIntAttrDatN(const TNodeI& NodeI, const TStr& attr) { return GetIntAttrDatN(NodeI.GetId(), attr); }
2932  TInt GetIntAttrDatN(const int& NId, const TStr& attr);
2933 
2935  TStr GetStrAttrDatN(const TNodeI& NodeI, const TStr& attr) { return GetStrAttrDatN(NodeI.GetId(), attr); }
2936  TStr GetStrAttrDatN(const int& NId, const TStr& attr);
2938  TFlt GetFltAttrDatN(const TNodeI& NodeI, const TStr& attr) { return GetFltAttrDatN(NodeI.GetId(), attr); }
2939  TFlt GetFltAttrDatN(const int& NId, const TStr& attr);
2941  TIntV GetIntVAttrDatN(const TNodeI& NodeI, const TStr& attr) const { return GetIntVAttrDatN(NodeI.GetId(), attr); }
2942  TIntV GetIntVAttrDatN(const int& NId, const TStr& attr) const;
2943 
2945  TFltV GetFltVAttrDatN(const TNodeI& NodeI, const TStr& attr) const { return GetFltVAttrDatN(NodeI.GetId(), attr); }
2946  TFltV GetFltVAttrDatN(const int& NId, const TStr& attr) const;
2947 
2949  int GetIntAttrIndN(const TStr& attr);
2951  int GetAttrIndN(const TStr& attr);
2952 
2954  TInt GetIntAttrIndDatN(const TNodeI& NodeI, const int& index) { return GetIntAttrIndDatN(NodeI.GetId(), index); }
2956  TInt GetIntAttrIndDatN(const int& NId, const int& index);
2957 
2959  TStr GetStrAttrIndDatN(const TNodeI& NodeI, const int& index) { return GetStrAttrIndDatN(NodeI.GetId(), index); }
2961  TStr GetStrAttrIndDatN(const int& NId, const int& index);
2962 
2964  TFlt GetFltAttrIndDatN(const TNodeI& NodeI, const int& index) { return GetFltAttrIndDatN(NodeI.GetId(), index); }
2966  TFlt GetFltAttrIndDatN(const int& NId, const int& index);
2967 
2969  TInt GetIntAttrDatE(const TEdgeI& EdgeI, const TStr& attr) { return GetIntAttrDatE(EdgeI.GetId(), attr); }
2970  TInt GetIntAttrDatE(const int& EId, const TStr& attr);
2972  TStr GetStrAttrDatE(const TEdgeI& EdgeI, const TStr& attr) { return GetStrAttrDatE(EdgeI.GetId(), attr); }
2973  TStr GetStrAttrDatE(const int& EId, const TStr& attr);
2975  TFlt GetFltAttrDatE(const TEdgeI& EdgeI, const TStr& attr) { return GetFltAttrDatE(EdgeI.GetId(), attr); }
2976  TFlt GetFltAttrDatE(const int& EId, const TStr& attr);
2978  TIntV GetIntVAttrDatE(const TEdgeI& EdgeI, const TStr& attr) { return GetIntVAttrDatE(EdgeI.GetId(), attr); }
2979  TIntV GetIntVAttrDatE(const int& EId, const TStr& attr);
2980 
2982  TFltV GetFltVAttrDatE(const TEdgeI& EdgeI, const TStr& attr) { return GetFltVAttrDatE(EdgeI.GetId(), attr); }
2983  TFltV GetFltVAttrDatE(const int& EId, const TStr& attr);
2984 
2986  int GetIntAttrIndE(const TStr& attr);
2988  int GetAttrIndE(const TStr& attr);
2989 
2991  TInt GetIntAttrIndDatE(const TEdgeI& EdgeI, const int& index) { return GetIntAttrIndDatE(EdgeI.GetId(), index); }
2993  TInt GetIntAttrIndDatE(const int& EId, const int& index);
2994 
2996  TFlt GetFltAttrIndDatE(const TEdgeI& EdgeI, const int& index) { return GetFltAttrIndDatE(EdgeI.GetId(), index); }
2998  TFlt GetFltAttrIndDatE(const int& EId, const int& index);
2999 
3001  TStr GetStrAttrIndDatE(const TEdgeI& EdgeI, const int& index) { return GetStrAttrIndDatE(EdgeI.GetId(), index); }
3003  TStr GetStrAttrIndDatE(const int& EId, const int& index);
3004 
3006  int DelAttrDatN(const TNodeI& NodeI, const TStr& attr) { return DelAttrDatN(NodeI.GetId(), attr); }
3007  int DelAttrDatN(const int& NId, const TStr& attr);
3009  int DelAttrDatE(const TEdgeI& EdgeI, const TStr& attr) { return DelAttrDatE(EdgeI.GetId(), attr); }
3010  int DelAttrDatE(const int& EId, const TStr& attr);
3011 
3013  int AddIntAttrN(const TStr& attr, TInt defaultValue=TInt::Mn);
3015  int AddStrAttrN(const TStr& attr, TStr defaultValue=TStr::GetNullStr());
3017  int AddFltAttrN(const TStr& attr, TFlt defaultValue=TFlt::Mn);
3019  int AddIntVAttrN(const TStr& attr, TBool UseDense=true);
3020 
3022  int AddFltVAttrN(const TStr& attr, TBool UseDense=true);
3023 
3025  int AddIntAttrE(const TStr& attr, TInt defaultValue=TInt::Mn);
3027  int AddStrAttrE(const TStr& attr, TStr defaultValue=TStr::GetNullStr());
3029  int AddFltAttrE(const TStr& attr, TFlt defaultValue=TFlt::Mn);
3031  int AddIntVAttrE(const TStr& attr, TBool UseDense=true);
3032 
3034  int AddFltVAttrE(const TStr& attr, TBool UseDense=true);
3035 
3037  int DelAttrN(const TStr& attr);
3039  int DelAttrE(const TStr& attr);
3040 
3042  bool IsAttrDeletedN(const int& NId, const TStr& attr) const;
3044  bool IsIntAttrDeletedN(const int& NId, const TStr& attr) const;
3046  bool IsIntVAttrDeletedN(const int& NId, const TStr& attr) const;
3048  bool IsFltVAttrDeletedN(const int& NId, const TStr& attr) const;
3050  bool IsStrAttrDeletedN(const int& NId, const TStr& attr) const;
3052  bool IsFltAttrDeletedN(const int& NId, const TStr& attr) const;
3053 
3055  bool NodeAttrIsDeleted(const int& NId, const TStrIntPrH::TIter& NodeHI) const;
3057  bool NodeAttrIsIntDeleted(const int& NId, const TStrIntPrH::TIter& NodeHI) const;
3059  bool NodeAttrIsIntVDeleted(const int& NId, const TStrIntPrH::TIter& NodeHI) const;
3061  bool NodeAttrIsFltVDeleted(const int& NId, const TStrIntPrH::TIter& NodeHI) const;
3063  bool NodeAttrIsStrDeleted(const int& NId, const TStrIntPrH::TIter& NodeHI) const;
3065  bool NodeAttrIsFltDeleted(const int& NId, const TStrIntPrH::TIter& NodeHI) const;
3066 
3068  bool IsAttrDeletedE(const int& EId, const TStr& attr) const;
3070  bool IsIntAttrDeletedE(const int& EId, const TStr& attr) const;
3072  bool IsIntVAttrDeletedE(const int& EId, const TStr& attr) const;
3074  bool IsFltVAttrDeletedE(const int& EId, const TStr& attr) const;
3076  bool IsStrAttrDeletedE(const int& EId, const TStr& attr) const;
3078  bool IsFltAttrDeletedE(const int& EId, const TStr& attr) const;
3079 
3081  bool EdgeAttrIsDeleted(const int& EId, const TStrIntPrH::TIter& EdgeHI) const;
3083  bool EdgeAttrIsIntDeleted(const int& EId, const TStrIntPrH::TIter& EdgeHI) const;
3085  bool EdgeAttrIsIntVDeleted(const int& EId, const TStrIntPrH::TIter& EdgeHI) const;
3087  bool EdgeAttrIsFltVDeleted(const int& EId, const TStrIntPrH::TIter& EdgeHI) const;
3089  bool EdgeAttrIsStrDeleted(const int& EId, const TStrIntPrH::TIter& EdgeHI) const;
3091  bool EdgeAttrIsFltDeleted(const int& EId, const TStrIntPrH::TIter& EdgeHI) const;
3092 
3094  TStr GetNodeAttrValue(const int& NId, const TStrIntPrH::TIter& NodeHI) const;
3096  TStr GetEdgeAttrValue(const int& EId, const TStrIntPrH::TIter& EdgeHI) const;
3097 
3099  TFlt GetWeightOutEdges(const TNodeI& NI, const TStr& attr);
3101  bool IsFltAttrE(const TStr& attr);
3103  bool IsIntAttrE(const TStr& attr);
3105  bool IsStrAttrE(const TStr& attr);
3107  TVec<TFlt>& GetFltAttrVecE(const TStr& attr);
3109  int GetFltKeyIdE(const int& EId);
3110 
3112  void GetWeightOutEdgesV(TFltV& OutWeights, const TFltV& AttrVal) ;
3114  void GetAttrNNames(TStrV& IntAttrNames, TStrV& FltAttrNames, TStrV& StrAttrNames) const;
3116  void GetAttrENames(TStrV& IntAttrNames, TStrV& FltAttrNames, TStrV& StrAttrNames) const;
3117 
3118 
3120  int AddSAttrDatN(const TInt& NId, const TStr& AttrName, const TInt& Val);
3122  int AddSAttrDatN(const TInt& NId, const TInt& AttrId, const TInt& Val);
3123 
3125  int AddSAttrDatN(const TNodeI& NodeI, const TStr& AttrName, const TInt& Val) {
3126  return AddSAttrDatN(NodeI.GetId(), AttrName, Val);
3127  }
3129  int AddSAttrDatN(const TNodeI& NodeI, const TInt& AttrId, const TInt& Val) {
3130  return AddSAttrDatN(NodeI.GetId(), AttrId, Val);
3131  }
3132 
3134  int AddSAttrDatN(const TInt& NId, const TStr& AttrName, const TFlt& Val);
3136  int AddSAttrDatN(const TInt& NId, const TInt& AttrId, const TFlt& Val);
3137 
3139  int AddSAttrDatN(const TNodeI& NodeI, const TStr& AttrName, const TFlt& Val) {
3140  return AddSAttrDatN(NodeI.GetId(), AttrName, Val);
3141  }
3143  int AddSAttrDatN(const TNodeI& NodeI, const TInt& AttrId, const TFlt& Val) {
3144  return AddSAttrDatN(NodeI.GetId(), AttrId, Val);
3145  }
3146 
3148  int AddSAttrDatN(const TInt& NId, const TStr& AttrName, const TStr& Val);
3150  int AddSAttrDatN(const TInt& NId, const TInt& AttrId, const TStr& Val);
3151 
3153  int AddSAttrDatN(const TNodeI& NodeI, const TStr& AttrName, const TStr& Val) {
3154  return AddSAttrDatN(NodeI.GetId(), AttrName, Val);
3155  }
3157  int AddSAttrDatN(const TNodeI& NodeI, const TInt& AttrId, const TStr& Val) {
3158  return AddSAttrDatN(NodeI.GetId(), AttrId, Val);
3159  }
3160 
3162  int GetSAttrDatN(const TInt& NId, const TStr& AttrName, TInt& ValX) const;
3164  int GetSAttrDatN(const TInt& NId, const TInt& AttrId, TInt& ValX) const;
3165 
3167  int GetSAttrDatN(const TNodeI& NodeI, const TStr& AttrName, TInt& ValX) const {
3168  return GetSAttrDatN(NodeI.GetId(), AttrName, ValX);
3169  }
3171  int GetSAttrDatN(const TNodeI& NodeI, const TInt& AttrId, TInt& ValX) const {
3172  return GetSAttrDatN(NodeI.GetId(), AttrId, ValX);
3173  }
3174 
3176  int GetSAttrDatN(const TInt& NId, const TStr& AttrName, TFlt& ValX) const;
3178  int GetSAttrDatN(const TInt& NId, const TInt& AttrId, TFlt& ValX) const;
3179 
3181  int GetSAttrDatN(const TNodeI& NodeI, const TStr& AttrName, TFlt& ValX) const {
3182  return GetSAttrDatN(NodeI.GetId(), AttrName, ValX);
3183  }
3185  int GetSAttrDatN(const TNodeI& NodeI, const TInt& AttrId, TFlt& ValX) const {
3186  return GetSAttrDatN(NodeI.GetId(), AttrId, ValX);
3187  }
3188 
3190  int GetSAttrDatN(const TInt& NId, const TStr& AttrName, TStr& ValX) const;
3192  int GetSAttrDatN(const TInt& NId, const TInt& AttrId, TStr& ValX) const;
3193 
3195  int GetSAttrDatN(const TNodeI& NodeI, const TStr& AttrName, TStr& ValX) const {
3196  return GetSAttrDatN(NodeI.GetId(), AttrName, ValX);
3197  }
3199  int GetSAttrDatN(const TNodeI& NodeI, const TInt& AttrId, TStr& ValX) const {
3200  return GetSAttrDatN(NodeI.GetId(), AttrId, ValX);
3201  }
3202 
3204  int DelSAttrDatN(const TInt& NId, const TStr& AttrName);
3206  int DelSAttrDatN(const TInt& NId, const TInt& AttrId);
3207 
3209  int DelSAttrDatN(const TNodeI& NodeI, const TStr& AttrName) {
3210  return DelSAttrDatN(NodeI.GetId(), AttrName);
3211  }
3213  int DelSAttrDatN(const TNodeI& NodeI, const TInt& AttrId) {
3214  return DelSAttrDatN(NodeI.GetId(), AttrId);
3215  }
3216 
3218  int GetSAttrVN(const TInt& NId, const TAttrType AttrType, TAttrPrV& AttrV) const;
3220  int GetSAttrVN(const TNodeI& NodeI, const TAttrType AttrType, TAttrPrV& AttrV) const {
3221  return GetSAttrVN(NodeI.GetId(), AttrType, AttrV);
3222  }
3223 
3225  int GetIdVSAttrN(const TStr& AttrName, TIntV& IdV) const;
3227  int GetIdVSAttrN(const TInt& AttrId, TIntV& IdV) const;
3228 
3230  int AddSAttrN(const TStr& Name, const TAttrType& AttrType, TInt& AttrId);
3231 
3233  int GetSAttrIdN(const TStr& Name, TInt& AttrIdX, TAttrType& AttrTypeX) const;
3235  int GetSAttrNameN(const TInt& AttrId, TStr& NameX, TAttrType& AttrTypeX) const;
3236 
3238  int AddSAttrDatE(const TInt& EId, const TStr& AttrName, const TInt& Val);
3240  int AddSAttrDatE(const TInt& EId, const TInt& AttrId, const TInt& Val);
3241 
3243  int AddSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName, const TInt& Val) {
3244  return AddSAttrDatE(EdgeI.GetId(), AttrName, Val);
3245  }
3247  int AddSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId, const TInt& Val) {
3248  return AddSAttrDatE(EdgeI.GetId(), AttrId, Val);
3249  }
3250 
3252  int AddSAttrDatE(const TInt& EId, const TStr& AttrName, const TFlt& Val);
3254  int AddSAttrDatE(const TInt& EId, const TInt& AttrId, const TFlt& Val);
3255 
3257  int AddSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName, const TFlt& Val) {
3258  return AddSAttrDatE(EdgeI.GetId(), AttrName, Val);
3259  }
3261  int AddSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId, const TFlt& Val){
3262  return AddSAttrDatE(EdgeI.GetId(), AttrId, Val);
3263  }
3264 
3266  int AddSAttrDatE(const TInt& EId, const TStr& AttrName, const TStr& Val);
3268  int AddSAttrDatE(const TInt& EId, const TInt& AttrId, const TStr& Val);
3269 
3271  int AddSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName, const TStr& Val) {
3272  return AddSAttrDatE(EdgeI.GetId(), AttrName, Val);
3273  }
3275  int AddSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId, const TStr& Val) {
3276  return AddSAttrDatE(EdgeI.GetId(), AttrId, Val);
3277  }
3278 
3280  int GetSAttrDatE(const TInt& EId, const TStr& AttrName, TInt& ValX) const;
3282  int GetSAttrDatE(const TInt& EId, const TInt& AttrId, TInt& ValX) const;
3283 
3285  int GetSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName, TInt& ValX) const {
3286  return GetSAttrDatE(EdgeI.GetId(), AttrName, ValX);
3287  }
3289  int GetSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId, TInt& ValX) const {
3290  return GetSAttrDatE(EdgeI.GetId(), AttrId, ValX);
3291  }
3292 
3294  int GetSAttrDatE(const TInt& EId, const TStr& AttrName, TFlt& ValX) const;
3296  int GetSAttrDatE(const TInt& EId, const TInt& AttrId, TFlt& ValX) const;
3297 
3299  int GetSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName, TFlt& ValX) const {
3300  return GetSAttrDatE(EdgeI.GetId(), AttrName, ValX);
3301  }
3303  int GetSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId, TFlt& ValX) const {
3304  return GetSAttrDatE(EdgeI.GetId(), AttrId, ValX);
3305  }
3306 
3308  int GetSAttrDatE(const TInt& EId, const TStr& AttrName, TStr& ValX) const;
3310  int GetSAttrDatE(const TInt& EId, const TInt& AttrId, TStr& ValX) const;
3311 
3313  int GetSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName, TStr& ValX) const {
3314  return GetSAttrDatE(EdgeI.GetId(), AttrName, ValX);
3315  }
3317  int GetSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId, TStr& ValX) const {
3318  return GetSAttrDatE(EdgeI.GetId(), AttrId, ValX);
3319  }
3320 
3322  int DelSAttrDatE(const TInt& EId, const TStr& AttrName);
3324  int DelSAttrDatE(const TInt& EId, const TInt& AttrId);
3325 
3327  int DelSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName) {
3328  return DelSAttrDatE(EdgeI.GetId(), AttrName);
3329  }
3331  int DelSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId) {
3332  return DelSAttrDatE(EdgeI.GetId(), AttrId);
3333  }
3335  int GetSAttrVE(const TInt& EId, const TAttrType AttrType, TAttrPrV& AttrV) const;
3337  int GetSAttrVE(const TEdgeI& EdgeI, const TAttrType AttrType, TAttrPrV& AttrV) const {
3338  return GetSAttrVE(EdgeI.GetId(), AttrType, AttrV);
3339  }
3340 
3342  int GetIdVSAttrE(const TStr& AttrName, TIntV& IdV) const;
3344  int GetIdVSAttrE(const TInt& AttrId, TIntV& IdV) const;
3345 
3347  int AddSAttrE(const TStr& Name, const TAttrType& AttrType, TInt& AttrId);
3348 
3350  int GetSAttrIdE(const TStr& Name, TInt& AttrIdX, TAttrType& AttrTypeX) const;
3352  int GetSAttrNameE(const TInt& AttrId, TStr& NameX, TAttrType& AttrTypeX) const;
3353 
3355 
3359  static PNEANet GetSmallGraph();
3360  friend class TPt<TNEANet>;
3361 };
3362 
3363 // set flags
3364 namespace TSnap {
3365 template <> struct IsMultiGraph<TNEANet> { enum { Val = 1 }; };
3366 template <> struct IsDirected<TNEANet> { enum { Val = 1 }; };
3367 }
3368 
3369  //#//////////////////////////////////////////////
3371 
3373 
3375 typedef TPt<TUndirNet> PUndirNet;
3376 
3377 //#//////////////////////////////////////////////
3379 class TDirNet;
3380 
3382 typedef TPt<TDirNet> PDirNet;
3383 
3384 //#//////////////////////////////////////////////
3386 
3397 class TUndirNet {
3398 public:
3399  typedef TUndirNet TNet;
3401 public:
3402  class TNode {
3403  private:
3406  public:
3407  TNode() : Id(-1), NIdV() { }
3408  TNode(const int& NId) : Id(NId), NIdV() { }
3409  TNode(const TNode& Node) : Id(Node.Id), NIdV(Node.NIdV) { }
3410  TNode(TSIn& SIn) : Id(SIn), NIdV(SIn) { }
3411  void Save(TSOut& SOut) const { Id.Save(SOut); NIdV.Save(SOut); }
3412  int GetId() const { return Id; }
3413  int GetDeg() const { return NIdV.Len(); }
3414  int GetInDeg() const { return GetDeg(); }
3415  int GetOutDeg() const { return GetDeg(); }
3416  int GetInNId(const int& NodeN) const { return GetNbrNId(NodeN); }
3417  int GetOutNId(const int& NodeN) const { return GetNbrNId(NodeN); }
3418  int GetNbrNId(const int& NodeN) const { return NIdV[NodeN]; }
3419  bool IsNbrNId(const int& NId) const { return NIdV.SearchBin(NId)!=-1; }
3420  bool IsInNId(const int& NId) const { return IsNbrNId(NId); }
3421  bool IsOutNId(const int& NId) const { return IsNbrNId(NId); }
3422  void PackOutNIdV() { NIdV.Pack(); }
3423  void PackNIdV() { NIdV.Pack(); }
3424  void SortNIdV() { NIdV.Sort();}
3425  void LoadShM(TShMIn& MStream) {
3426  Id = TInt(MStream);
3427  NIdV.LoadShM(MStream);
3428  }
3429  friend class TUndirNet;
3430  friend class TUndirNetMtx;
3431  };
3433  class TNodeI {
3434  private:
3436  THashIter NodeHI;
3437  public:
3438  TNodeI() : NodeHI() { }
3439  TNodeI(const THashIter& NodeHIter) : NodeHI(NodeHIter) { }
3440  TNodeI(const TNodeI& NodeI) : NodeHI(NodeI.NodeHI) { }
3441  TNodeI& operator = (const TNodeI& NodeI) { NodeHI = NodeI.NodeHI; return *this; }
3442 
3444  TNodeI& operator++ (int) { NodeHI++; return *this; }
3446  TNodeI& operator-- (int) { NodeHI--; return *this; }
3447 
3448 
3449  bool operator < (const TNodeI& NodeI) const { return NodeHI < NodeI.NodeHI; }
3450  bool operator == (const TNodeI& NodeI) const { return NodeHI == NodeI.NodeHI; }
3451 
3453  int GetId() const { return NodeHI.GetDat().GetId(); }
3455  int GetDeg() const { return NodeHI.GetDat().GetDeg(); }
3457  int GetInDeg() const { return NodeHI.GetDat().GetInDeg(); }
3459  int GetOutDeg() const { return NodeHI.GetDat().GetOutDeg(); }
3461  void SortNIdV() { NodeHI.GetDat().SortNIdV(); }
3463 
3466  int GetInNId(const int& NodeN) const { return NodeHI.GetDat().GetInNId(NodeN); }
3468 
3471  int GetOutNId(const int& NodeN) const { return NodeHI.GetDat().GetOutNId(NodeN); }
3473 
3476  int GetNbrNId(const int& NodeN) const { return NodeHI.GetDat().GetNbrNId(NodeN); }
3478  bool IsInNId(const int& NId) const { return NodeHI.GetDat().IsInNId(NId); }
3480  bool IsOutNId(const int& NId) const { return NodeHI.GetDat().IsOutNId(NId); }
3482  bool IsNbrNId(const int& NId) const { return NodeHI.GetDat().IsNbrNId(NId); }
3483  friend class TUndirNet;
3484  };
3486  class TEdgeI {
3487  private:
3488  TNodeI CurNode, EndNode;
3489  int CurEdge;
3490  public:
3491  TEdgeI() : CurNode(), EndNode(), CurEdge(0) { }
3492  TEdgeI(const TNodeI& NodeI, const TNodeI& EndNodeI, const int& EdgeN=0) : CurNode(NodeI), EndNode(EndNodeI), CurEdge(EdgeN) { }
3493  TEdgeI(const TEdgeI& EdgeI) : CurNode(EdgeI.CurNode), EndNode(EdgeI.EndNode), CurEdge(EdgeI.CurEdge) { }
3494  TEdgeI& operator = (const TEdgeI& EdgeI) { if (this!=&EdgeI) { CurNode=EdgeI.CurNode; EndNode=EdgeI.EndNode; CurEdge=EdgeI.CurEdge; } return *this; }
3496  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; }
3497  bool operator < (const TEdgeI& EdgeI) const { return CurNode<EdgeI.CurNode || (CurNode==EdgeI.CurNode && CurEdge<EdgeI.CurEdge); }
3498  bool operator == (const TEdgeI& EdgeI) const { return CurNode == EdgeI.CurNode && CurEdge == EdgeI.CurEdge; }
3500  int GetId() const { return -1; }
3502  int GetSrcNId() const { return CurNode.GetId(); }
3504  int GetDstNId() const { return CurNode.GetOutNId(CurEdge); }
3505  friend class TUndirNet;
3506  };
3507 private:
3511 
3514 private:
3515  TNode& GetNode(const int& NId) { return NodeH.GetDat(NId); }
3516  const TNode& GetNode(const int& NId) const { return NodeH.GetDat(NId); }
3517  TIntPr OrderEdgeNodes(const int& SrcNId, const int& DstNId) const;
3518 private:
3520  public:
3522  void operator() (TNode* n, TShMIn& ShMIn) {n->LoadShM(ShMIn);}
3523  };
3524 private:
3525  void LoadNetworkShM(TShMIn& ShMIn) {
3526  MxNId = TInt(ShMIn);
3527  NEdges = TInt(ShMIn);
3528  LoadTNodeFunctor NodeFn;
3529  NodeH.LoadShM(ShMIn, NodeFn);
3530  SAttrN.Load(ShMIn);
3531  SAttrE = TAttrPair(ShMIn);
3532  }
3533 public:
3534  TUndirNet() : CRef(), MxNId(0), NEdges(0), NodeH(), SAttrN(), SAttrE() { }
3536  explicit TUndirNet(const int& Nodes, const int& Edges) : MxNId(0), NEdges(0), SAttrN(), SAttrE() { Reserve(Nodes, Edges); }
3537  TUndirNet(const TUndirNet& Graph) : MxNId(Graph.MxNId), NEdges(Graph.NEdges), NodeH(Graph.NodeH),
3538  SAttrN(), SAttrE() { }
3540  TUndirNet(TSIn& SIn) : MxNId(SIn), NEdges(SIn), NodeH(SIn), SAttrN(SIn), SAttrE(SIn) { }
3542  void Save(TSOut& SOut) const { MxNId.Save(SOut); NEdges.Save(SOut); NodeH.Save(SOut);
3543  SAttrN.Save(SOut); SAttrE.Save(SOut); }
3545  void Save_V1(TSOut& SOut) const { MxNId.Save(SOut); NEdges.Save(SOut); NodeH.Save(SOut); }
3547  static PUndirNet New() { return new TUndirNet(); }
3549 
3551  static PUndirNet New(const int& Nodes, const int& Edges) { return new TUndirNet(Nodes, Edges); }
3553  static PUndirNet Load(TSIn& SIn) { return PUndirNet(new TUndirNet(SIn)); }
3555  static PUndirNet Load_V1(TSIn& SIn) { PUndirNet Graph = PUndirNet(new TUndirNet());
3556  Graph->MxNId.Load(SIn); Graph->NEdges.Load(SIn); Graph->NodeH.Load(SIn); return Graph;
3557  }
3558 
3560 
3564  static PUndirNet LoadShM(TShMIn& ShMIn) {
3565  TUndirNet* Network = new TUndirNet();
3566  Network->LoadNetworkShM(ShMIn);
3567  return PUndirNet(Network);
3568  }
3569 
3571  bool HasFlag(const TGraphFlag& Flag) const;
3573  if (this!=&Graph) { MxNId=Graph.MxNId; NEdges=Graph.NEdges; NodeH=Graph.NodeH; } return *this; }
3574 
3576  int GetNodes() const { return NodeH.Len(); }
3578 
3582  int AddNode(int NId = -1);
3584 
3588  int AddNodeUnchecked(int NId = -1);
3590  int AddNode(const TNodeI& NodeI) { return AddNode(NodeI.GetId()); }
3592 
3601  int AddNode(const int& NId, const TIntV& NbrNIdV);
3603 
3612  int AddNode(const int& NId, const TVecPool<TInt>& Pool, const int& NIdVId);
3614 
3616  void DelNode(const int& NId);
3618  void DelNode(const TNode& NodeI) { DelNode(NodeI.GetId()); }
3620  bool IsNode(const int& NId) const { return NodeH.IsKey(NId); }
3622  TNodeI BegNI() const { return TNodeI(NodeH.BegI()); }
3624  TNodeI EndNI() const { return TNodeI(NodeH.EndI()); }
3626  TNodeI GetNI(const int& NId) const { return TNodeI(NodeH.GetI(NId)); }
3628  int GetMxNId() const { return MxNId; }
3629 
3631  int GetEdges() const;
3633 
3639  int AddEdge(const int& SrcNId, const int& DstNId);
3641 
3648  int AddEdgeUnchecked(const int& SrcNId, const int& DstNId);
3650  int AddEdge(const TEdgeI& EdgeI) { return AddEdge(EdgeI.GetSrcNId(), EdgeI.GetDstNId()); }
3652 
3656  void DelEdge(const int& SrcNId, const int& DstNId);
3658  bool IsEdge(const int& SrcNId, const int& DstNId) const;
3660  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; }
3662  TEdgeI EndEI() const { return TEdgeI(EndNI(), EndNI()); }
3664  TEdgeI GetEI(const int& EId) const;
3666 
3669  TEdgeI GetEI(const int& SrcNId, const int& DstNId) const;
3670 
3672  int GetRndNId(TRnd& Rnd=TInt::Rnd) { return NodeH.GetKey(NodeH.GetRndKeyId(Rnd, 0.8)); }
3674  TNodeI GetRndNI(TRnd& Rnd=TInt::Rnd) { return GetNI(GetRndNId(Rnd)); }
3676  void GetNIdV(TIntV& NIdV) const;
3677 
3679  bool Empty() const { return GetNodes()==0; }
3681  void Clr() { MxNId=0; NEdges=0; NodeH.Clr(); SAttrN.Clr(); SAttrE.Clr(); }
3683  void Reserve(const int& Nodes, const int& Edges) { if (Nodes>0) NodeH.Gen(Nodes/2); }
3685  void ReserveNIdDeg(const int& NId, const int& Deg) { GetNode(NId).NIdV.Reserve(Deg); }
3687  void SortNodeAdjV() { for (TNodeI NI = BegNI(); NI < EndNI(); NI++) { NI.SortNIdV();} }
3689 
3694  void Defrag(const bool& OnlyNodeLinks=false);
3696 
3699  bool IsOk(const bool& ThrowExcept=true) const;
3701  void Dump(FILE *OutF=stdout) const;
3703 
3709  static PUndirNet GetSmallGraph();
3710 
3712  int AddSAttrDatN(const TInt& NId, const TStr& AttrName, const TInt& Val);
3714  int AddSAttrDatN(const TInt& NId, const TInt& AttrId, const TInt& Val);
3715 
3717  int AddSAttrDatN(const TNodeI& NodeI, const TStr& AttrName, const TInt& Val) {
3718  return AddSAttrDatN(NodeI.GetId(), AttrName, Val);
3719  }
3721  int AddSAttrDatN(const TNodeI& NodeI, const TInt& AttrId, const TInt& Val) {
3722  return AddSAttrDatN(NodeI.GetId(), AttrId, Val);
3723  }
3724 
3726  int AddSAttrDatN(const TInt& NId, const TStr& AttrName, const TFlt& Val);
3728  int AddSAttrDatN(const TInt& NId, const TInt& AttrId, const TFlt& Val);
3729 
3731  int AddSAttrDatN(const TNodeI& NodeI, const TStr& AttrName, const TFlt& Val) {
3732  return AddSAttrDatN(NodeI.GetId(), AttrName, Val);
3733  }
3735  int AddSAttrDatN(const TNodeI& NodeI, const TInt& AttrId, const TFlt& Val) {
3736  return AddSAttrDatN(NodeI.GetId(), AttrId, Val);
3737  }
3738 
3740  int AddSAttrDatN(const TInt& NId, const TStr& AttrName, const TStr& Val);
3742  int AddSAttrDatN(const TInt& NId, const TInt& AttrId, const TStr& Val);
3743 
3745  int AddSAttrDatN(const TNodeI& NodeI, const TStr& AttrName, const TStr& Val) {
3746  return AddSAttrDatN(NodeI.GetId(), AttrName, Val);
3747  }
3749  int AddSAttrDatN(const TNodeI& NodeI, const TInt& AttrId, const TStr& Val) {
3750  return AddSAttrDatN(NodeI.GetId(), AttrId, Val);
3751  }
3752 
3754  int GetSAttrDatN(const TInt& NId, const TStr& AttrName, TInt& ValX) const;
3756  int GetSAttrDatN(const TInt& NId, const TInt& AttrId, TInt& ValX) const;
3757 
3759  int GetSAttrDatN(const TNodeI& NodeI, const TStr& AttrName, TInt& ValX) const {
3760  return GetSAttrDatN(NodeI.GetId(), AttrName, ValX);
3761  }
3763  int GetSAttrDatN(const TNodeI& NodeI, const TInt& AttrId, TInt& ValX) const {
3764  return GetSAttrDatN(NodeI.GetId(), AttrId, ValX);
3765  }
3766 
3768  int GetSAttrDatN(const TInt& NId, const TStr& AttrName, TFlt& ValX) const;
3770  int GetSAttrDatN(const TInt& NId, const TInt& AttrId, TFlt& ValX) const;
3771 
3773  int GetSAttrDatN(const TNodeI& NodeI, const TStr& AttrName, TFlt& ValX) const {
3774  return GetSAttrDatN(NodeI.GetId(), AttrName, ValX);
3775  }
3777  int GetSAttrDatN(const TNodeI& NodeI, const TInt& AttrId, TFlt& ValX) const {
3778  return GetSAttrDatN(NodeI.GetId(), AttrId, ValX);
3779  }
3780 
3782  int GetSAttrDatN(const TInt& NId, const TStr& AttrName, TStr& ValX) const;
3784  int GetSAttrDatN(const TInt& NId, const TInt& AttrId, TStr& ValX) const;
3785 
3787  int GetSAttrDatN(const TNodeI& NodeI, const TStr& AttrName, TStr& ValX) const {
3788  return GetSAttrDatN(NodeI.GetId(), AttrName, ValX);
3789  }
3791  int GetSAttrDatN(const TNodeI& NodeI, const TInt& AttrId, TStr& ValX) const {
3792  return GetSAttrDatN(NodeI.GetId(), AttrId, ValX);
3793  }
3794 
3796  int DelSAttrDatN(const TInt& NId, const TStr& AttrName);
3798  int DelSAttrDatN(const TInt& NId, const TInt& AttrId);
3799 
3801  int DelSAttrDatN(const TNodeI& NodeI, const TStr& AttrName) {
3802  return DelSAttrDatN(NodeI.GetId(), AttrName);
3803  }
3805  int DelSAttrDatN(const TNodeI& NodeI, const TInt& AttrId) {
3806  return DelSAttrDatN(NodeI.GetId(), AttrId);
3807  }
3808 
3810  int GetSAttrVN(const TInt& NId, const TAttrType AttrType, TAttrPrV& AttrV) const;
3812  int GetSAttrVN(const TNodeI& NodeI, const TAttrType AttrType, TAttrPrV& AttrV) const {
3813  return GetSAttrVN(NodeI.GetId(), AttrType, AttrV);
3814  }
3815 
3817  int GetIdVSAttrN(const TStr& AttrName, TIntV& IdV) const;
3819  int GetIdVSAttrN(const TInt& AttrId, TIntV& IdV) const;
3820 
3822  int AddSAttrN(const TStr& Name, const TAttrType& AttrType, TInt& AttrId);
3823 
3825  int GetSAttrIdN(const TStr& Name, TInt& AttrIdX, TAttrType& AttrTypeX) const;
3827  int GetSAttrNameN(const TInt& AttrId, TStr& NameX, TAttrType& AttrTypeX) const;
3828 
3830  int AddSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName, const TInt& Val);
3832  int AddSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId, const TInt& Val);
3833 
3835  int AddSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName, const TInt& Val) {
3836  return AddSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName, Val);
3837  }
3839  int AddSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId, const TInt& Val) {
3840  return AddSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId, Val);
3841  }
3842 
3844  int AddSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName, const TFlt& Val);
3846  int AddSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId, const TFlt& Val);
3847 
3849  int AddSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName, const TFlt& Val) {
3850  return AddSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName, Val);
3851  }
3853  int AddSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId, const TFlt& Val){
3854  return AddSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId, Val);
3855  }
3856 
3858  int AddSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName, const TStr& Val);
3860  int AddSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId, const TStr& Val);
3861 
3863  int AddSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName, const TStr& Val) {
3864  return AddSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName, Val);
3865  }
3867  int AddSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId, const TStr& Val) {
3868  return AddSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId, Val);
3869  }
3870 
3872  int GetSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName, TInt& ValX) const;
3874  int GetSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId, TInt& ValX) const;
3875 
3877  int GetSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName, TInt& ValX) const {
3878  return GetSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName, ValX);
3879  }
3881  int GetSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId, TInt& ValX) const {
3882  return GetSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId, ValX);
3883  }
3884 
3886  int GetSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName, TFlt& ValX) const;
3888  int GetSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId, TFlt& ValX) const;
3889 
3891  int GetSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName, TFlt& ValX) const {
3892  return GetSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName, ValX);
3893  }
3895  int GetSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId, TFlt& ValX) const {
3896  return GetSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId, ValX);
3897  }
3898 
3900  int GetSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName, TStr& ValX) const;
3902  int GetSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId, TStr& ValX) const;
3903 
3905  int GetSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName, TStr& ValX) const {
3906  return GetSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName, ValX);
3907  }
3909  int GetSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId, TStr& ValX) const {
3910  return GetSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId, ValX);
3911  }
3912 
3914  int DelSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName);
3916  int DelSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId);
3917 
3919  int DelSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName) {
3920  return DelSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName);
3921  }
3923  int DelSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId) {
3924  return DelSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId);
3925  }
3927  int GetSAttrVE(const int& SrcNId, const int& DstNId, const TAttrType AttrType, TAttrPrV& AttrV) const;
3929  int GetSAttrVE(const TEdgeI& EdgeI, const TAttrType AttrType, TAttrPrV& AttrV) const {
3930  return GetSAttrVE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrType, AttrV);
3931  }
3932 
3934  int GetIdVSAttrE(const TStr& AttrName, TIntPrV& IdV) const;
3936  int GetIdVSAttrE(const TInt& AttrId, TIntPrV& IdV) const;
3937 
3939  int AddSAttrE(const TStr& Name, const TAttrType& AttrType, TInt& AttrId);
3940 
3942  int GetSAttrIdE(const TStr& Name, TInt& AttrIdX, TAttrType& AttrTypeX) const;
3944  int GetSAttrNameE(const TInt& AttrId, TStr& NameX, TAttrType& AttrTypeX) const;
3945 
3946  friend class TUndirNetMtx;
3947  friend class TPt<TUndirNet>;
3948 };
3949 
3950 //#//////////////////////////////////////////////
3952 
3966 class TDirNet {
3967 public:
3968  typedef TDirNet TNet;
3970 public:
3971  class TNode {
3972  private:
3974  TIntV InNIdV, OutNIdV;
3975  public:
3976  TNode() : Id(-1), InNIdV(), OutNIdV() { }
3977  TNode(const int& NId) : Id(NId), InNIdV(), OutNIdV() { }
3978  TNode(const TNode& Node) : Id(Node.Id), InNIdV(Node.InNIdV), OutNIdV(Node.OutNIdV) { }
3979  TNode(TSIn& SIn) : Id(SIn), InNIdV(SIn), OutNIdV(SIn) { }
3980  void Save(TSOut& SOut) const { Id.Save(SOut); InNIdV.Save(SOut); OutNIdV.Save(SOut); }
3981  int GetId() const { return Id; }
3982  int GetDeg() const { return GetInDeg() + GetOutDeg(); }
3983  int GetInDeg() const { return InNIdV.Len(); }
3984  int GetOutDeg() const { return OutNIdV.Len(); }
3985  int GetInNId(const int& NodeN) const { return InNIdV[NodeN]; }
3986  int GetOutNId(const int& NodeN) const { return OutNIdV[NodeN]; }
3987  int GetNbrNId(const int& NodeN) const { return NodeN<GetOutDeg()?GetOutNId(NodeN):GetInNId(NodeN-GetOutDeg()); }
3988  bool IsInNId(const int& NId) const { return InNIdV.SearchBin(NId) != -1; }
3989  bool IsOutNId(const int& NId) const { return OutNIdV.SearchBin(NId) != -1; }
3990  bool IsNbrNId(const int& NId) const { return IsOutNId(NId) || IsInNId(NId); }
3991  void PackOutNIdV() { OutNIdV.Pack(); }
3992  void PackNIdV() { InNIdV.Pack(); }
3993  void SortNIdV() { InNIdV.Sort(); OutNIdV.Sort();}
3994  void LoadShM(TShMIn& MStream) {
3995  Id = TInt(MStream);
3996  InNIdV.LoadShM(MStream);
3997  OutNIdV.LoadShM(MStream);
3998  }
3999  friend class TDirNet;
4000  friend class TDirNetMtx;
4001  };
4003  class TNodeI {
4004  private:
4006  THashIter NodeHI;
4007  public:
4008  TNodeI() : NodeHI() { }
4009  TNodeI(const THashIter& NodeHIter) : NodeHI(NodeHIter) { }
4010  TNodeI(const TNodeI& NodeI) : NodeHI(NodeI.NodeHI) { }
4011  TNodeI& operator = (const TNodeI& NodeI) { NodeHI = NodeI.NodeHI; return *this; }
4013  TNodeI& operator++ (int) { NodeHI++; return *this; }
4015  TNodeI& operator-- (int) { NodeHI--; return *this; }
4016 
4017  bool operator < (const TNodeI& NodeI) const { return NodeHI < NodeI.NodeHI; }
4018  bool operator == (const TNodeI& NodeI) const { return NodeHI == NodeI.NodeHI; }
4020  int GetId() const { return NodeHI.GetDat().GetId(); }
4022  int GetDeg() const { return NodeHI.GetDat().GetDeg(); }
4024  int GetInDeg() const { return NodeHI.GetDat().GetInDeg(); }
4026  int GetOutDeg() const { return NodeHI.GetDat().GetOutDeg(); }
4028  void SortNIdV() { NodeHI.GetDat().SortNIdV(); }
4030 
4032  int GetInNId(const int& NodeN) const { return NodeHI.GetDat().GetInNId(NodeN); }
4034 
4036  int GetOutNId(const int& NodeN) const { return NodeHI.GetDat().GetOutNId(NodeN); }
4038 
4040  int GetNbrNId(const int& NodeN) const { return NodeHI.GetDat().GetNbrNId(NodeN); }
4042  bool IsInNId(const int& NId) const { return NodeHI.GetDat().IsInNId(NId); }
4044  bool IsOutNId(const int& NId) const { return NodeHI.GetDat().IsOutNId(NId); }
4046  bool IsNbrNId(const int& NId) const { return IsOutNId(NId) || IsInNId(NId); }
4047  friend class TDirNet;
4048  };
4050  class TEdgeI {
4051  private:
4052  TNodeI CurNode, EndNode;
4053  int CurEdge;
4054  public:
4055  TEdgeI() : CurNode(), EndNode(), CurEdge(0) { }
4056  TEdgeI(const TNodeI& NodeI, const TNodeI& EndNodeI, const int& EdgeN=0) : CurNode(NodeI), EndNode(EndNodeI), CurEdge(EdgeN) { }
4057  TEdgeI(const TEdgeI& EdgeI) : CurNode(EdgeI.CurNode), EndNode(EdgeI.EndNode), CurEdge(EdgeI.CurEdge) { }
4058  TEdgeI& operator = (const TEdgeI& EdgeI) { if (this!=&EdgeI) { CurNode=EdgeI.CurNode; EndNode=EdgeI.EndNode; CurEdge=EdgeI.CurEdge; } return *this; }
4060  TEdgeI& operator++ (int) { CurEdge++; if (CurEdge >= CurNode.GetOutDeg()) { CurEdge=0; CurNode++;
4061  while (CurNode < EndNode && CurNode.GetOutDeg()==0) { CurNode++; } } return *this; }
4062  bool operator < (const TEdgeI& EdgeI) const { return CurNode<EdgeI.CurNode || (CurNode==EdgeI.CurNode && CurEdge<EdgeI.CurEdge); }
4063  bool operator == (const TEdgeI& EdgeI) const { return CurNode == EdgeI.CurNode && CurEdge == EdgeI.CurEdge; }
4065  int GetId() const { return -1; }
4067  int GetSrcNId() const { return CurNode.GetId(); }
4069  int GetDstNId() const { return CurNode.GetOutNId(CurEdge); }
4070  friend class TDirNet;
4071  };
4072 private:
4078 private:
4079  TNode& GetNode(const int& NId) { return NodeH.GetDat(NId); }
4080  const TNode& GetNode(const int& NId) const { return NodeH.GetDat(NId); }
4081 private:
4083  public:
4085  void operator() (TNode* n, TShMIn& ShMIn) { n->LoadShM(ShMIn);}
4086  };
4087 private:
4088  void LoadNetworkShM(TShMIn& ShMIn) {
4089  MxNId = TInt(ShMIn);
4090  TNodeFunctor f;
4091  NodeH.LoadShM(ShMIn, f);
4092  SAttrN.Load(ShMIn);
4093  SAttrE = TAttrPair(ShMIn);
4094  }
4095 public:
4096  TDirNet() : CRef(), MxNId(0), NodeH(), SAttrN(), SAttrE() { }
4098  explicit TDirNet(const int& Nodes, const int& Edges) : MxNId(0), SAttrN(), SAttrE() { Reserve(Nodes, Edges); }
4099  TDirNet(const TDirNet& Graph) : MxNId(Graph.MxNId), NodeH(Graph.NodeH), SAttrN(), SAttrE() { }
4101  TDirNet(TSIn& SIn) : MxNId(SIn), NodeH(SIn), SAttrN(SIn), SAttrE(SIn) { }
4103  void Save(TSOut& SOut) const { MxNId.Save(SOut); NodeH.Save(SOut); SAttrN.Save(SOut); SAttrE.Save(SOut); }
4105  void Save_V1(TSOut& SOut) const { MxNId.Save(SOut); NodeH.Save(SOut); }
4107  static PDirNet New() { return new TDirNet(); }
4109 
4111  static PDirNet New(const int& Nodes, const int& Edges) { return new TDirNet(Nodes, Edges); }
4113  static PDirNet Load(TSIn& SIn) { return PDirNet(new TDirNet(SIn)); }
4115  static PDirNet Load_V1(TSIn& SIn) { PDirNet Graph = PDirNet(new TDirNet());
4116  Graph->MxNId.Load(SIn); Graph->NodeH.Load(SIn); return Graph;
4117  }
4119 
4123  static PDirNet LoadShM(TShMIn& ShMIn) {
4124  TDirNet* Network = new TDirNet();
4125  Network->LoadNetworkShM(ShMIn);
4126  return PDirNet(Network);
4127  }
4129  bool HasFlag(const TGraphFlag& Flag) const;
4130  TDirNet& operator = (const TDirNet& Graph) {
4131  if (this!=&Graph) { MxNId=Graph.MxNId; NodeH=Graph.NodeH; } return *this; }
4132 
4134  int GetNodes() const { return NodeH.Len(); }
4136 
4140  int AddNode(int NId = -1);
4142 
4146  int AddNodeUnchecked(int NId = -1);
4148  int AddNode(const TNodeI& NodeId) { return AddNode(NodeId.GetId()); }
4150 
4160  int AddNode(const int& NId, const TIntV& InNIdV, const TIntV& OutNIdV);
4162 
4171  int AddNode(const int& NId, const TVecPool<TInt>& Pool, const int& SrcVId, const int& DstVId);
4173 
4175  void DelNode(const int& NId);
4177  void DelNode(const TNode& NodeI) { DelNode(NodeI.GetId()); }
4179  bool IsNode(const int& NId) const { return NodeH.IsKey(NId); }
4181  TNodeI BegNI() const { return TNodeI(NodeH.BegI()); }
4183  TNodeI EndNI() const { return TNodeI(NodeH.EndI()); }
4185  TNodeI GetNI(const int& NId) const { return TNodeI(NodeH.GetI(NId)); }
4186  // GetNodeC() has been commented out. It was a quick shortcut, do not use.
4187  //const TNode& GetNodeC(const int& NId) const { return NodeH.GetDat(NId); }
4189  int GetMxNId() const { return MxNId; }
4190 
4192  int GetEdges() const;
4194 
4200  int AddEdge(const int& SrcNId, const int& DstNId);
4202 
4209  int AddEdgeUnchecked(const int& SrcNId, const int& DstNId);
4210  // Adds an edge from EdgeI.GetSrcNId() to EdgeI.GetDstNId() to the network.
4211  int AddEdge(const TEdgeI& EdgeI) { return AddEdge(EdgeI.GetSrcNId(), EdgeI.GetDstNId()); }
4213 
4217  void DelEdge(const int& SrcNId, const int& DstNId, const bool& IsDir = true);
4219  bool IsEdge(const int& SrcNId, const int& DstNId, const bool& IsDir = true) const;
4221  TEdgeI BegEI() const { TNodeI NI=BegNI(); while(NI<EndNI() && NI.GetOutDeg()==0){NI++;} return TEdgeI(NI, EndNI()); }
4223  TEdgeI EndEI() const { return TEdgeI(EndNI(), EndNI()); }
4225  TEdgeI GetEI(const int& EId) const; // not supported
4227  TEdgeI GetEI(const int& SrcNId, const int& DstNId) const;
4228 
4230  int GetRndNId(TRnd& Rnd=TInt::Rnd) { return NodeH.GetKey(NodeH.GetRndKeyId(Rnd, 0.8)); }
4232  TNodeI GetRndNI(TRnd& Rnd=TInt::Rnd) { return GetNI(GetRndNId(Rnd)); }
4234  void GetNIdV(TIntV& NIdV) const;
4235 
4237  bool Empty() const { return GetNodes()==0; }
4239  void Clr() { MxNId=0; NodeH.Clr(); SAttrN.Clr(); SAttrE.Clr(); }
4241  void Reserve(const int& Nodes, const int& Edges) { if (Nodes>0) { NodeH.Gen(Nodes/2); } }
4243  void ReserveNIdInDeg(const int& NId, const int& InDeg) { GetNode(NId).InNIdV.Reserve(InDeg); }
4245  void ReserveNIdOutDeg(const int& NId, const int& OutDeg) { GetNode(NId).OutNIdV.Reserve(OutDeg); }
4247  void SortNodeAdjV() { for (TNodeI NI = BegNI(); NI < EndNI(); NI++) { NI.SortNIdV();} }
4249 
4254  void Defrag(const bool& OnlyNodeLinks=false);
4256 
4259  bool IsOk(const bool& ThrowExcept=true) const;
4261  void Dump(FILE *OutF=stdout) const;
4263 
4267  static PDirNet GetSmallGraph();
4268 
4270  int AddSAttrDatN(const TInt& NId, const TStr& AttrName, const TInt& Val);
4272  int AddSAttrDatN(const TInt& NId, const TInt& AttrId, const TInt& Val);
4273 
4275  int AddSAttrDatN(const TNodeI& NodeI, const TStr& AttrName, const TInt& Val) {
4276  return AddSAttrDatN(NodeI.GetId(), AttrName, Val);
4277  }
4279  int AddSAttrDatN(const TNodeI& NodeI, const TInt& AttrId, const TInt& Val) {
4280  return AddSAttrDatN(NodeI.GetId(), AttrId, Val);
4281  }
4282 
4284  int AddSAttrDatN(const TInt& NId, const TStr& AttrName, const TFlt& Val);
4286  int AddSAttrDatN(const TInt& NId, const TInt& AttrId, const TFlt& Val);
4287 
4289  int AddSAttrDatN(const TNodeI& NodeI, const TStr& AttrName, const TFlt& Val) {
4290  return AddSAttrDatN(NodeI.GetId(), AttrName, Val);
4291  }
4293  int AddSAttrDatN(const TNodeI& NodeI, const TInt& AttrId, const TFlt& Val) {
4294  return AddSAttrDatN(NodeI.GetId(), AttrId, Val);
4295  }
4296 
4298  int AddSAttrDatN(const TInt& NId, const TStr& AttrName, const TStr& Val);
4300  int AddSAttrDatN(const TInt& NId, const TInt& AttrId, const TStr& Val);
4301 
4303  int AddSAttrDatN(const TNodeI& NodeI, const TStr& AttrName, const TStr& Val) {
4304  return AddSAttrDatN(NodeI.GetId(), AttrName, Val);
4305  }
4307  int AddSAttrDatN(const TNodeI& NodeI, const TInt& AttrId, const TStr& Val) {
4308  return AddSAttrDatN(NodeI.GetId(), AttrId, Val);
4309  }
4310 
4312  int GetSAttrDatN(const TInt& NId, const TStr& AttrName, TInt& ValX) const;
4314  int GetSAttrDatN(const TInt& NId, const TInt& AttrId, TInt& ValX) const;
4315 
4317  int GetSAttrDatN(const TNodeI& NodeI, const TStr& AttrName, TInt& ValX) const {
4318  return GetSAttrDatN(NodeI.GetId(), AttrName, ValX);
4319  }
4321  int GetSAttrDatN(const TNodeI& NodeI, const TInt& AttrId, TInt& ValX) const {
4322  return GetSAttrDatN(NodeI.GetId(), AttrId, ValX);
4323  }
4324 
4326  int GetSAttrDatN(const TInt& NId, const TStr& AttrName, TFlt& ValX) const;
4328  int GetSAttrDatN(const TInt& NId, const TInt& AttrId, TFlt& ValX) const;
4329 
4331  int GetSAttrDatN(const TNodeI& NodeI, const TStr& AttrName, TFlt& ValX) const {
4332  return GetSAttrDatN(NodeI.GetId(), AttrName, ValX);
4333  }
4335  int GetSAttrDatN(const TNodeI& NodeI, const TInt& AttrId, TFlt& ValX) const {
4336  return GetSAttrDatN(NodeI.GetId(), AttrId, ValX);
4337  }
4338 
4340  int GetSAttrDatN(const TInt& NId, const TStr& AttrName, TStr& ValX) const;
4342  int GetSAttrDatN(const TInt& NId, const TInt& AttrId, TStr& ValX) const;
4343 
4345  int GetSAttrDatN(const TNodeI& NodeI, const TStr& AttrName, TStr& ValX) const {
4346  return GetSAttrDatN(NodeI.GetId(), AttrName, ValX);
4347  }
4349  int GetSAttrDatN(const TNodeI& NodeI, const TInt& AttrId, TStr& ValX) const {
4350  return GetSAttrDatN(NodeI.GetId(), AttrId, ValX);
4351  }
4352 
4354  int DelSAttrDatN(const TInt& NId, const TStr& AttrName);
4356  int DelSAttrDatN(const TInt& NId, const TInt& AttrId);
4357 
4359  int DelSAttrDatN(const TNodeI& NodeI, const TStr& AttrName) {
4360  return DelSAttrDatN(NodeI.GetId(), AttrName);
4361  }
4363  int DelSAttrDatN(const TNodeI& NodeI, const TInt& AttrId) {
4364  return DelSAttrDatN(NodeI.GetId(), AttrId);
4365  }
4366 
4368  int GetSAttrVN(const TInt& NId, const TAttrType AttrType, TAttrPrV& AttrV) const;
4370  int GetSAttrVN(const TNodeI& NodeI, const TAttrType AttrType, TAttrPrV& AttrV) const {
4371  return GetSAttrVN(NodeI.GetId(), AttrType, AttrV);
4372  }
4373 
4375  int GetIdVSAttrN(const TStr& AttrName, TIntV& IdV) const;
4377  int GetIdVSAttrN(const TInt& AttrId, TIntV& IdV) const;
4378 
4380  int AddSAttrN(const TStr& Name, const TAttrType& AttrType, TInt& AttrId);
4381 
4383  int GetSAttrIdN(const TStr& Name, TInt& AttrIdX, TAttrType& AttrTypeX) const;
4385  int GetSAttrNameN(const TInt& AttrId, TStr& NameX, TAttrType& AttrTypeX) const;
4386 
4388  int AddSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName, const TInt& Val);
4390  int AddSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId, const TInt& Val);
4391 
4393  int AddSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName, const TInt& Val) {
4394  return AddSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName, Val);
4395  }
4397  int AddSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId, const TInt& Val) {
4398  return AddSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId, Val);
4399  }
4400 
4402  int AddSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName, const TFlt& Val);
4404  int AddSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId, const TFlt& Val);
4405 
4407  int AddSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName, const TFlt& Val) {
4408  return AddSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName, Val);
4409  }
4411  int AddSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId, const TFlt& Val){
4412  return AddSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId, Val);
4413  }
4414 
4416  int AddSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName, const TStr& Val);
4418  int AddSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId, const TStr& Val);
4419 
4421  int AddSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName, const TStr& Val) {
4422  return AddSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName, Val);
4423  }
4425  int AddSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId, const TStr& Val) {
4426  return AddSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId, Val);
4427  }
4428 
4430  int GetSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName, TInt& ValX) const;
4432  int GetSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId, TInt& ValX) const;
4433 
4435  int GetSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName, TInt& ValX) const {
4436  return GetSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName, ValX);
4437  }
4439  int GetSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId, TInt& ValX) const {
4440  return GetSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId, ValX);
4441  }
4442 
4444  int GetSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName, TFlt& ValX) const;
4446  int GetSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId, TFlt& ValX) const;
4447 
4449  int GetSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName, TFlt& ValX) const {
4450  return GetSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName, ValX);
4451  }
4453  int GetSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId, TFlt& ValX) const {
4454  return GetSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId, ValX);
4455  }
4456 
4458  int GetSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName, TStr& ValX) const;
4460  int GetSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId, TStr& ValX) const;
4461 
4463  int GetSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName, TStr& ValX) const {
4464  return GetSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName, ValX);
4465  }
4467  int GetSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId, TStr& ValX) const {
4468  return GetSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId, ValX);
4469  }
4470 
4472  int DelSAttrDatE(const int& SrcNId, const int& DstNId, const TStr& AttrName);
4474  int DelSAttrDatE(const int& SrcNId, const int& DstNId, const TInt& AttrId);
4475 
4477  int DelSAttrDatE(const TEdgeI& EdgeI, const TStr& AttrName) {
4478  return DelSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName);
4479  }
4481  int DelSAttrDatE(const TEdgeI& EdgeI, const TInt& AttrId) {
4482  return DelSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId);
4483  }
4485  int GetSAttrVE(const int& SrcNId, const int& DstNId, const TAttrType AttrType, TAttrPrV& AttrV) const;
4487  int GetSAttrVE(const TEdgeI& EdgeI, const TAttrType AttrType, TAttrPrV& AttrV) const {
4488  return GetSAttrVE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrType, AttrV);
4489  }
4490 
4492  int GetIdVSAttrE(const TStr& AttrName, TIntPrV& IdV) const;
4494  int GetIdVSAttrE(const TInt& AttrId, TIntPrV& IdV) const;
4495 
4497  int AddSAttrE(const TStr& Name, const TAttrType& AttrType, TInt& AttrId);
4498 
4500  int GetSAttrIdE(const TStr& Name, TInt& AttrIdX, TAttrType& AttrTypeX) const;
4502  int GetSAttrNameE(const TInt& AttrId, TStr& NameX, TAttrType& AttrTypeX) const;
4503 
4504  friend class TPt<TDirNet>;
4505  friend class TDirNetMtx;
4506 };
4507 
4508 // set flags
4509 namespace TSnap {
4510 template <> struct IsDirected<TDirNet> { enum { Val = 1 }; };
4511 }
4512 #endif // NETWORK_H
int AddNodeUnchecked(int NId=-1)
Adds a node of ID NId to the network, noop if the node already exists.
Definition: network.h:1495
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:4487
int GetNbrEId(const int &EdgeN) const
Definition: network.h:1102
int AddEdge(const TEdgeI &EdgeI)
Adds an edge from EdgeI.GetSrcNId() to EdgeI.GetDstNId() to the network.
Definition: network.h:247
TEdgeI EndEI() const
Returns an iterator referring to the past-the-end edge in the network.
Definition: network.h:4223
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:708
TEdgeI GetEI(const int &EId) const
Not supported/implemented!
void LoadNetworkShM(TShMIn &ShMIn)
Definition: network.h:1268
Definition: bd.h:440
TEdgeDat & GetOutEDat(const int &EdgeN)
Definition: network.h:1211
#define IAssert(Cond)
Definition: bd.h:262
static int GetNIdPos(const TVec< TPair< TInt, TEdgeData > > &NIdV, const int &NId)
Definition: network.h:823
TVec< TIntV > VecOfIntVecsN
Definition: network.h:2063
int AddSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to NodeI.
Definition: network.h:3125
TNEANet(TSIn &SIn)
Constructor for loading the graph from a (binary) stream SIn.
Definition: network.h:2154
bool IsNbrNId(const int &NId) const
Tests whether node with ID NId is a neighbor of the current node.
Definition: network.h:1831
int GetSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, TFlt &ValX) const
Gets Flt sparse attribute with name AttrName from EdgeI.
Definition: network.h:4449
TInt MxEId
Definition: network.h:1258
TNodeData TNodeDat
Definition: network.h:1076
TEdgeI(const THashIter &EdgeHIter, const TNodeEdgeNet *NetPt)
Definition: network.h:1226
static const T & Mn(const T &LVal, const T &RVal)
Definition: xmath.h:36
TNodeI & operator++(int)
Increment iterator.
Definition: network.h:548
THash< TStr, TBool > KeyToDenseE
Definition: network.h:2058
TNodeNet(const TNodeNet &NodeNet)
Definition: network.h:163
TEdgeI & operator++(int)
Definition: network.h:1229
TNodeI(const THashIter &NodeHIter, const TNodeNet *NetPt)
Definition: network.h:65
TPair< TInt, TInt > TIntPr
Definition: ds.h:83
TNodeData & GetDat()
Definition: network.h:517
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:1123
void IntVAttrNameNI(const TInt &NId, TStrV &Names) const
Returns a vector of int attr names for node NId.
Definition: network.h:2550
int DelSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName)
Deletes sparse attribute with name AttrName from EdgeI.
Definition: network.h:4477
void Reserve(const int &Nodes, const int &Edges)
Reserves memory for a network of Nodes nodes and Edges edges.
Definition: network.h:4241
TNodeData & GetOutNDat(const int &EdgeN)
Definition: network.h:1192
bool IsDeleted() const
Returns true if the attribute has been deleted.
Definition: network.h:1928
TInt GetIntAttrDatN(const TNodeI &NodeI, const TStr &attr)
Gets the value of int attr from the node attr value vector.
Definition: network.h:2931
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:3773
Main namespace for all the Snap global entities.
Definition: alg.h:1
int GetRndNId(TRnd &Rnd=TInt::Rnd)
Returns an ID of a random node in the graph.
Definition: network.h:2821
TVec< TFltV >::TIter TFltVVecIter
Definition: network.h:1960
bool DelIfIn(const TVal &Val)
Removes the first occurrence of element Val.
Definition: ds.h:1212
int GetDeg() const
Returns degree of the current node.
Definition: network.h:3455
void Clr()
Deletes all nodes and edges from the network.
Definition: network.h:1421
TIter EndI() const
Returns an iterator referring to the past-the-end element in the vector.
Definition: ds.h:595
int GetInEId(const int &EdgeN) const
Returns ID of EdgeN-th in-edge.
Definition: network.h:1197
const TNodeData & GetInNDat(const int &EdgeN) const
Definition: network.h:1189
int GetId() const
Definition: network.h:1781
int GetNbrEId(const int &EdgeN) const
Returns ID of EdgeN-th in or out-edge.
Definition: network.h:1201
static PUndirNet New()
Static constructor that returns a pointer to the network. Call: PUndirNet Graph = TUndirNet::New()...
Definition: network.h:3547
int GetNodes() const
Returns the number of nodes in the network.
Definition: network.h:2363
TPt< TIntNEDNet > PIntNEDNet
Definition: network.h:1065
const TEdgeDat & GetOutEDat(const int &EdgeN) const
Definition: network.h:1212
int GetSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, TInt &ValX) const
Gets Int sparse attribute with id AttrId from NodeI.
Definition: network.h:4321
void SetNDat(const int &NId, const TNodeData &NodeDat)
Sets node data for the node of ID NId in the network.
Definition: network.h:1539
bool IsKeyIdEqKeyN() const
Definition: hash.h:233
TPt< TIntFltNEDNet > PIntFltNEDNet
Definition: network.h:1067
void SortEIdByDat(const bool &Asc=true)
Sorts edges by edge data.
Definition: network.h:1432
void LoadShM(TShMIn &MStream)
Definition: network.h:3425
THash< TInt, TNode >::TIter THashIter
Definition: network.h:4005
#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:1172
void LoadNetworkShM(TShMIn &ShMIn)
Definition: network.h:153
int GetSrcNId() const
Definition: network.h:1782
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:2935
THash< TStr, TFlt > FltDefaultsE
Definition: network.h:2062
TNode(TSIn &SIn)
Definition: network.h:1091
int AppendIntVAttrDatN(const TNodeI &NodeI, const TInt &value, const TStr &attr)
Appends value onto the TIntV attribute for the given node.
Definition: network.h:2880
virtual void Save(TSOut &SOut) const
Saves the network to a (binary) stream SOut.
Definition: network.h:659
int AddSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, const TInt &Val)
Adds Int sparse attribute with id AttrId to EdgeI.
Definition: network.h:3839
int GetDeg() const
Returns degree of the current node.
Definition: network.h:76
int AddFltAttrDatE(const TEdgeI &EdgeI, const TFlt &value, const TStr &attr)
Attribute based add function for attr to Flt value.
Definition: network.h:2908
bool IsOutNId(const int &NId) const
Tests whether the current node points to node with ID NId.
Definition: network.h:3480
TNode(const int &NId, const TNodeData &NodeData)
Definition: network.h:1089
int GetOutNId(const int &EdgeN) const
Returns ID of EdgeN-th out-node (the node the current node points to).
Definition: network.h:1821
int GetDeg() const
Definition: network.h:36
TDirNet(const TDirNet &Graph)
Definition: network.h:4099
TNode & GetNode(const int &NId)
Definition: network.h:139
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:2518
void Save_V1(TSOut &SOut) const
Saves the network to a (binary) stream SOut. Available for backwards compatibility.
Definition: network.h:4105
THash< TInt, TNode > NodeH
Definition: network.h:3510
int AddFltVAttrDatE(const TEdgeI &EdgeI, const TFltV &value, const TStr &attr)
Attribute based add function for attr to TFltV value.
Definition: network.h:2924
int GetOutDeg() const
Returns out-degree of the current node.
Definition: network.h:1813
TEdgeI(const TNodeI &NodeI, const TNodeI &EndNodeI, const int &EdgeN=0)
Definition: network.h:119
int GetSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from NodeI.
Definition: network.h:3759
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:1389
const TNodeData & GetNDat(const int &NId) const
Returns node data for the node of ID NId in the network.
Definition: network.h:1348
const TNodeData & GetDat() const
Definition: network.h:516
TNode(TSIn &SIn)
Definition: network.h:3410
TVec< TStrV > VecOfStrVecsE
Definition: network.h:2064
TCRef CRef
Definition: network.h:635
THash< TStr, TInt > IntDefaultsE
Definition: network.h:2060
int GetInNId(const int &EdgeN) const
Returns ID of EdgeN-th in-node (the node pointing to the current node).
Definition: network.h:1168
void Save(TSOut &SOut) const
Definition: network.h:1092
int GetSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, TFlt &ValX) const
Gets Flt sparse attribute with id AttrId from NodeI.
Definition: network.h:4335
TNodeEDatNet & operator=(const TNodeEDatNet &NodeNet)
Definition: network.h:676
TCRef CRef
Definition: network.h:4073
const TNodeData & operator()() const
Definition: network.h:579
void Save(TSOut &SOut) const
Definition: network.h:1755
void Save_V1(TSOut &SOut) const
Saves the graph to a (binary) stream SOut. Available for backwards compatibility. ...
Definition: network.h:2203
int AddNode(const TNodeI &NodeI)
Adds a node NodeI and its node data to the network.
Definition: network.h:700
TNode(const TNode &Node)
Definition: network.h:3409
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:4179
TNode & GetNode(const int &NId)
Definition: network.h:4079
int GetId() const
Returns edge ID. Always returns -1 since only edges in multigraphs have explicit IDs.
Definition: network.h:4065
int GetSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, TStr &ValX) const
Gets Str sparse attribute with name AttrName from EdgeI.
Definition: network.h:4463
int GetInNId(const int &NodeN) const
Returns ID of NodeN-th in-node (the node pointing to the current node).
Definition: network.h:563
int AddEdge(const TEdgeI &EdgeI)
Adds an edge from EdgeI.GetSrcNId() to EdgeI.GetDstNId() and its edge data to the network...
Definition: network.h:1372
int GetOutDeg() const
Returns out-degree of the current node (returns same as value GetDeg() since the network is undirecte...
Definition: network.h:3459
int DelSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId)
Deletes sparse attribute with id AttrId from EdgeI.
Definition: network.h:3331
int GetSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, TFlt &ValX) const
Gets Flt sparse attribute with name AttrName from NodeI.
Definition: network.h:4331
void SortNIdById(const bool &Asc=true)
Sorts nodes by node IDs.
Definition: network.h:1426
bool Empty() const
Tests whether the network is empty (has zero nodes).
Definition: network.h:273
int GetInNId(const int &NodeN) const
Definition: network.h:41
int GetInNId(const int &NodeN) const
Definition: network.h:3416
void Reserve(const int &Nodes, const int &Edges)
Reserves memory for a network of Nodes nodes and Edges edges.
Definition: network.h:1423
TEdgeI GetEI(const int &EId) const
Returns an iterator referring to edge with edge ID EId.
Definition: network.h:2816
void DelNode(const int &NId)
Deletes node of ID NId from the network.
Definition: network.h:878
TNodeData & GetDat()
Definition: network.h:1188
int AddSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to EdgeI.
Definition: network.h:3243
int GetEdges() const
Returns the number of edges in the network.
Definition: network.h:898
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:390
int AddEdge(const TEdgeI &EdgeI)
Adds an edge between EdgeI.GetSrcNId() and EdgeI.GetDstNId() to the graph.
Definition: network.h:2794
int GetSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, TInt &ValX) const
Gets Int sparse attribute with id AttrId from NodeI.
Definition: network.h:3763
bool operator<(const TEdgeI &EdgeI) const
Definition: network.h:125
Definition: dt.h:11
void SortNIdV()
Sorts the adjacency lists of the current node.
Definition: network.h:4028
TAFltI & operator++(int)
Definition: network.h:2025
const TNode & GetNode(const int &NId) const
Returns node element for the node of ID NId in the network.
Definition: network.h:225
Definition: attr.h:98
bool IsNbrEId(const int &EId) const
Definition: network.h:1105
TEdgeI(const THashIter &EdgeHIter, const TNEANet *GraphPt)
Definition: network.h:1874
int AddNodeUnchecked(int NId=-1)
Adds a node of ID NId to the network, noop if the node already exists.
Definition: network.h:848
TPt< TStrIntNEDNet > PStrIntNEDNet
Definition: network.h:1069
THash< TInt, TNode >::TIter THashIter
Definition: network.h:539
TNodeData & GetNDat(const int &NId)
Returns node data for the node of ID NId in the network.
Definition: network.h:720
int AddEdge(const TEdgeI &EdgeI)
Definition: network.h:4211
void Del(const TSizeTy &ValN)
Removes the element at position ValN.
Definition: ds.h:1189
Edge iterator. Only forward iteration (operator++) is supported.
Definition: network.h:3486
TEdgeI EndEI() const
Returns an iterator referring to the past-the-end edge in the network.
Definition: network.h:758
THashIter EdgeHI
Definition: network.h:1222
TInt CheckDenseOrSparseN(const TStr &attr) const
Return 1 if in Dense, 0 if in Sparse, -1 if neither.
Definition: network.h:2110
void AttrNameEI(const TInt &EId, TStrV &Names) const
Returns a vector of attr names for edge EId.
Definition: network.h:2586
static const T & Mx(const T &LVal, const T &RVal)
Definition: xmath.h:32
TVec< THash< TInt, TIntV > > VecOfIntHashVecsE
Definition: network.h:2068
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:3929
int GetOutNId(const int &NodeN) const
Definition: network.h:3986
void SortNIdByDat(const bool &Asc=true)
Sorts nodes by node data.
Definition: network.h:282
TNodeData & GetOutNDat(const int &NodeN)
Definition: network.h:106
int GetNbrNId(const int &NodeN) const
Returns ID of NodeN-th neighboring node.
Definition: network.h:3476
TStrVecIter HI
Definition: network.h:1987
void GetNIdV(TIntV &NIdV) const
Returns a vector of all node IDs in the network.
Definition: network.h:1634
const TNodeData & GetDat() const
Definition: network.h:39
THash< TInt, TFltV >::TIter TFltHVecIter
Definition: network.h:1963
int GetId() const
Returns ID of the current node.
Definition: network.h:3453
void Save(TSOut &SOut) const
Definition: dt.h:1153
static PNEANet Load(TSIn &SIn)
Static constructor that loads the graph from a stream SIn and returns a pointer to it...
Definition: network.h:2232
TEdgeData & GetInEDat(const int &EdgeN)
Definition: network.h:592
int GetSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, TStr &ValX) const
Gets Str sparse attribute with id AttrId from EdgeI.
Definition: network.h:4467
TNode & GetNode(const int &NId)
Definition: network.h:2030
TNodeI BegNI() const
Returns an iterator referring to the first node in the network.
Definition: network.h:1338
int AddNode(const TNodeI &NodeI)
Definition: network.h:1328
void StrAttrNameNI(const TInt &NId, TStrV &Names) const
Returns a vector of str attr names for node NId.
Definition: network.h:2569
TNodeI(const TNodeI &NodeI)
Definition: network.h:1800
int AddSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to EdgeI.
Definition: network.h:3835
void DelNode(const TNode &NodeI)
Deletes node of ID NodeI.GetId() from the network.
Definition: network.h:706
void FltAttrNameNI(const TInt &NId, TStrV &Names) const
Returns a vector of int attr names for node NId.
Definition: network.h:2577
bool IsInEId(const int &EId) const
Tests whether the edge with ID EId is an in-edge of current node.
Definition: network.h:1839
TNodeI(const THashIter &NodeHIter, const TNodeEdgeNet *NetPt)
Definition: network.h:1150
TPt< TUndirNet > PNet
Definition: network.h:3400
void IntVAttrValueEI(const TInt &EId, TVec< TIntV > &Values) const
Returns a vector of attr values for edge EId.
Definition: network.h:2608
bool operator<(const TNodeI &NodeI) const
Definition: network.h:1155
void SortNodeAdjV()
Sorts the adjacency lists of each node.
Definition: network.h:3687
void ReserveNIdInDeg(const int &NId, const int &InDeg)
Reserves memory for node ID NId having InDeg in-edges.
Definition: network.h:4243
int AddNode(int NId=-1)
Adds a node of ID NId to the network.
Definition: network.h:836
Directed network.
Definition: network.h:3966
TVec< THash< TInt, TFltV > > VecOfFltHashVecsN
Definition: network.h:2069
TAttrPair SAttrE
Definition: network.h:4077
void Save(TSOut &SOut) const
Saves the network to a (binary) stream SOut. Expects data structures for sparse attributes.
Definition: network.h:3542
bool IsOutNId(const int &NId) const
Definition: network.h:524
virtual ~TNodeEDatNet()
Definition: network.h:657
void PackOutNIdV()
Definition: network.h:3991
const TNodeData & GetOutNDat(const int &EdgeN) const
Definition: network.h:1191
TInt GetIntAttrDefaultE(const TStr &attribute) const
Gets Int edge attribute val. If not a proper attr, return default.
Definition: network.h:2044
bool IsNbrNId(const int &NId) const
Tests whether node with ID NId is a neighbor of the current node.
Definition: network.h:98
TNodeData & GetDat()
Definition: network.h:40
TInt CheckDenseOrSparseE(const TStr &attr) const
Definition: network.h:2116
TNodeI(const TNodeI &NodeI)
Definition: network.h:545
TNodeEdgeNet< TFlt, TFlt > TFltNENet
Definition: network.h:1717
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:2806
TFlt GetFltAttrDatE(const TEdgeI &EdgeI, const TStr &attr)
Gets the value of flt attr from the edge attr value vector.
Definition: network.h:2975
bool operator<(const TEdgeI &EdgeI) const
Definition: network.h:612
TEdgeI(const TEdgeI &EdgeI)
Definition: network.h:3493
TNodeEDatNet(const int &Nodes, const int &Edges)
Constructor that reserves enough memory for a network of Nodes nodes and Edges edges.
Definition: network.h:653
bool IsInNId(const int &NId) const
Definition: network.h:3988
THash< TInt, TNode >::TIter THashIter
Definition: network.h:1794
TNodeData & GetDat()
Definition: network.h:1099
TPt< TIntNENet > PIntNENet
Definition: network.h:1716
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:924
int GetSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, TStr &ValX) const
Gets Str sparse attribute with id AttrId from EdgeI.
Definition: network.h:3909
int AddSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, const TInt &Val)
Adds Int sparse attribute with id AttrId to EdgeI.
Definition: network.h:4397
Tests (at compile time) if the graph is directed.
Definition: gbase.h:28
const TNEANet * Graph
Definition: network.h:1871
int AddIntVAttrDatE(const TEdgeI &EdgeI, const TIntV &value, const TStr &attr)
Attribute based add function for attr to IntV value.
Definition: network.h:2915
int GetInNId(const int &EdgeN) const
Returns ID of EdgeN-th in-node (the node pointing to the current node).
Definition: network.h:1817
TIter BegI() const
Definition: hash.h:213
TPt< TFltNNet > PFltNNet
Definition: network.h:484
bool operator<(const TNodeI &NodeI) const
Definition: network.h:70
const TEdge & GetEdgeKId(const int &EdgeKeyId) const
Definition: network.h:1255
const TNode & GetNode(const int &NId) const
Definition: network.h:1251
static PUndirNet LoadShM(TShMIn &ShMIn)
Static constructor that loads the network from memory.
Definition: network.h:3564
int AddSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, const TFlt &Val)
Adds Flt sparse attribute with id AttrId to EdgeI.
Definition: network.h:4411
bool IsNbrNId(const int &NId) const
Tests whether node with ID NId is a neighbor of the current node.
Definition: network.h:4046
TPt< TDirNet > PNet
Definition: network.h:3969
bool IsInNId(const int &NId) const
Tests whether node with ID NId points to the current node.
Definition: network.h:573
void LoadShM(TShMIn &MStream)
Definition: network.h:526
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
int GetInDeg() const
Returns in-degree of the current node.
Definition: network.h:4024
TNodeI GetRndNI(TRnd &Rnd=TInt::Rnd)
Returns an interator referring to a random node in the network.
Definition: network.h:1408
TAFltVI BegEAFltVI(const TStr &attr) const
Returns an iterator referring to the first edge's int attribute.
Definition: network.h:2705
TNode(const TNode &Node)
Definition: network.h:509
void GetFltAttrVal(TFltV &Val) const
Gets vector of flt attribute values.
Definition: network.h:1906
TEdgeI(const TEdgeI &EdgeI)
Definition: network.h:607
const TNEANet * Graph
Definition: network.h:1796
bool IsOutNId(const int &NId) const
Tests whether the current node points to node with ID NId.
Definition: network.h:4044
int GetDeg() const
Definition: network.h:1095
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:946
bool operator<(const TNode &Node) const
Definition: network.h:1093
void Save(TSOut &SOut) const
Definition: hash.h:183
int AppendFltVAttrDatN(const TNodeI &NodeI, const TFlt &value, const TStr &attr)
Appends value onto the TFltV attribute for the given node.
Definition: network.h:2887
virtual ~TNodeEdgeNet()
Definition: network.h:1282
void FltVAttrNameEI(const TInt &EId, TStrV &Names) const
Returns a vector of flt attr names for edge EId.
Definition: network.h:2613
int GetMxNId() const
Returns an ID that is larger than any node ID in the network.
Definition: network.h:1350
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:1336
TEdge(const int &EId, const int &SourceNId, const int &DestNId, const TEdgeData &EdgeData)
Definition: network.h:1122
TNodeEdgeNet(const TNodeEdgeNet &Net)
Definition: network.h:1279
void StrAttrValueNI(const TInt &NId, TStrV &Values) const
Returns a vector of attr values for node NId.
Definition: network.h:2573
static PNet New()
Static constructor that returns a pointer to the network. Call: TPt > Net = TNod...
Definition: network.h:170
TIntV GetIntVAttrDatE(const TEdgeI &EdgeI, const TStr &attr)
Gets the value of the intv attr from the edge attr value vector.
Definition: network.h:2978
const TNodeData & GetInNDat(const int &NodeN) const
Definition: network.h:103
TAFltVI BegNAFltVI(const TStr &attr) const
Returns an iterator referring to the first node's flt attribute.
Definition: network.h:2457
int GetNodes() const
Returns the number of nodes in the network.
Definition: network.h:1307
TNodeI & operator++(int)
Increment iterator.
Definition: network.h:1154
TStrIntPrH KeyToIndexTypeE
Definition: network.h:2056
const TNodeData & GetInNDat(const int &NodeN) const
Definition: network.h:585
TEdgeData & GetOutEDat(const int &EdgeN)
Definition: network.h:521
int GetSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, TInt &ValX) const
Gets Int sparse attribute with id AttrId from EdgeI.
Definition: network.h:3881
int GetSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from EdgeI.
Definition: network.h:3877
TStr GetStrAttrDatE(const TEdgeI &EdgeI, const TStr &attr)
Gets the value of str attr from the edge attr value vector.
Definition: network.h:2972
Edge iterator. Only forward iteration (operator++) is supported.
Definition: network.h:113
int GetNbrNId(const int &NodeN) const
Definition: network.h:3418
void SetAllEDat(const TEdgeData &EdgeDat)
Sets edge data for all the edges in the network to EDat.
Definition: network.h:975
bool IsInNId(const int &NId) const
Definition: network.h:44
TEdgeData EdgeDat
Definition: network.h:1118
void Save(TSOut &SOut) const
Saves the network to a (binary) stream SOut. Expects data structures for sparse attributes.
Definition: network.h:4103
TNodeI & operator=(const TNodeI &NodeI)
Definition: network.h:67
TEdgeI GetEI(const int &SrcNId, const int &DstNId) const
Returns an iterator referring to edge (SrcNId, DstNId) in the graph.
Definition: network.h:2818
TNodeI EndNI() const
Returns an iterator referring to the past-the-end node in the network.
Definition: network.h:221
TNodeI(const TNodeI &NodeI)
Definition: network.h:66
int GetEdges() const
Returns the number of edges in the network.
Definition: network.h:373
int GetRndEId(TRnd &Rnd=TInt::Rnd)
Returns an ID of a random edge in the graph.
Definition: network.h:2825
int GetSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, TFlt &ValX) const
Gets Flt sparse attribute with id AttrId from NodeI.
Definition: network.h:3777
bool IsOutEId(const int &EId) const
Tests whether the edge with ID EId is an out-edge of current node.
Definition: network.h:1205
int GetOutEId(const int &EdgeN) const
Returns ID of EdgeN-th out-edge.
Definition: network.h:1835
TNode(TSIn &SIn)
Definition: network.h:33
TAFltVI EndNAFltVI(const TStr &attr) const
Returns an iterator referring to the past-the-end node's attribute.
Definition: network.h:2474
THash< TInt, TNode > NodeH
Definition: network.h:144
TAttr SAttrN
Definition: network.h:2072
Node iterator. Only forward iteration (operator++) is supported.
Definition: network.h:4003
TStr GetDat() const
Returns an attribute of the node.
Definition: network.h:1999
int GetOutNId(const int &NodeN) const
Definition: network.h:42
TFltVecIter HI
Definition: network.h:2010
TEdge(const TEdge &Edge)
Definition: network.h:1778
TNodeData & GetNbrNDat(const int &NodeN)
Definition: network.h:588
TNodeI & operator++(int)
Increment iterator.
Definition: network.h:69
TCRef CRef
Definition: network.h:1257
TInt GetDat() const
Returns an attribute of the node.
Definition: network.h:1926
int GetOutDeg() const
Definition: network.h:1097
TVec< TIntV >::TIter TIntVVecIter
Definition: network.h:1935
bool IsNbrNId(const int &NId) const
Definition: network.h:525
THash< TStr, TFlt > FltDefaultsN
Definition: network.h:2062
void SortNIdById(const bool &Asc=true)
Sorts nodes by node IDs.
Definition: network.h:791
void Reserve(const int &Nodes, const int &Edges)
Reserves memory for a network of Nodes nodes and Edges edges.
Definition: network.h:3683
TEdgeI GetRndEI(TRnd &Rnd=TInt::Rnd)
Returns an interator referring to a random edge in the graph.
Definition: network.h:2827
const TEdge & GetEdge(const int &EId) const
Definition: network.h:1254
bool IsEdge(const int &EId) const
Tests whether an edge with edge ID EId exists in the graph.
Definition: network.h:2804
TEdgeData TEdgeDat
Definition: network.h:494
static PNet LoadShM(TShMIn &ShMIn)
Static constructor that loads the network from shared memory.
Definition: network.h:178
const TNodeData & GetNbrNDat(const int &NodeN) const
Definition: network.h:587
int GetUniqEdges(const bool &IsDir=true) const
Returns the number of edges in the network with a unique pair of nodes.
Definition: network.h:1545
TNodeEDatNet< TInt, TFlt > TIntFltNEDNet
Definition: network.h:1066
int AddNode(int NId=-1)
Adds a node of ID NId to the network.
Definition: network.h:1483
Definition: fl.h:384
TAttr SAttrN
Definition: network.h:4076
TNodeData & GetNbrNDat(const int &EdgeN)
Definition: network.h:1194
int AppendFltVAttrDatE(const TEdgeI &EdgeI, const TFlt &value, const TStr &attr)
Appends value onto the TFltV attribute for the given node.
Definition: network.h:2927
TNodeData & GetInNDat(const int &NodeN)
Definition: network.h:586
const TNEANet * Graph
Definition: network.h:1942
void IntAttrValueEI(const TInt &EId, TIntV &Values) const
Returns a vector of attr values for edge EId.
Definition: network.h:2598
TEdgeI GetEI(const int &EId) const
Not supported/implemented!
int AddIntAttrDatE(const TEdgeI &EdgeI, const TInt &value, const TStr &attr)
Attribute based add function for attr to Int value.
Definition: network.h:2898
TInt MxNId
Definition: network.h:2052
TIntV OutEIdV
Definition: network.h:1749
void ReserveNIdOutDeg(const int &NId, const int &OutDeg)
Reserves memory for node ID NId having OutDeg out-edges.
Definition: network.h:4245
int GetNbrNId(const int &EdgeN) const
Returns ID of EdgeN-th neighboring node.
Definition: network.h:1176
int AddSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, const TStr &Val)
Adds Str sparse attribute with id AttrId to EdgeI.
Definition: network.h:3867
int AddSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, const TInt &Val)
Adds Int sparse attribute with id AttrId to NodeI.
Definition: network.h:4279
TEdgeI(const TNodeI &NodeI, const TNodeI &EndNodeI, const int &EdgeN=0)
Definition: network.h:4056
TNodeData & GetNDat(const int &NId)
Returns node data for the node of ID NId in the network.
Definition: network.h:1346
TFlt GetDat() const
Returns an attribute of the node.
Definition: network.h:2022
int GetDeg() const
Definition: network.h:3982
int GetDeg() const
Returns degree of the current node, the sum of in-degree and out-degree.
Definition: network.h:4022
TNodeData & GetNDat(const int &NId)
Returns node data for the node of ID NId in the network.
Definition: network.h:229
bool IsOutEId(const int &EId) const
Definition: network.h:1764
TAIntI BegNAIntI(const TStr &attr) const
Returns an iterator referring to the first node's int attribute.
Definition: network.h:2393
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:262
int AddSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, const TFlt &Val)
Adds Flt sparse attribute with name AttrName to NodeI.
Definition: network.h:3731
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:2941
Node iterator. Only forward iteration (operator++) is supported.
Definition: network.h:1792
Node/edge integer attribute iterator. Iterates through all nodes/edges for one integer attribute...
Definition: network.h:1911
int GetInNId(const int &EdgeN) const
Definition: network.h:518
TAFltI(const TAFltI &I)
Definition: network.h:2017
void AttrValueNI(const TInt &NId, TStrV &Values) const
Returns a vector of attr values for node NId.
Definition: network.h:2535
int GetSrcNId() const
Gets the source node of an edge.
Definition: network.h:130
TEdgeData & operator()()
Definition: network.h:620
void GetStrAttrNames(TStrV &Names) const
Gets vector of str attribute names.
Definition: network.h:1900
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:953
TVec< TIntV > VecOfIntVecsE
Definition: network.h:2063
TIter EndI() const
Definition: hash.h:218
void Defrag(const bool &OnlyNodeLinks=false)
Defragments the network.
Definition: network.h:1650
TNodeI & operator=(const TNodeI &NodeI)
Definition: network.h:1152
const TEdgeData & GetInEDat(const int &EdgeN) const
Definition: network.h:593
int DelSAttrDatN(const TNodeI &NodeI, const TStr &AttrName)
Deletes sparse attribute with name AttrName from NodeI.
Definition: network.h:3801
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:1843
void IntAttrNameNI(const TInt &NId, TStrV &Names) const
Returns a vector of int attr names for node NId.
Definition: network.h:2540
int GetSrcNId() const
Gets the source node of an edge.
Definition: network.h:617
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:2420
TNodeI GetRndNI(TRnd &Rnd=TInt::Rnd)
Returns an interator referring to a random node in the network.
Definition: network.h:268
TNode(const int &NId)
Definition: network.h:3977
int GetNodes() const
Returns the number of nodes in the network.
Definition: network.h:189
int GetInDeg() const
Definition: network.h:3983
bool IsNbrNId(const int &NId) const
Definition: network.h:3990
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:3551
bool IsNbrNId(const int &NId) const
Definition: network.h:46
TEdgeI GetEI(const int &EId) const
Not supported/implemented!
Definition: network.h:1393
void LoadNetworkShM(TShMIn &ShMIn)
Definition: network.h:3525
TNodeData NodeDat
Definition: network.h:1085
static TRnd Rnd
Definition: dt.h:1146
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:2776
TNodeI BegNI() const
Returns an iterator referring to the first node in the network.
Definition: network.h:219
int GetNbrEId(const int &EdgeN) const
Definition: network.h:1762
int AddSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, const TInt &Val)
Adds Int sparse attribute with id AttrId to NodeI.
Definition: network.h:3129
bool IsDeleted() const
Returns true if the attribute has been deleted.
Definition: network.h:2024
TAFltVI & operator++(int)
Definition: network.h:1979
TDirNet TNet
Definition: network.h:3968
int GetInDeg() const
Returns in-degree of the current node.
Definition: network.h:557
TAFltI BegEAFltI(const TStr &attr) const
Returns an iterator referring to the first edge's flt attribute.
Definition: network.h:2768
void SetNDat(const int &NId, const TNodeData &NodeDat)
Sets node data for the node of ID NId in the network.
Definition: network.h:367
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:2764
TVec< TVec< TFltV > > VecOfFltVecVecsN
Definition: network.h:2067
Node/edge float attribute iterator. Iterates through all nodes/edges for one float attribute...
Definition: network.h:2007
int AddNode(const TNodeI &NodeI)
Adds a node of ID NodeI.GetId() to the graph.
Definition: network.h:2377
TIntV InNIdV
Definition: network.h:27
Node Edge Network (directed multigraph, TNEGraph with data on nodes and edges).
Definition: network.h:1074
int GetSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, TFlt &ValX) const
Gets Flt sparse attribute with id AttrId from EdgeI.
Definition: network.h:4453
int GetId() const
Returns edge ID.
Definition: network.h:1882
void LoadShM(TShMIn &ShMIn)
Load THash from shared memory file. Copying/Deleting Keys is illegal.
Definition: hash.h:157
static PUndirNet Load(TSIn &SIn)
Static constructor that loads the network from a stream SIn and returns a pointer to it...
Definition: network.h:3553
void PackNIdV()
Definition: network.h:3992
void Load(TSIn &InStream)
Definition: network.h:1784
int GetOutNId(const int &EdgeN) const
Definition: network.h:519
TSizeTy AddSorted(const TVal &Val, const bool &Asc=true, const TSizeTy &_MxVals=-1)
Adds element Val to a sorted vector.
Definition: ds.h:1117
void ErrNotify(const char *NotifyCStr)
Definition: bd.h:74
TNodeEDatNet< TInt, TInt > TIntNEDNet
Definition: network.h:1064
void Defrag()
Definition: hash.h:555
bool IsOutEId(const int &EId) const
Definition: network.h:1104
TAIntI BegEAIntI(const TStr &attr) const
Returns an iterator referring to the first edge's int attribute.
Definition: network.h:2640
int GetNbrNId(const int &NodeN) const
Definition: network.h:3987
virtual void Save(TSOut &SOut) const
Saves the network to a (binary) stream SOut.
Definition: network.h:1284
const TNodeData & GetNDat(const int &NId) const
Returns node data for the node of ID NId in the network.
Definition: network.h:231
int DelSAttrDatN(const TNodeI &NodeI, const TStr &AttrName)
Deletes sparse attribute with name AttrName from NodeI.
Definition: network.h:4359
bool operator==(const TEdgeI &EdgeI) const
Definition: network.h:613
Definition: dt.h:1386
TEdge(const int &EId, const int &SourceNId, const int &DestNId)
Definition: network.h:1121
TVec< TStrV > VecOfStrVecsN
Definition: network.h:2064
void GetStrAttrVal(TStrV &Val) const
Gets vector of str attribute values.
Definition: network.h:1902
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:217
TPt< TNet > PNet
Definition: network.h:496
TNodeEDatNet(const TNodeEDatNet &NodeNet)
Definition: network.h:654
int GetNbrNId(const int &NodeN) const
Returns ID of NodeN-th neighboring node.
Definition: network.h:571
Definition: fl.h:58
void Save(TSOut &SOut) const
Definition: ds.h:954
const TNEANet * Graph
Definition: network.h:1967
TEdgeI & operator++(int)
Increment iterator.
Definition: network.h:123
TNodeI GetNI(const int &NId) const
Returns an iterator referring to the node of ID NId in the network.
Definition: network.h:223
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:1557
int GetDeg() const
Returns degree of the current node, the sum of in-degree and out-degree.
Definition: network.h:1809
int GetSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, TStr &ValX) const
Gets Str sparse attribute with id AttrId from NodeI.
Definition: network.h:3199
void DelNode(const TNode &NodeI)
Deletes node of ID NodeI.GetId() from the network.
Definition: network.h:3618
int AddFltAttrDatN(const TNodeI &NodeI, const TFlt &value, const TStr &attr)
Attribute based add function for attr to Flt value.
Definition: network.h:2868
int GetInEId(const int &EdgeN) const
Returns ID of EdgeN-th in-edge.
Definition: network.h:1833
int DelSAttrDatN(const TNodeI &NodeI, const TInt &AttrId)
Deletes sparse attribute with id AttrId from NodeI.
Definition: network.h:4363
void IntVAttrValueNI(const TInt &NId, TVec< TIntV > &Values) const
Returns a vector of attr values for node NId.
Definition: network.h:2554
int GetInDeg() const
Returns in-degree of the current node.
Definition: network.h:78
TEdge(TSIn &SIn)
Definition: network.h:1124
bool IsOutNId(const int &NId) const
Tests whether the current node points to node with ID NId.
Definition: network.h:575
int AddSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, const TStr &Val)
Adds Str sparse attribute with id AttrId to NodeI.
Definition: network.h:3749
THash< TInt, TIntV >::TIter TIntHVecIter
Definition: network.h:1938
THash< TInt, TEdge > EdgeH
Definition: network.h:2054
void PackNIdV()
Definition: network.h:3423
static PNet New()
Static constructor that returns a pointer to the network. Call: TPt > Net = TNodeEDatNet::New().
Definition: network.h:661
int GetSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, TStr &ValX) const
Gets Str sparse attribute with name AttrName from EdgeI.
Definition: network.h:3313
TNodeI(const THashIter &NodeHIter)
Definition: network.h:4009
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:2648
int DelFromIntVAttrDatN(const TNodeI &NodeI, const TInt &value, const TStr &attr)
Deletes value from the TIntV attribute for the given node.
Definition: network.h:2883
int AddIntVAttrDatN(const TNodeI &NodeI, const TIntV &value, const TStr &attr)
Attribute based add function for attr to IntV value.
Definition: network.h:2871
const TNodeData & GetSrcNDat() const
Definition: network.h:625
TAStrI EndEAStrI(const TStr &attr) const
Returns an iterator referring to the past-the-end edge's attribute.
Definition: network.h:2760
int GetDstNId() const
Returns the destination of the edge.
Definition: network.h:1886
TNode(const int &NId, const TNodeData &NodeData)
Definition: network.h:508
int GetSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, TFlt &ValX) const
Gets Flt sparse attribute with id AttrId from EdgeI.
Definition: network.h:3895
int AddSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, const TFlt &Val)
Adds Flt sparse attribute with name AttrName to EdgeI.
Definition: network.h:3257
int GetId() const
Definition: network.h:512
const TEdgeData & GetOutEDat(const int &EdgeN) const
Definition: network.h:522
TNodeI BegNI() const
Returns an iterator referring to the first node in the network.
Definition: network.h:3622
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:3001
bool operator==(const TNodeI &NodeI) const
Definition: network.h:71
bool operator==(const TEdgeI &EdgeI) const
Definition: network.h:1231
int AddSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, const TFlt &Val)
Adds Flt sparse attribute with name AttrName to NodeI.
Definition: network.h:3139
int GetMxNId() const
Returns an ID that is larger than any node ID in the network.
Definition: network.h:3628
static PNEANet LoadShM(TShMIn &ShMIn)
Static constructor that loads the network from memory.
Definition: network.h:2273
TEdgeI(const TEdgeI &EdgeI)
Definition: network.h:120
TAStrI BegEAStrI(const TStr &attr) const
Returns an iterator referring to the first edge's str attribute.
Definition: network.h:2757
virtual void DelNode(const int &NId)
Deletes node of ID NId from the network.
Definition: network.h:347
int AddEdge(const int &SrcNId, const int &DstNId)
Adds an edge from node SrcNId to node DstNId to the network.
Definition: network.h:906
const TNodeData & GetDat() const
Definition: network.h:1187
TNodeData & GetInNDat(const int &EdgeN)
Definition: network.h:1190
void SortNIdV()
Definition: network.h:3993
const TNode & GetNode(const int &NId) const
Definition: network.h:4080
TAStrI EndNAStrI(const TStr &attr) const
Returns an iterator referring to the past-the-end node's attribute.
Definition: network.h:2515
void Save(TSOut &SOut) const
Definition: network.h:511
TAIntVI(const TAIntVI &I)
Definition: network.h:1948
TEdgeI(const TNodeI &NodeI, const TNodeI &EndNodeI, const int &EdgeN=0)
Definition: network.h:606
TNodeData & GetInNDat(const int &NodeN)
Definition: network.h:104
THash< TInt, TNode > NodeH
Definition: network.h:637
void Clr()
Deletes all nodes and edges from the network.
Definition: network.h:4239
int AddEdge(const TEdgeI &EdgeI)
Adds an edge between EdgeI.GetSrcNId() and EdgeI.GetDstNId() to the network.
Definition: network.h:3650
THashIter NodeHI
Definition: network.h:61
TAttr SAttrE
Definition: network.h:2073
void DelKey(const TKey &Key)
Definition: hash.h:404
Edge iterator. Only forward iteration (operator++) is supported.
Definition: network.h:1219
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:2396
void LoadShM(TShMIn &MStream)
Definition: network.h:1106
TNodeEDatNet * Net
Definition: network.h:541
Edge iterator. Only forward iteration (operator++) is supported.
Definition: network.h:600
TUndirNet()
Definition: network.h:3534
int GetId() const
Returns ID of the current node.
Definition: network.h:1807
static const int Mn
Definition: dt.h:1141
void GetStrAttrVal(TStrV &Val) const
Gets vector of str attribute values.
Definition: network.h:1859
bool IsOutEId(const int &EId) const
Tests whether the edge with ID EId is an out-edge of current node.
Definition: network.h:1841
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:3220
TAIntI EndEAIntI(const TStr &attr) const
Returns an iterator referring to the past-the-end edge's attribute.
Definition: network.h:2644
int GetOutDeg() const
Returns out-degree of the current node.
Definition: network.h:559
TInt MxNId
Definition: network.h:1258
int GetRndNId(TRnd &Rnd=TInt::Rnd)
Returns an ID of a random node in the network.
Definition: network.h:3672
TAFltI BegNAFltI(const TStr &attr) const
Returns an iterator referring to the first node's flt attribute.
Definition: network.h:2521
TCRef CRef
Definition: network.h:142
void Clr(const bool &DoDel=true, const bool &ResetDat=true)
Deletes all nodes and edges from the network.
Definition: network.h:786
int GetOutNId(const int &NodeN) const
Definition: network.h:3417
const TNodeData & GetDat() const
Definition: network.h:101
int GetSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, TStr &ValX) const
Gets Str sparse attribute with id AttrId from EdgeI.
Definition: network.h:3317
TNEANet(const TNEANet &Graph, bool modeSubGraph)
Definition: network.h:2164
int GetSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, TInt &ValX) const
Gets Int sparse attribute with id AttrId from EdgeI.
Definition: network.h:4439
void Clr(const bool &DoDel=true, const TSizeTy &NoDelLim=-1)
Clears the contents of the vector.
Definition: ds.h:1022
Node Edge Network (directed graph, TNGraph with data on nodes and edges).
Definition: network.h:491
TVec< TFltV > VecOfFltVecsE
Definition: network.h:2065
int GetInNId(const int &NodeN) const
Returns ID of NodeN-th in-node (the node pointing to the current node).
Definition: network.h:4032
int DelSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId)
Deletes sparse attribute with id AttrId from EdgeI.
Definition: network.h:3923
TNode & GetNode(const int &NId)
Definition: network.h:632
int GetId() const
Definition: network.h:1094
TStrIntPrH KeyToIndexTypeN
KeyToIndexType[N|E]: Key->(Type,Index).
Definition: network.h:2056
TAFltI EndNAFltI(const TStr &attr) const
Returns an iterator referring to the past-the-end node's attribute.
Definition: network.h:2524
TNodeI GetNI(const int &NId) const
Returns an iterator referring to the node of ID NId in the network.
Definition: network.h:714
TNodeData & GetDstNDat()
Definition: network.h:1245
TInt GetIntAttrDatE(const TEdgeI &EdgeI, const TStr &attr)
Gets the value of int attr from the edge attr value vector.
Definition: network.h:2969
virtual void Save(TSOut &SOut) const
Saves the network to a (binary) stream SOut.
Definition: network.h:168
bool IsInNId(const int &NId) const
Tests whether node with ID NId points to the current node.
Definition: network.h:3478
void Save(TSOut &SOut) const
Saves the attributes to a (binary) stream SOut.
Definition: attr.h:118
int AddStrAttrDatN(const TNodeI &NodeI, const TStr &value, const TStr &attr)
Attribute based add function for attr to Str value.
Definition: network.h:2865
TNodeI GetNI(const int &NId) const
Returns an iterator referring to the node of ID NId in the network.
Definition: network.h:4185
int DelSAttrDatN(const TNodeI &NodeI, const TInt &AttrId)
Deletes sparse attribute with id AttrId from NodeI.
Definition: network.h:3805
void Sort(const bool &Asc=true)
Sorts the elements of the vector.
Definition: ds.h:1318
void Gen(const int &ExpectVals)
Definition: hash.h:222
TUndirNet TNet
Definition: network.h:3399
void StrAttrValueEI(const TInt &EId, TStrV &Values) const
Returns a vector of attr values for node NId.
Definition: network.h:2627
#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:1250
TEdgeI BegEI() const
Returns an iterator referring to the first edge in the network.
Definition: network.h:756
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:1920
void LoadNetworkShM(TShMIn &ShMIn)
Definition: network.h:4088
bool Empty() const
Tests whether the network is empty (has zero nodes).
Definition: network.h:784
int GetInDeg() const
Definition: network.h:3414
int GetInNId(const int &NodeN) const
Returns ID of NodeN-th in-node (the node pointing to the current node).
Definition: network.h:84
void GetIntVAttrVal(TVec< TIntV > &Val) const
Gets vector of int attribute values.
Definition: network.h:1855
void FltAttrValueEI(const TInt &EId, TFltV &Values) const
Returns a vector of attr values for node NId.
Definition: network.h:2635
TNodeI GetRndNI(TRnd &Rnd=TInt::Rnd)
Returns an interator referring to a random node in the network.
Definition: network.h:4232
TEdgeDat & GetNbrEDat(const int &EdgeN)
Definition: network.h:1213
static PNet Load(TSIn &SIn)
Static constructor that loads the network from a stream SIn and returns a pointer to it...
Definition: network.h:172
TNodeData & GetDstNDat()
Definition: network.h:134
TNodeI(const TNodeI &NodeI)
Definition: network.h:3440
void SortNIdByDat(const bool &Asc=true)
Sorts nodes by node data.
Definition: network.h:1428
int GetId() const
Gets edge ID. Always returns -1 since only edges in multigraphs have explicit IDs.
Definition: network.h:615
int GetNbrNId(const int &EdgeN) const
Returns ID of EdgeN-th neighboring node.
Definition: network.h:1825
int GetSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, TFlt &ValX) const
Gets Flt sparse attribute with name AttrName from NodeI.
Definition: network.h:3181
bool IsOutNId(const int &NId) const
Definition: network.h:3989
bool Empty() const
Tests whether the network is empty (has zero nodes).
Definition: network.h:4237
int GetNbrNId(const int &NodeN) const
Returns ID of NodeN-th neighboring node.
Definition: network.h:4040
TVec< TVec< TFltV > > VecOfFltVecVecsE
Definition: network.h:2067
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:3620
void Reserve(const int &Nodes, const int &Edges)
Reserves memory for a graph of Nodes nodes and Edges edges.
Definition: network.h:2844
int GetSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from EdgeI.
Definition: network.h:4435
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:3555
void ReserveNIdDeg(const int &NId, const int &Deg)
Reserves memory for node ID NId having Deg edges.
Definition: network.h:3685
TEdgeI & operator=(const TEdgeI &EdgeI)
Definition: network.h:608
TFltV::TIter TFltVecIter
Definition: network.h:2009
TEdgeI & operator++(int)
Increment iterator.
Definition: network.h:610
TNode & GetNode(const int &NId)
Definition: network.h:3515
int AddEdge(const int &SrcNId, const int &DstNId)
Adds an edge from node SrcNId to node DstNId to the network.
Definition: network.h:381
TEdgeI GetRndEI(TRnd &Rnd=TInt::Rnd)
Returns an interator referring to a random edge in the network.
Definition: network.h:1412
int GetSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, TStr &ValX) const
Gets Str sparse attribute with name AttrName from EdgeI.
Definition: network.h:3905
int GetDstNId() const
Gets the destination node of an edge.
Definition: network.h:132
int GetId() const
Definition: network.h:1127
static PDirNet LoadShM(TShMIn &ShMIn)
Static constructor that loads the network from memory.
Definition: network.h:4123
const TVal & GetDat(const TVal &Val) const
Returns reference to the first occurrence of element Val.
Definition: ds.h:838
int AddNode(const TNodeI &NodeId)
Adds a node of ID NodeI.GetId() to the network.
Definition: network.h:4148
TCRef CRef
Definition: network.h:2050
TNode(const TNode &Node)
Definition: network.h:3978
bool operator<(const TNode &Node) const
Definition: network.h:53
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:939
TNode(TSIn &SIn)
Definition: network.h:510
TAStrI & operator++(int)
Definition: network.h:2002
int GetSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, TFlt &ValX) const
Gets Flt sparse attribute with name AttrName from EdgeI.
Definition: network.h:3299
const TNodeData & GetDat() const
Definition: network.h:1098
TStr GetStrAttrDefaultE(const TStr &attribute) const
Gets Str edge attribute val. If not a proper attr, return default.
Definition: network.h:2046
const TNodeData & GetSrcNDat() const
Definition: network.h:133
void SortNIdById(const bool &Asc=true)
Sorts nodes by node IDs.
Definition: network.h:280
TNEANet(const int &Nodes, const int &Edges)
Constructor that reserves enough memory for a graph of nodes and edges.
Definition: network.h:2134
TAStrI(const TAStrI &I)
Definition: network.h:1994
bool IsOutNId(const int &NId) const
Tests whether the current node points to node with ID NId.
Definition: network.h:96
TNEANet()
Definition: network.h:2124
int DelSAttrDatN(const TNodeI &NodeI, const TInt &AttrId)
Deletes sparse attribute with id AttrId from NodeI.
Definition: network.h:3213
int GetMxNId() const
Returns an ID that is larger than any node ID in the network.
Definition: network.h:233
THashIter NodeHI
Definition: network.h:3436
TNodeData & GetDstNDat()
Definition: network.h:626
bool FNextKeyId(int &KeyId) const
Definition: hash.h:478
TNodeI(const THashIter &NodeHIter)
Definition: network.h:3439
THash< TStr, TStr > StrDefaultsN
Definition: network.h:2061
void AttrNameNI(const TInt &NId, TStrV &Names) const
Returns a vector of attr names for node NId.
Definition: network.h:2531
void operator()(TNode *n, TShMIn &ShMIn)
Definition: network.h:150
const TEdgeData & GetDat() const
Definition: network.h:1240
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:4075
#define Assert(Cond)
Definition: bd.h:251
TFltVVecIter HI
Definition: network.h:1961
TAIntVI EndEAIntVI(const TStr &attr) const
Returns an iterator referring to the past-the-end edge's attribute.
Definition: network.h:2670
THash< TInt, TNode > NodeH
Definition: network.h:1259
TInt MxNId
Definition: network.h:3509
TNodeNet * Net
Definition: network.h:62
TNodeI EndNode
Definition: network.h:115
void DelNode(const TNode &NodeI)
Deletes node of ID NodeI.GetId() from the graph.
Definition: network.h:2383
TNodeNet(TSIn &SIn)
Constructor that loads the network from a (binary) stream SIn.
Definition: network.h:165
bool Empty() const
Tests whether the network is empty (has zero nodes).
Definition: network.h:3679
TEdgeData & GetDat()
Definition: network.h:1241
TFlt GetFltAttrDatN(const TNodeI &NodeI, const TStr &attr)
Gets the value of flt attr from the node attr value vector.
Definition: network.h:2938
TEdgeI BegEI() const
Returns an iterator referring to the first edge in the graph.
Definition: network.h:2812
TNodeEDatNet(TSIn &SIn)
Constructor that loads the network from a (binary) stream SIn.
Definition: network.h:656
int AddSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, const TStr &Val)
Adds Str sparse attribute with name AttrName to NodeI.
Definition: network.h:3153
void SortNIdByDat(const bool &Asc=true)
Sorts nodes by node data.
Definition: network.h:793
const TNodeData & operator()() const
Definition: network.h:1185
bool IsNbrNId(const int &NId) const
Tests whether node with ID NId is a neighbor of the current node.
Definition: network.h:3482
bool IsOk(const bool &ThrowExcept=true) const
Checks the network data structure for internal consistency.
Definition: network.h:1016
TNodeEDatNet< TNodeData, TEdgeData > TNet
Definition: network.h:495
TNodeI(const TNodeI &NodeI)
Definition: network.h:4010
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:2954
void IntVAttrNameEI(const TInt &EId, TStrV &Names) const
Returns a vector of int attr names for edge EId.
Definition: network.h:2604
bool IsInNId(const int &NId) const
Definition: network.h:3420
THashIter NodeHI
Definition: network.h:540
bool IsInNId(const int &NId) const
Tests whether node with ID NId points to the current node.
Definition: network.h:94
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:2439
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:3853
TInt MxNId
Definition: network.h:143
int FFirstKeyId() const
Definition: hash.h:278
void Save(TSOut &SOut) const
Definition: network.h:3980
void FltVAttrNameNI(const TInt &NId, TStrV &Names) const
Returns a vector of flt attr names for node NId.
Definition: network.h:2559
int GetId() const
Returns edge ID. Always returns -1 since only edges in multigraphs have explicit IDs.
Definition: network.h:3500
int GetId() const
Gets edge ID. Always returns -1 since only edges in multigraphs have explicit IDs.
Definition: network.h:128
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:2399
int GetOutEId(const int &EdgeN) const
Returns ID of EdgeN-th out-edge.
Definition: network.h:1199
TPt< TUndirNet > PUndirNet
Pointer to an undirected network (TUndirNet)
Definition: network.h:3372
int AddSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to NodeI.
Definition: network.h:3717
TEdgeI EndEI() const
Returns an iterator referring to the past-the-end edge in the graph.
Definition: network.h:2814
bool HasFlag(const TGraphFlag &Flag) const
Allows for run-time checking the type of the network (see the TGraphFlag for flags).
Definition: network.h:306
TAFltVI(const TAFltVI &I)
Definition: network.h:1973
int GetInDeg() const
Returns in-degree of the current node.
Definition: network.h:1811
int GetDstNId() const
Definition: network.h:1783
TNode(const int &NId)
Definition: network.h:30
void PackOutNIdV()
Definition: network.h:3422
TFltV GetFltVAttrDatE(const TEdgeI &EdgeI, const TStr &attr)
Gets the value of the fltv attr from the edge attr value vector.
Definition: network.h:2982
TNodeI(const THashIter &NodeHIter, const TNodeEDatNet *NetPt)
Definition: network.h:544
THash< TInt, TNode >::TIter THashIter
Definition: network.h:3435
TEdge(TSIn &SIn)
Definition: network.h:1779
TNodeData & GetSrcNDat()
Definition: network.h:624
TVec< TPair< TInt, TEdgeData > > TNIdDatPrV
Definition: network.h:497
TNodeData & GetDat()
Definition: network.h:102
int AddSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, const TStr &Val)
Adds Str sparse attribute with name AttrName to NodeI.
Definition: network.h:4303
TNode(const TNode &Node)
Definition: network.h:1753
TStr GetStrAttrDefaultN(const TStr &attribute) const
Gets Str node attribute val. If not a proper attr, return default.
Definition: network.h:2040
int GetSrcNId() const
Returns the source of the edge.
Definition: network.h:1884
TEdgeData & GetDat()
Definition: network.h:1138
TNodeNet()
Definition: network.h:160
int GetInNId(const int &NodeN) const
Returns ID of NodeN-th in-node (the node pointing to the current node).
Definition: network.h:3466
const TNodeData & GetNDat(const int &NId) const
Returns node data for the node of ID NId in the network.
Definition: network.h:722
int GetRndNId(TRnd &Rnd=TInt::Rnd)
Returns an ID of a random node in the network.
Definition: network.h:777
Node iterator. Only forward iteration (operator++) is supported.
Definition: network.h:537
TVec< TVec< TIntV > > VecOfIntVecVecsE
Definition: network.h:2066
TNodeEdgeNet & operator=(const TNodeEdgeNet &Net)
Definition: network.h:1303
void LoadShM(TShMIn &MStream)
Definition: network.h:3994
void GetAttrVal(TStrV &Val) const
Gets vector of attribute values.
Definition: network.h:1890
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:3863
int GetOutNId(const int &NodeN) const
Returns ID of NodeN-th out-node (the node the current node points to).
Definition: network.h:4036
int GetDstNId() const
Returns the destination of the edge. Since the network is undirected, this is the node with a greater...
Definition: network.h:3504
TNodeI EndNI() const
Returns an iterator referring to the past-the-end node in the network.
Definition: network.h:3624
TAFltVI GetEAFltVI(const TStr &attr, const int &EId) const
Returns an iterator referring to the edge of ID EId in the graph.
Definition: network.h:2739
int AddSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, const TFlt &Val)
Adds Flt sparse attribute with name AttrName to EdgeI.
Definition: network.h:4407
TEdgeI(const TEdgeI &EdgeI)
Definition: network.h:4057
void Save_V2(TSOut &SOut) const
Saves the graph without any sparse data structures. Available for backwards compatibility.
Definition: network.h:2213
int GetRndNId(TRnd &Rnd=TInt::Rnd)
Returns an ID of a random node in the network.
Definition: network.h:266
bool IsInNId(const int &NId) const
Definition: network.h:523
int AddSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, const TStr &Val)
Adds Str sparse attribute with id AttrId to EdgeI.
Definition: network.h:3275
THash< TInt, TEdge > EdgeH
Definition: network.h:1260
TEdgeI BegEI() const
Returns an iterator referring to the first edge in the network.
Definition: network.h:4221
void SetAllEDat(const TEdgeData &EdgeDat)
Sets edge data for all the edges in the network to EDat.
Definition: network.h:1626
bool HasFlag(const TGraphFlag &Flag) const
Allows for run-time checking the type of the network (see the TGraphFlag for flags).
Definition: network.h:818
void AttrValueEI(const TInt &EId, TStrV &Values) const
Returns a vector of attr values for edge EId.
Definition: network.h:2590
int GetOutDeg() const
Returns out-degree of the current node.
Definition: network.h:1164
void SortNIdV()
Definition: network.h:3424
void FltAttrValueNI(const TInt &NId, TFltV &Values) const
Returns a vector of attr values for node NId.
Definition: network.h:2581
TInt MxNId
Definition: network.h:636
int GetSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, TStr &ValX) const
Gets Str sparse attribute with name AttrName from NodeI.
Definition: network.h:3195
Directed multigraph with node edge attributes.
Definition: network.h:1741
Definition: fl.h:128
bool operator==(const TEdgeI &EdgeI) const
Definition: network.h:126
TPt< TNEANet > PNet
Definition: network.h:1744
TEdgeData & GetOutEDat(const int &EdgeN)
Definition: network.h:590
void LoadNetworkShM(TShMIn &ShMIn)
load network from shared memory for this network
Definition: network.cpp:2
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:4111
void GetAttrNames(TStrV &Names) const
Gets vector of attribute names.
Definition: network.h:1845
int AddSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, const TStr &Val)
Adds Str sparse attribute with id AttrId to NodeI.
Definition: network.h:3157
void GetFltAttrVal(TFltV &Val) const
Gets vector of flt attribute values.
Definition: network.h:1863
bool Empty() const
Tests whether the graph is empty (has zero nodes).
Definition: network.h:2834
TNode(TSIn &SIn)
Definition: network.h:3979
TInt MxEId
Definition: network.h:2052
static PNet LoadShM(TShMIn &ShMIn)
Static constructor that loads the network from shared memory.
Definition: network.h:669
TSizeTy SearchBin(const TVal &Val) const
Returns the position of an element with value Val.
Definition: ds.h:1519
int DelSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName)
Deletes sparse attribute with name AttrName from EdgeI.
Definition: network.h:3919
TAStrI BegNAStrI(const TStr &attr) const
Returns an iterator referring to the first node's str attribute.
Definition: network.h:2511
TNodeI CurNode
Definition: network.h:4052
void GetFltAttrNames(TStrV &Names) const
Gets vector of flt attribute names.
Definition: network.h:1904
TNodeNet(const int &Nodes, const int &Edges)
Constructor that reserves enough memory for a network of Nodes nodes and Edges edges.
Definition: network.h:162
bool IsEdge(const int &EId) const
Tests whether an edge with ID EId exists in the network.
Definition: network.h:1382
bool IsDeleted() const
Returns true if the attribute has been deleted.
Definition: network.h:2001
int GetInDeg() const
Definition: network.h:1096
TStrV::TIter TStrVecIter
Definition: network.h:1986
const TNodeData & operator()() const
Definition: network.h:99
TEdgeData & GetEDat(const int &EId)
Returns edge data for the edge with ID EId.
Definition: network.h:1399
int AddNode(const TNodeI &NodeI)
Adds a node NodeI and its node data to the network.
Definition: network.h:209
int GetId() const
Definition: network.h:3412
int GetSrcNId() const
Gets the source of an edge.
Definition: network.h:1235
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:4189
int GetSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, TFlt &ValX) const
Gets Flt sparse attribute with id AttrId from NodeI.
Definition: network.h:3185
bool IsInEId(const int &EId) const
Definition: network.h:1763
int AddSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to EdgeI.
Definition: network.h:4393
void SortByKey(const bool &Asc=true)
Definition: hash.h:291
void SetEDat(const int &EId, const TEdgeData &EdgeDat)
Sets edge data for the edge of ID NId in the network.
Definition: network.h:1620
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:401
Definition: dt.h:1137
void LoadShM(TShMIn &MStream)
Definition: network.h:1765
TVal * TIter
Random access iterator to TVal.
Definition: ds.h:432
TEdge & GetEdge(const int &EId)
Definition: network.h:2032
int GetOutDeg() const
Definition: network.h:1759
int GetNbrNId(const int &NodeN) const
Returns ID of NodeN-th neighboring node.
Definition: network.h:92
const TNode & GetNode(const int &NId) const
Definition: network.h:3516
TAIntVI BegEAIntVI(const TStr &attr) const
Returns an iterator referring to the first edge's int attribute.
Definition: network.h:2653
void FltVAttrValueEI(const TInt &EId, TVec< TFltV > &Values) const
Returns a vector of attr values for edge EId.
Definition: network.h:2617
int GetNbrNId(const int &EdgeN) const
Definition: network.h:520
void LoadShM(TShMIn &MStream)
Definition: network.h:47
void DelNode(const TNode &NodeI)
Deletes node of ID NodeI.GetId() from the network.
Definition: network.h:215
TNodeI GetRndNI(TRnd &Rnd=TInt::Rnd)
Returns an interator referring to a random node in the graph.
Definition: network.h:2823
int GetEId(const int &SrcNId, const int &DstNId) const
Definition: network.h:1387
int GetDeg() const
Definition: network.h:3413
int GetId() const
Returns ID of the current node.
Definition: network.h:74
int GetKeyId(const TKey &Key) const
Definition: hash.h:466
THash< TInt, TEdge >::TIter THashIter
Definition: network.h:1221
Edge iterator. Only forward iteration (operator++) is supported.
Definition: network.h:4050
void IntAttrValueNI(const TInt &NId, TIntV &Values) const
Returns a vector of attr values for node NId.
Definition: network.h:2544
TNodeI EndNI() const
Returns an iterator referring to the past-the-end node in the graph.
Definition: network.h:2389
int GetSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, TStr &ValX) const
Gets Str sparse attribute with id AttrId from NodeI.
Definition: network.h:4349
void LoadNetworkShM(TShMIn &ShMIn)
Definition: network.h:645
int GetRndNId(TRnd &Rnd=TInt::Rnd)
Returns an ID of a random node in the network.
Definition: network.h:1406
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:2687
bool IsNbrNId(const int &NId) const
Definition: network.h:3419
TUndirNet(const TUndirNet &Graph)
Definition: network.h:3537
void GetIntAttrNames(TStrV &Names) const
Gets vector of int attribute names.
Definition: network.h:1849
const TNodeData & GetOutNDat(const int &NodeN) const
Definition: network.h:105
const TEdgeData & operator()() const
Definition: network.h:1238
int GetId() const
Gets edge ID.
Definition: network.h:1233
const TEdgeDat & GetNbrEDat(const int &EdgeN) const
Definition: network.h:1214
TNode(const int &NId)
Definition: network.h:1752
void LoadShM(TShMIn &ShMIn)
Constructs the vector from a shared memory input.
Definition: ds.h:932
int GetId() const
Definition: network.h:3981
TUndirNet(const int &Nodes, const int &Edges)
Constructor that reserves enough memory for a network of Nodes nodes and Edges edges.
Definition: network.h:3536
TNodeNet< TInt > TIntNNet
Definition: network.h:481
TNodeNet< TFlt > TFltNNet
Definition: network.h:483
TFltV GetDat() const
Returns an attribute of the node.
Definition: network.h:1978
TNodeData & GetDat()
Definition: network.h:582
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:4370
int AddNode(int NId=-1)
Adds a node of ID NId to the network.
Definition: network.h:311
TNodeI EndNode
Definition: network.h:4052
Edge iterator. Only forward iteration (operator++) is supported.
Definition: network.h:1867
TNode(const TNode &Node)
Definition: network.h:32
static PNEANet Load_V2(TSIn &SIn)
Static constructor that loads the graph from a stream SIn and returns a pointer to it...
Definition: network.h:2249
int DelAttrDatE(const TEdgeI &EdgeI, const TStr &attr)
Deletes the edge attribute for NodeI.
Definition: network.h:3009
void Reserve(const int &Nodes, const int &Edges)
Reserves memory for a network of Nodes nodes and Edges edges.
Definition: network.h:789
TNode(const int &NId)
Definition: network.h:507
int Len() const
Definition: shash.h:1121
int GetNodes() const
Returns the number of nodes in the network.
Definition: network.h:3576
TNode(const TNode &Node)
Definition: network.h:1090
TPt< TStrNNet > PStrNNet
Definition: network.h:486
void SortEIdById(const bool &Asc=true)
Sorts edges by edge IDs.
Definition: network.h:1430
TVec< THash< TInt, TFltV > > VecOfFltHashVecsE
Definition: network.h:2069
bool IsOutNId(const int &NId) const
Tests whether the current node points to node with ID NId.
Definition: network.h:1473
THash< TInt, TEdge >::TIter THashIter
Definition: network.h:1869
void FltAttrNameEI(const TInt &EId, TStrV &Names) const
Returns a vector of int attr names for node NId.
Definition: network.h:2631
int AddNode(const TNodeI &NodeI)
Adds a node of ID NodeI.GetId() to the network.
Definition: network.h:3590
TNode(const int &NId)
Definition: network.h:1088
TNodeEdgeNet(TSIn &SIn)
Constructor that loads the network from a (binary) stream SIn.
Definition: network.h:1281
TNodeI BegNI() const
Returns an iterator referring to the first node in the network.
Definition: network.h:710
TNodeData TNodeDat
Definition: network.h:493
void Clr()
Deletes all nodes and edges from the network.
Definition: network.h:3681
TEdgeData TEdgeDat
Definition: network.h:1077
TNodeEdgeNet< TNodeData, TEdgeData > TNet
Definition: network.h:1078
void FltVAttrValueNI(const TInt &NId, TVec< TFltV > &Values) const
Returns a vector of flt values for node NId.
Definition: network.h:2563
int GetId() const
Definition: network.h:35
bool operator<(const TEdgeI &EdgeI) const
Definition: network.h:1230
THash< TStr, TStr > StrDefaultsE
Definition: network.h:2061
const TEdgeData & GetDat() const
Definition: network.h:623
int GetOutDeg() const
Definition: network.h:515
int GetInEId(const int &NodeN) const
Definition: network.h:1100
void Clr()
Clears the contents of the attribute map.
Definition: attr.h:122
void SetNDat(const int &NId, const TNodeData &NodeDat)
Sets node data for the node of ID NId in the network.
Definition: network.h:872
TNodeI GetNI(const int &NId) const
Returns an iterator referring to the node of ID NId in the network.
Definition: network.h:1342
const TNode & GetNodeKId(const int &NodeKeyId) const
Definition: network.h:1252
const TNodeData & GetSrcNDat() const
Definition: network.h:1242
void StrAttrNameEI(const TInt &EId, TStrV &Names) const
Returns a vector of str attr names for node NId.
Definition: network.h:2623
TFlt GetFltAttrDefaultE(const TStr &attribute) const
Gets Flt edge attribute val. If not a proper attr, return default.
Definition: network.h:2048
void Load(TSIn &InStream)
Definition: network.h:1130
void ConvertToSparse()
Definition: network.h:2279
int GetEdges() const
Returns the number of edges in the graph.
Definition: network.h:2785
void Save(TSOut &SOut) const
Definition: network.h:1780
TNodeI GetRndNI(TRnd &Rnd=TInt::Rnd)
Returns an interator referring to a random node in the network.
Definition: network.h:3674
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:4115
Undirected network.
Definition: network.h:3397
TNodeNet< TStr > TStrNNet
Definition: network.h:485
int GetOutEId(const int &EdgeN) const
Definition: network.h:1761
THashIter NodeHI
Definition: network.h:1146
int GetInDeg() const
Returns in-degree of the current node.
Definition: network.h:1162
TNodeI CurNode
Definition: network.h:115
void Save(TSOut &SOut) const
Saves the graph to a (binary) stream SOut. Expects data structures for sparse attributes.
Definition: network.h:2187
TAttrPair SAttrE
Definition: network.h:3513
void GetEIdV(TIntV &EIdV) const
Returns a vector of all edge IDs in the network.
Definition: network.h:1642
bool IsInEId(const int &EId) const
Definition: network.h:1103
TEdgeI(const TEdgeI &EdgeI)
Definition: network.h:1227
int GetDstNId() const
Returns the destination node of the edge.
Definition: network.h:4069
TAIntVI BegNAIntVI(const TStr &attr) const
Returns an iterator referring to the first node's int attribute.
Definition: network.h:2403
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:2903
TDirNet()
Definition: network.h:4096
void GetAttrVal(TStrV &Val) const
Gets vector of attribute values.
Definition: network.h:1847
const TEdgeDat & GetInEDat(const int &EdgeN) const
Definition: network.h:1210
const TNodeData & GetDstNDat() const
Definition: network.h:627
TNodeNet & operator=(const TNodeNet &NodeNet)
Definition: network.h:185
const TNodeData & GetNbrNDat(const int &NodeN) const
Definition: network.h:107
TNEANet(const TNEANet &Graph)
Definition: network.h:2144
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:2234
TEdgeI(const TEdgeI &EdgeI)
Definition: network.h:1875
TIter BegI() const
Returns an iterator pointing to the first element in the vector.
Definition: ds.h:593
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:33
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:1323
void Pack()
Reduces vector capacity (frees memory) to match its size.
Definition: ds.h:1057
static PNet New()
Static constructor that returns a pointer to the network.
Definition: network.h:1288
void DelEdge(const int &EId)
Deletes an edge with ID EId from the network.
Definition: network.h:1581
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:3327
TPt< TIntNNet > PIntNNet
Definition: network.h:482
void operator()(TNode *n, TShMIn &ShMIn)
Definition: network.h:642
int GetOutNId(const int &NodeN) const
Returns ID of NodeN-th out-node (the node the current node points to).
Definition: network.h:88
bool operator<(const TEdge &Edge) const
Definition: network.h:1126
TNodeEdgeNet * Net
Definition: network.h:1147
int GetOutDeg() const
Returns out-degree of the current node.
Definition: network.h:4026
TNode(TSIn &SIn)
Definition: network.h:1754
const TNode & GetNode(const int &NId) const
Definition: network.h:2031
int GetOutNId(const int &NodeN) const
Returns ID of NodeN-th out-node (the node the current node points to).
Definition: network.h:567
int GetSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, TStr &ValX) const
Gets Str sparse attribute with id AttrId from NodeI.
Definition: network.h:3791
int AddFltVAttrDatN(const TNodeI &NodeI, const TFltV &value, const TStr &attr)
Attribute based add function for attr to FltV value.
Definition: network.h:2874
int GetMxEId() const
Returns an ID that is larger than any edge ID in the network.
Definition: network.h:2782
int GetSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, TStr &ValX) const
Gets Str sparse attribute with name AttrName from NodeI.
Definition: network.h:4345
Definition: hash.h:97
int GetEdges() const
Returns the number of edges in the network.
Definition: network.h:1354
TAttr SAttrN
Definition: network.h:3512
int GetInDeg() const
Definition: network.h:37
int GetNbrEId(const int &EdgeN) const
Returns ID of EdgeN-th in or out-edge.
Definition: network.h:1837
int DelSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId)
Deletes sparse attribute with id AttrId from EdgeI.
Definition: network.h:4481
TAIntI & operator++(int)
Definition: network.h:1929
const TEdgeData & GetDat() const
Definition: network.h:1137
int GetDeg() const
Definition: network.h:1757
int AddSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, const TFlt &Val)
Adds Flt sparse attribute with id AttrId to NodeI.
Definition: network.h:3143
int AddSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, const TFlt &Val)
Adds Flt sparse attribute with id AttrId to EdgeI.
Definition: network.h:3261
TVec< TFltV > VecOfFltVecsN
Definition: network.h:2065
int GetSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from NodeI.
Definition: network.h:4317
int GetInDeg() const
Definition: network.h:1758
TAFltI EndEAFltI(const TStr &attr) const
Returns an iterator referring to the past-the-end edge's attribute.
Definition: network.h:2772
TIntV::TIter TIntVecIter
Definition: network.h:1913
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:2527
#define EAssertR(Cond, MsgStr)
Definition: bd.h:283
int AddSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, const TFlt &Val)
Adds Flt sparse attribute with name AttrName to EdgeI.
Definition: network.h:3849
bool HasFlag(const TGraphFlag &Flag) const
Allows for run-time checking the type of the network (see the TGraphFlag for flags).
Definition: network.h:1458
void Clr()
Deletes all nodes and edges from the graph.
Definition: network.h:2836
void Clr(const bool &DoDel=true, const bool &ResetDat=true)
Deletes all nodes and edges from the network.
Definition: network.h:275
TEdgeData & GetNbrEDat(const int &EdgeN)
Definition: network.h:594
void Save(TSOut &SOut) const
Definition: network.h:3411
void operator()(TNode *n, TShMIn &ShMIn)
Definition: network.h:1265
int GetId() const
Definition: network.h:1756
TVec< THash< TInt, TIntV > > VecOfIntHashVecsN
Definition: network.h:2068
const TNodeData & GetNbrNDat(const int &EdgeN) const
Definition: network.h:1193
TCRef CRef
Definition: network.h:3508
int GetDeg() const
Definition: network.h:513
int AddSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, const TStr &Val)
Adds Str sparse attribute with name AttrName to EdgeI.
Definition: network.h:4421
TNodeData NodeDat
Definition: network.h:502
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:2810
TNodeI GetNI(const int &NId) const
Returns an iterator referring to the node of ID NId in the network.
Definition: network.h:3626
bool Empty() const
Tests whether the network is empty (has zero nodes).
Definition: network.h:1419
virtual ~TNodeNet()
Definition: network.h:166
bool IsNbrNId(const int &NId) const
Tests whether node with ID NId is a neighbor of the current node.
Definition: network.h:577
int AddSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, const TStr &Val)
Adds Str sparse attribute with name AttrName to NodeI.
Definition: network.h:3745
void GetIntVAttrNames(TStrV &Names) const
Gets vector of int attribute names.
Definition: network.h:1853
const TNodeData & GetOutNDat(const int &NodeN) const
Definition: network.h:583
TVal1 Val1
Definition: ds.h:34
void DelNode(const TNode &NodeI)
Deletes node of ID NodeI.GetId() from the network.
Definition: network.h:1334
TEdgeI GetEI(const int &SrcNId, const int &DstNId) const
Returns an iterator referring to edge (SrcNId, DstNId) in the graph.
Definition: network.h:1395
TVal2 Val2
Definition: ds.h:35
void Clr(const bool &DoDel=true, const int &NoDelLim=-1, const bool &ResetDat=true)
Definition: hash.h:361
TIntPr OrderEdgeNodes(const int &SrcNId, const int &DstNId) const
Definition: network.cpp:2468
bool IsInEId(const int &EId) const
Tests whether the edge with ID EId is an in-edge of current node.
Definition: network.h:1203
bool operator<(const TNode &Node) const
Definition: network.h:532
int GetSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, TFlt &ValX) const
Gets Flt sparse attribute with id AttrId from EdgeI.
Definition: network.h:3303
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:746
void GetNIdV(TIntV &NIdV) const
Gets a vector IDs of all nodes in the network.
Definition: network.h:408
THash< TStr, TInt > IntDefaultsN
Definition: network.h:2060
int GetDstNId() const
Definition: network.h:1129
TNodeI(const THashIter &NodeHIter, const TNEANet *GraphPt)
Definition: network.h:1799
TNode(const int &NId)
Definition: network.h:3408
TAIntVI(const TIntVVecIter &HIter, const TIntHVecIter &HHIter, TStr attribute, bool isEdgeIter, const TNEANet *GraphPt, bool is_dense)
Definition: network.h:1945
TNodeEdgeNet * Net
Definition: network.h:1223
TIntV OutNIdV
Definition: network.h:3974
const TNode & GetNode(const int &NId) const
Returns node element for the node of ID NId in the network.
Definition: network.h:716
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:2385
int GetNodes() const
Returns the number of nodes in the network.
Definition: network.h:4134
int GetRndNId(TRnd &Rnd=TInt::Rnd)
Returns an ID of a random node in the network.
Definition: network.h:4230
bool IsInNId(const int &NId) const
Tests whether node with ID NId points to the current node.
Definition: network.h:4042
int GetOutNId(const int &NodeN) const
Returns ID of NodeN-th out-node (the node the current node points to).
Definition: network.h:3471
const TNEANet * Graph
Definition: network.h:2013
void Defrag(const bool &OnlyNodeLinks=false)
Defragments the network.
Definition: network.h:423
void Defrag(const bool &OnlyNodeLinks=false)
Defragments the network.
Definition: network.h:1005
void DelNode(const int &NId)
Deletes node of ID NId from the network.
Definition: network.h:1519
int GetOutDeg() const
Returns out-degree of the current node.
Definition: network.h:80
THash< TInt, TNode > NodeH
Definition: network.h:2053
int AppendIntVAttrDatE(const TEdgeI &EdgeI, const TInt &value, const TStr &attr)
Appends value onto the TIntV attribute for the given node.
Definition: network.h:2918
int GetSrcNId() const
Definition: network.h:1128
int GetSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, TInt &ValX) const
Gets Int sparse attribute with id AttrId from NodeI.
Definition: network.h:3171
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:444
bool IsNbrNId(const int &NId) const
Tests whether node with ID NId is a neighbor of the current node.
Definition: network.h:1183
static PDirNet New()
Static constructor that returns a pointer to the network. Call: PDirNet Graph = TDirNet::New().
Definition: network.h:4107
TEdge & GetEdge(const int &EId)
Definition: network.h:1253
TAFltVI GetNAFltVI(const TStr &attr, const int &NId) const
Returns an iterator referring to the node of ID NId in the graph.
Definition: network.h:2493
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
Definition: ds.h:523
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:3812
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:3502
TEdgeI & operator=(const TEdgeI &EdgeI)
Definition: network.h:1228
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:2964
int GetDstNId() const
Gets the destination node of an edge.
Definition: network.h:619
TDirNet(TSIn &SIn)
Constructor that loads the network from a (binary) stream SIn.
Definition: network.h:4101
TEdgeI & operator=(const TEdgeI &EdgeI)
Definition: network.h:121
TPt< TNet > PNet
Definition: network.h:1079
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:1207
TNodeI BegNI() const
Returns an iterator referring to the first node in the graph.
Definition: network.h:2387
void GetNIdV(TIntV &NIdV) const
Gets a vector IDs of all nodes in the network.
Definition: network.h:998
TVec< TVec< TIntV > > VecOfIntVecVecsN
Definition: network.h:2066
int GetInDeg() const
Definition: network.h:514
THashIter EdgeHI
Definition: network.h:1870
TEdgeI BegEI() const
Returns an iterator referring to the first edge in the network.
Definition: network.h:257
int AddSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, const TInt &Val)
Adds Int sparse attribute with id AttrId to NodeI.
Definition: network.h:3721
int AddSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, const TStr &Val)
Adds Str sparse attribute with name AttrName to EdgeI.
Definition: network.h:3271
void Reserve(const TSizeTy &_MxVals)
Reserves enough memory for the vector to store _MxVals elements.
Definition: ds.h:543
int GetSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from EdgeI.
Definition: network.h:3285
TEdge(const int &EId, const int &SourceNId, const int &DestNId)
Definition: network.h:1777
TNodeI GetNI(const int &NId) const
Returns an iterator referring to the node of ID NId in the graph.
Definition: network.h:2391
TNodeI EndNI() const
Returns an iterator referring to the past-the-end node in the network.
Definition: network.h:712
const TEdgeData & GetOutEDat(const int &EdgeN) const
Definition: network.h:591
int DelFromFltVAttrDatN(const TNodeI &NodeI, const TFlt &value, const TStr &attr)
Deletes value from the TFltV attribute for the given node.
Definition: network.h:2890
TFlt GetFltAttrDefaultN(const TStr &attribute) const
Gets Flt node attribute val. If not a proper attr, return default.
Definition: network.h:2042
bool IsInNId(const int &NId) const
Tests whether node with ID NId points to the current node.
Definition: network.h:1463
int GetInEId(const int &EdgeN) const
Definition: network.h:1760
TEdgeI EndEI() const
Returns an iterator referring to the past-the-end edge in the network.
Definition: network.h:3662
int AddSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, const TFlt &Val)
Adds Flt sparse attribute with id AttrId to NodeI.
Definition: network.h:4293
void IntAttrNameEI(const TInt &EId, TStrV &Names) const
Returns a vector of int attr names for edge EId.
Definition: network.h:2594
int GetSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, TFlt &ValX) const
Gets Flt sparse attribute with name AttrName from EdgeI.
Definition: network.h:3891
TEdgeData & GetDat()
Definition: network.h:622
TNodeI BegNI() const
Returns an iterator referring to the first node in the network.
Definition: network.h:4181
void GetIntAttrNames(TStrV &Names) const
Gets vector of int attribute names.
Definition: network.h:1892
void Reserve(const int &Nodes, const int &Edges)
Reserves memory for a network of Nodes nodes and Edges edges.
Definition: network.h:278
TNodeI & operator=(const TNodeI &NodeI)
Definition: network.h:546
TInt GetIntAttrDefaultN(const TStr &attribute) const
Gets Int node attribute val. If not a proper attr, return default.
Definition: network.h:2038
TAStrI(const TStrVecIter &HIter, TStr attribute, bool isEdgeIter, const TNEANet *GraphPt)
Definition: network.h:1993
void Load(TSIn &SIn)
Load attribute from input stream.
Definition: attr.h:25
TNodeEdgeNet< TInt, TInt > TIntNENet
Definition: network.h:1715
int GetOutDeg() const
Definition: network.h:3415
static PNet Load(TSIn &SIn)
Static constructor that loads the network from a stream SIn and returns a pointer to it...
Definition: network.h:663
TInt MxNId
Definition: network.h:4074
bool IsOk(const bool &ThrowExcept=true) const
Checks the network data structure for internal consistency.
Definition: network.h:433
int GetInNId(const int &NodeN) const
Definition: network.h:3985
TIntVecIter HI
Definition: network.h:1914
void DelNode(const TNode &NodeI)
Deletes node of ID NodeI.GetId() from the network.
Definition: network.h:4177
char * CStr()
Definition: dt.h:479
bool IsOutNId(const int &NId) const
Definition: network.h:3421
TDirNet(const int &Nodes, const int &Edges)
Constructor that reserves enough memory for a network of Nodes nodes and Edges edges.
Definition: network.h:4098
TNodeData & GetNbrNDat(const int &NodeN)
Definition: network.h:108
int GetInDeg() const
Returns in-degree of the current node (returns same as value GetDeg() since the network is undirected...
Definition: network.h:3457
Node iterator. Only forward iteration (operator++) is supported.
Definition: network.h:58
int GetSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, TStr &ValX) const
Gets Str sparse attribute with name AttrName from NodeI.
Definition: network.h:3787
THashIter NodeHI
Definition: network.h:1795
int DelSAttrDatN(const TNodeI &NodeI, const TStr &AttrName)
Deletes sparse attribute with name AttrName from NodeI.
Definition: network.h:3209
int AddSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, const TFlt &Val)
Adds Flt sparse attribute with name AttrName to NodeI.
Definition: network.h:4289
TPt< TNEANet > PNEANet
Pointer to a directed attribute multigraph (TNEANet)
Definition: network.h:1720
bool IsKey(const TKey &Key) const
Definition: hash.h:258
TIntV GetDat() const
Returns an attribute of the node.
Definition: network.h:1953
static PDirNet Load(TSIn &SIn)
Static constructor that loads the network from a stream SIn and returns a pointer to it...
Definition: network.h:4113
int AddAttributes(const int NId)
Definition: network.cpp:559
TNEANet TNet
Definition: network.h:1743
const TEdge & GetEdge(const int &EId) const
Definition: network.h:2033
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:602
int GetSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, TInt &ValX) const
Gets Int sparse attribute with id AttrId from EdgeI.
Definition: network.h:3289
Definition: dt.h:974
static PNEANet New()
Static cons returns pointer to graph. Ex: PNEANet Graph=TNEANet::New().
Definition: network.h:2226
void GetFltAttrNames(TStrV &Names) const
Gets vector of flt attribute names.
Definition: network.h:1861
bool IsOk(const bool &ThrowExcept=true) const
Checks the network data structure for internal consistency.
Definition: network.h:1660
static PNet LoadShM(TShMIn &ShMIn)
Static constructor that loads the network from memory.
Definition: network.h:1296
int AddNodeUnchecked(int NId=-1)
Adds a node of ID NId to the network, noop if the node already exists.
Definition: network.h:323
TIntV OutNIdV
Definition: network.h:27
TInt NEdges
Definition: network.h:3509
TAIntVI & operator++(int)
Definition: network.h:1954
TNodeI(const TNodeI &NodeI)
Definition: network.h:1151
int GetSrcNId() const
Returns the source node of the edge.
Definition: network.h:4067
int Len() const
Definition: hash.h:228
TIntVVecIter HI
Definition: network.h:1936
TNodeData & GetOutNDat(const int &NodeN)
Definition: network.h:584
int DelAttrDatN(const TNodeI &NodeI, const TStr &attr)
Deletes the node attribute for NodeI.
Definition: network.h:3006
int GetDeg() const
Returns degree of the current node, the sum of in-degree and out-degree.
Definition: network.h:1160
TIter GetI(const TSizeTy &ValN) const
Returns an iterator an element at position ValN.
Definition: ds.h:597
void GetStrAttrNames(TStrV &Names) const
Gets vector of str attribute names.
Definition: network.h:1857
TNEANet(bool copyAll, const TNEANet &Graph)
Definition: network.h:2174
int GetOutDeg() const
Definition: network.h:3984
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:1384
TDat & AddDat(const TKey &Key)
Definition: hash.h:238
TEdgeI EndEI() const
Returns an iterator referring to the past-the-end edge in the network.
Definition: network.h:1391
bool operator==(const TNodeI &NodeI) const
Definition: network.h:550
THashIter NodeHI
Definition: network.h:4006
TEdgeDat & GetInEDat(const int &EdgeN)
Definition: network.h:1209
int GetSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from NodeI.
Definition: network.h:3167
TFltV GetFltVAttrDatN(const TNodeI &NodeI, const TStr &attr) const
Gets the value of the fltv attr from the node attr value vector.
Definition: network.h:2945
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:3337
Node/edge string attribute iterator. Iterates through all nodes/edges for one string attribute...
Definition: network.h:1984
bool operator<(const TNodeI &NodeI) const
Definition: network.h:549
void SortNodeAdjV()
Sorts the adjacency lists of each node.
Definition: network.h:4247
void GetAttrNames(TStrV &Names) const
Gets vector of attribute names.
Definition: network.h:1888
Node iterator. Only forward iteration (operator++) is supported.
Definition: network.h:1143
TAFltVI EndEAFltVI(const TStr &attr) const
Returns an iterator referring to the past-the-end edge's attribute.
Definition: network.h:2722
int AddIntAttrDatN(const TNodeI &NodeI, const TInt &value, const TStr &attr)
Attribute based add function for attr to Int value.
Definition: network.h:2862
void GetIntAttrVal(TIntV &Val) const
Gets vector of int attribute values.
Definition: network.h:1894
int AddSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to NodeI.
Definition: network.h:4275
int AddSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, const TStr &Val)
Adds Str sparse attribute with id AttrId to EdgeI.
Definition: network.h:4425
void GetIntVAttrVal(TVec< TIntV > &Val) const
Gets vector of int attribute values.
Definition: network.h:1898
TAFltI(const TFltVecIter &HIter, TStr attribute, bool isEdgeIter, const TNEANet *GraphPt)
Definition: network.h:2016
const TNEANet * Graph
Definition: network.h:1917
void Save(TSOut &SOut) const
Definition: network.h:1125
TAIntI(const TAIntI &I)
Definition: network.h:1921
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:2959
THash< TInt, TNode >::TIter THashIter
Definition: network.h:60
TEdgeI(const TNodeI &NodeI, const TNodeI &EndNodeI, const int &EdgeN=0)
Definition: network.h:3492
TNodeI EndNI() const
Returns an iterator referring to the past-the-end node in the network.
Definition: network.h:1340
void GetIntAttrVal(TIntV &Val) const
Gets vector of int attribute values.
Definition: network.h:1851
TNIdDatPrV OutNIdV
Definition: network.h:504
TNodeI EndNI() const
Returns an iterator referring to the past-the-end node in the network.
Definition: network.h:4183
void SortNIdV()
Sorts the adjacency lists of the current node.
Definition: network.h:3461
Node iterator. Only forward iteration (operator++) is supported.
Definition: network.h:3433
const TNEANet * Graph
Definition: network.h:1990
int GetOutEId(const int &NodeN) const
Definition: network.h:1101
THash< TStr, TBool > KeyToDenseN
KeyToDense[N|E]: Key->(True if Vec, False if Hash)
Definition: network.h:2058
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:2230
int GetRndEId(TRnd &Rnd=TInt::Rnd)
Returns an ID of a random edge in the network.
Definition: network.h:1410
void Clr()
Clears the contents of the attribute map.
Definition: attr.h:37
const TKey & GetKey(const int &KeyId) const
Definition: hash.h:252
int AddSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, const TStr &Val)
Adds Str sparse attribute with id AttrId to NodeI.
Definition: network.h:4307
int GetMxNId() const
Returns an ID that is larger than any node ID in the network.
Definition: network.h:2780
THash< TInt, TNode >::TIter THashIter
Definition: network.h:1145
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:1158
int AddSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, const TInt &Val)
Adds Int sparse attribute with id AttrId to EdgeI.
Definition: network.h:3247
int GetDeg() const
Returns degree of the current node.
Definition: network.h:555
const TEdgeData & GetEDat(const int &EId) const
Returns edge data for the edge with ID EId.
Definition: network.h:1401
TNodeEDatNet< TStr, TInt > TStrIntNEDNet
Definition: network.h:1068
int GetId() const
Returns ID of the current node.
Definition: network.h:4020
TEdgeI BegEI() const
Returns an iterator referring to the first edge in the network.
Definition: network.h:3660
TUndirNet(TSIn &SIn)
Constructor that loads the network from a (binary) stream SIn.
Definition: network.h:3540
const TEdgeData & GetNbrEDat(const int &EdgeN) const
Definition: network.h:595
int GetId() const
Returns ID of the current node.
Definition: network.h:553
const TNodeData & GetDstNDat() const
Definition: network.h:1244
const TNodeData & GetDat() const
Definition: network.h:581
TNode(const int &NId, const TNodeData &NodeData)
Definition: network.h:31
int GetDstNId() const
Gets destination of an edge.
Definition: network.h:1237
TIntHVecIter HHI
Definition: network.h:1939
static const double Mn
Definition: dt.h:1390
int AddSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, const TFlt &Val)
Adds Flt sparse attribute with id AttrId to NodeI.
Definition: network.h:3735
TNodeEDatNet()
Definition: network.h:651
int GetNbrNId(const int &NodeN) const
Definition: network.h:43
void GetIntVAttrNames(TStrV &Names) const
Gets vector of int attribute names.
Definition: network.h:1896
bool operator==(const TNodeI &NodeI) const
Definition: network.h:1156
TPt< TDirNet > PDirNet
Pointer to a directed network (TDirNet)
Definition: network.h:3379
TFltHVecIter HHI
Definition: network.h:1964
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:1290
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:2996
TAFltVI(const TFltVVecIter &HIter, const TFltHVecIter &HHIter, TStr attribute, bool isEdgeIter, const TNEANet *GraphPt, bool is_dense)
Definition: network.h:1970
TNodeEdgeNet(const int &Nodes, const int &Edges)
Constructor that reserves enough memory for a network of Nodes nodes and Edges edges.
Definition: network.h:1278
int GetNodes() const
Returns the number of nodes in the network.
Definition: network.h:680
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:2991
TNodeI GetRndNI(TRnd &Rnd=TInt::Rnd)
Returns an interator referring to a random node in the network.
Definition: network.h:779
TIter GetI(const TKey &Key) const
Definition: hash.h:220
void SortByDat(const bool &Asc=true)
Definition: hash.h:292
TPt< TFltNENet > PFltNENet
Definition: network.h:1718
Implements a single CrossNet consisting of edges between two TModeNets (could be the same TModeNet) ...
Definition: mmnet.h:133
int GetMxNId() const
Returns an ID that is larger than any node ID in the network.
Definition: network.h:724
void Save_V1(TSOut &SOut) const
Saves the network to a (binary) stream SOut. Available for backwards compatibility.
Definition: network.h:3545
TNodeData & GetSrcNDat()
Definition: network.h:1243
TEdgeI EndEI() const
Returns an iterator referring to the past-the-end edge in the network.
Definition: network.h:259