SNAP Library 6.0, User Reference  2020-12-09 16:24:20
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
networkmp.h
Go to the documentation of this file.
1 #ifndef NETWORKMP_H
2 #define NETWORKMP_H
3 
4 #ifdef GCC_ATOMIC
5 
6 class TNEANetMP;
9 
10 //#//////////////////////////////////////////////
12 
27 class TNEANetMP {
28 public:
29  typedef TNEANetMP TNet;
31 public:
32  class TNode {
33  private:
36  public:
37  TNode() : Id(-1), InEIdV(), OutEIdV() { }
38  TNode(const int& NId) : Id(NId), InEIdV(), OutEIdV() { }
39  TNode(const TNode& Node) : Id(Node.Id), InEIdV(Node.InEIdV), OutEIdV(Node.OutEIdV) { }
40  TNode(TSIn& SIn) : Id(SIn), InEIdV(SIn), OutEIdV(SIn) { }
41  void Save(TSOut& SOut) const { Id.Save(SOut); InEIdV.Save(SOut); OutEIdV.Save(SOut); }
42  int GetId() const { return Id; }
43  int GetDeg() const { return GetInDeg() + GetOutDeg(); }
44  int GetInDeg() const { return InEIdV.Len(); }
45  int GetOutDeg() const { return OutEIdV.Len(); }
46  int GetInEId(const int& EdgeN) const { return InEIdV[EdgeN]; }
47  int GetOutEId(const int& EdgeN) const { return OutEIdV[EdgeN]; }
48  int GetNbrEId(const int& EdgeN) const { return EdgeN<GetOutDeg()?GetOutEId(EdgeN):GetInEId(EdgeN-GetOutDeg()); }
49  bool IsInEId(const int& EId) const { return InEIdV.SearchBin(EId) != -1; }
50  bool IsOutEId(const int& EId) const { return OutEIdV.SearchBin(EId) != -1; }
51  friend class TNEANetMP;
52  };
53  class TEdge {
54  private:
56  public:
57  TEdge() : Id(-1), SrcNId(-1), DstNId(-1) { }
58  TEdge(const int& EId, const int& SourceNId, const int& DestNId) : Id(EId), SrcNId(SourceNId), DstNId(DestNId) { }
59  TEdge(const TEdge& Edge) : Id(Edge.Id), SrcNId(Edge.SrcNId), DstNId(Edge.DstNId) { }
60  TEdge(TSIn& SIn) : Id(SIn), SrcNId(SIn), DstNId(SIn) { }
61  void Save(TSOut& SOut) const { Id.Save(SOut); SrcNId.Save(SOut); DstNId.Save(SOut); }
62  int GetId() const { return Id; }
63  int GetSrcNId() const { return SrcNId; }
64  int GetDstNId() const { return DstNId; }
65  friend class TNEANetMP;
66  };
68  class TNodeI {
69  private:
71  THashIter NodeHI;
72  const TNEANetMP *Graph;
73  public:
74  TNodeI() : NodeHI(), Graph(NULL) { }
75  TNodeI(const THashIter& NodeHIter, const TNEANetMP* GraphPt) : NodeHI(NodeHIter), Graph(GraphPt) { }
76  TNodeI(const TNodeI& NodeI) : NodeHI(NodeI.NodeHI), Graph(NodeI.Graph) { }
77  TNodeI& operator = (const TNodeI& NodeI) { NodeHI = NodeI.NodeHI; Graph=NodeI.Graph; return *this; }
79  TNodeI& operator++ (int) { NodeHI++; return *this; }
80  bool operator < (const TNodeI& NodeI) const { return NodeHI < NodeI.NodeHI; }
81  bool operator == (const TNodeI& NodeI) const { return NodeHI == NodeI.NodeHI; }
83  int GetId() const { return NodeHI.GetDat().GetId(); }
85  int GetDeg() const { return NodeHI.GetDat().GetDeg(); }
87  int GetInDeg() const { return NodeHI.GetDat().GetInDeg(); }
89  int GetOutDeg() const { return NodeHI.GetDat().GetOutDeg(); }
91 
93  int GetInNId(const int& EdgeN) const { return Graph->GetEdge(NodeHI.GetDat().GetInEId(EdgeN)).GetSrcNId(); }
95 
97  int GetOutNId(const int& EdgeN) const { return Graph->GetEdge(NodeHI.GetDat().GetOutEId(EdgeN)).GetDstNId(); }
99 
101  int GetNbrNId(const int& EdgeN) const { const TEdge& E = Graph->GetEdge(NodeHI.GetDat().GetNbrEId(EdgeN)); return GetId()==E.GetSrcNId() ? E.GetDstNId():E.GetSrcNId(); }
103  bool IsInNId(const int& NId) const;
105  bool IsOutNId(const int& NId) const;
107  bool IsNbrNId(const int& NId) const { return IsOutNId(NId) || IsInNId(NId); }
109  int GetInEId(const int& EdgeN) const { return NodeHI.GetDat().GetInEId(EdgeN); }
111  int GetOutEId(const int& EdgeN) const { return NodeHI.GetDat().GetOutEId(EdgeN); }
113  int GetNbrEId(const int& EdgeN) const { return NodeHI.GetDat().GetNbrEId(EdgeN); }
115  bool IsInEId(const int& EId) const { return NodeHI.GetDat().IsInEId(EId); }
117  bool IsOutEId(const int& EId) const { return NodeHI.GetDat().IsOutEId(EId); }
119  bool IsNbrEId(const int& EId) const { return IsInEId(EId) || IsOutEId(EId); }
121  void GetAttrNames(TStrV& Names) const { Graph->AttrNameNI(GetId(), Names); }
123  void GetAttrVal(TStrV& Val) const { Graph->AttrValueNI(GetId(), Val); }
125  void GetIntAttrNames(TStrV& Names) const { Graph->IntAttrNameNI(GetId(), Names); }
127  void GetIntAttrVal(TIntV& Val) const { Graph->IntAttrValueNI(GetId(), Val); }
129  void GetStrAttrNames(TStrV& Names) const { Graph->StrAttrNameNI(GetId(), Names); }
131  void GetStrAttrVal(TStrV& Val) const { Graph->StrAttrValueNI(GetId(), Val); }
133  void GetFltAttrNames(TStrV& Names) const { Graph->FltAttrNameNI(GetId(), Names); }
135  void GetFltAttrVal(TFltV& Val) const { Graph->FltAttrValueNI(GetId(), Val); }
136  friend class TNEANetMP;
137  };
139  class TEdgeI {
140  private:
142  THashIter EdgeHI;
143  const TNEANetMP *Graph;
144  public:
145  TEdgeI() : EdgeHI(), Graph(NULL) { }
146  TEdgeI(const THashIter& EdgeHIter, const TNEANetMP *GraphPt) : EdgeHI(EdgeHIter), Graph(GraphPt) { }
147  TEdgeI(const TEdgeI& EdgeI) : EdgeHI(EdgeI.EdgeHI), Graph(EdgeI.Graph) { }
148  TEdgeI& operator = (const TEdgeI& EdgeI) { if (this!=&EdgeI) { EdgeHI=EdgeI.EdgeHI; Graph=EdgeI.Graph; } return *this; }
150  TEdgeI& operator++ (int) { EdgeHI++; return *this; }
151  bool operator < (const TEdgeI& EdgeI) const { return EdgeHI < EdgeI.EdgeHI; }
152  bool operator == (const TEdgeI& EdgeI) const { return EdgeHI == EdgeI.EdgeHI; }
154  int GetId() const { return EdgeHI.GetDat().GetId(); }
156  int GetSrcNId() const { return EdgeHI.GetDat().GetSrcNId(); }
158  int GetDstNId() const { return EdgeHI.GetDat().GetDstNId(); }
160  void GetAttrNames(TStrV& Names) const { Graph->AttrNameEI(GetId(), Names); }
162  void GetAttrVal(TStrV& Val) const { Graph->AttrValueEI(GetId(), Val); }
164  void GetIntAttrNames(TStrV& Names) const { Graph->IntAttrNameEI(GetId(), Names); }
166  void GetIntAttrVal(TIntV& Val) const { Graph->IntAttrValueEI(GetId(), Val); }
168  void GetStrAttrNames(TStrV& Names) const { Graph->StrAttrNameEI(GetId(), Names); }
170  void GetStrAttrVal(TStrV& Val) const { Graph->StrAttrValueEI(GetId(), Val); }
172  void GetFltAttrNames(TStrV& Names) const { Graph->FltAttrNameEI(GetId(), Names); }
174  void GetFltAttrVal(TFltV& Val) const { Graph->FltAttrValueEI(GetId(), Val); }
175  friend class TNEANetMP;
176  };
177 
179  class TAIntI {
180  private:
182  TIntVecIter HI;
183  bool isNode;
185  const TNEANetMP *Graph;
186  public:
187  TAIntI() : HI(), attr(), Graph(NULL) { }
188  TAIntI(const TIntVecIter& HIter, TStr attribute, bool isEdgeIter, const TNEANetMP* GraphPt) : HI(HIter), attr(), Graph(GraphPt) { isNode = !isEdgeIter; attr = attribute; }
189  TAIntI(const TAIntI& I) : HI(I.HI), attr(I.attr), Graph(I.Graph) { isNode = I.isNode; }
190  TAIntI& operator = (const TAIntI& I) { HI = I.HI; Graph=I.Graph; isNode = I.isNode; attr = I.attr; return *this; }
191  bool operator < (const TAIntI& I) const { return HI < I.HI; }
192  bool operator == (const TAIntI& I) const { return HI == I.HI; }
194  TInt GetDat() const { return HI[0]; }
196  bool IsDeleted() const { return isNode ? GetDat() == Graph->GetIntAttrDefaultN(attr) : GetDat() == Graph->GetIntAttrDefaultE(attr); };
197  TAIntI& operator++(int) { HI++; return *this; }
198  friend class TNEANetMP;
199  };
200 
202  class TAStrI {
203  private:
205  TStrVecIter HI;
206  bool isNode;
208  const TNEANetMP *Graph;
209  public:
210  TAStrI() : HI(), attr(), Graph(NULL) { }
211  TAStrI(const TStrVecIter& HIter, TStr attribute, bool isEdgeIter, const TNEANetMP* GraphPt) : HI(HIter), attr(), Graph(GraphPt) { isNode = !isEdgeIter; attr = attribute; }
212  TAStrI(const TAStrI& I) : HI(I.HI), attr(I.attr), Graph(I.Graph) { isNode = I.isNode; }
213  TAStrI& operator = (const TAStrI& I) { HI = I.HI; Graph=I.Graph; isNode = I.isNode; attr = I.attr; return *this; }
214  bool operator < (const TAStrI& I) const { return HI < I.HI; }
215  bool operator == (const TAStrI& I) const { return HI == I.HI; }
217  TStr GetDat() const { return HI[0]; }
219  bool IsDeleted() const { return isNode ? GetDat() == Graph->GetStrAttrDefaultN(attr) : GetDat() == Graph->GetStrAttrDefaultE(attr); };
220  TAStrI& operator++(int) { HI++; return *this; }
221  friend class TNEANetMP;
222  };
223 
225  class TAFltI {
226  private:
228  TFltVecIter HI;
229  bool isNode;
231  const TNEANetMP *Graph;
232  public:
233  TAFltI() : HI(), attr(), Graph(NULL) { }
234  TAFltI(const TFltVecIter& HIter, TStr attribute, bool isEdgeIter, const TNEANetMP* GraphPt) : HI(HIter), attr(), Graph(GraphPt) { isNode = !isEdgeIter; attr = attribute; }
235  TAFltI(const TAFltI& I) : HI(I.HI), attr(I.attr), Graph(I.Graph) { isNode = I.isNode; }
236  TAFltI& operator = (const TAFltI& I) { HI = I.HI; Graph=I.Graph; isNode = I.isNode; attr = I.attr; return *this; }
237  bool operator < (const TAFltI& I) const { return HI < I.HI; }
238  bool operator == (const TAFltI& I) const { return HI == I.HI; }
240  TFlt GetDat() const { return HI[0]; }
242  bool IsDeleted() const { return isNode ? GetDat() == Graph->GetFltAttrDefaultN(attr) : GetDat() == Graph->GetFltAttrDefaultE(attr); };
243  TAFltI& operator++(int) { HI++; return *this; }
244  friend class TNEANetMP;
245  };
246 
247 private:
248  TNode& GetNode(const int& NId) { return NodeH.GetDat(NId); }
249  const TNode& GetNode(const int& NId) const { return NodeH.GetDat(NId); }
250  TEdge& GetEdge(const int& EId) { return EdgeH.GetDat(EId); }
251  const TEdge& GetEdge(const int& EId) const { return EdgeH.GetDat(EId); }
252 
254  TInt GetIntAttrDefaultN(const TStr& attribute) const { return IntDefaultsN.IsKey(attribute) ? IntDefaultsN.GetDat(attribute) : (TInt) TInt::Mn; }
256  TStr GetStrAttrDefaultN(const TStr& attribute) const { return StrDefaultsN.IsKey(attribute) ? StrDefaultsN.GetDat(attribute) : (TStr) TStr::GetNullStr(); }
258  TFlt GetFltAttrDefaultN(const TStr& attribute) const { return FltDefaultsN.IsKey(attribute) ? FltDefaultsN.GetDat(attribute) : (TFlt) TFlt::Mn; }
260  TInt GetIntAttrDefaultE(const TStr& attribute) const { return IntDefaultsE.IsKey(attribute) ? IntDefaultsE.GetDat(attribute) : (TInt) TInt::Mn; }
262  TStr GetStrAttrDefaultE(const TStr& attribute) const { return StrDefaultsE.IsKey(attribute) ? StrDefaultsE.GetDat(attribute) : (TStr) TStr::GetNullStr(); }
264  TFlt GetFltAttrDefaultE(const TStr& attribute) const { return FltDefaultsE.IsKey(attribute) ? FltDefaultsE.GetDat(attribute) : (TFlt) TFlt::Mn; }
265 
266 private:
273 
280  enum { IntType, StrType, FltType };
281 public:
282  TNEANetMP() : CRef(), MxNId(0), MxEId(0), NodeH(), EdgeH(),
283  KeyToIndexTypeN(), KeyToIndexTypeE(), IntDefaultsN(), IntDefaultsE(),
284  StrDefaultsN(), StrDefaultsE(), FltDefaultsN(), FltDefaultsE(),
285  VecOfIntVecsN(), VecOfIntVecsE(), VecOfStrVecsN(), VecOfStrVecsE(),
286  VecOfFltVecsN(), VecOfFltVecsE() { }
288  explicit TNEANetMP(const int& Nodes, const int& Edges) : CRef(),
289  MxNId(0), MxEId(0), NodeH(), EdgeH(), KeyToIndexTypeN(), KeyToIndexTypeE(),
290  IntDefaultsN(), IntDefaultsE(), StrDefaultsN(), StrDefaultsE(),
291  FltDefaultsN(), FltDefaultsE(), VecOfIntVecsN(), VecOfIntVecsE(),
292  VecOfStrVecsN(), VecOfStrVecsE(), VecOfFltVecsN(), VecOfFltVecsE()
293  { Reserve(Nodes, Edges); }
294  TNEANetMP(const TNEANetMP& Graph) : MxNId(Graph.MxNId), MxEId(Graph.MxEId),
295  NodeH(Graph.NodeH), EdgeH(Graph.EdgeH), KeyToIndexTypeN(), KeyToIndexTypeE(),
296  IntDefaultsN(), IntDefaultsE(), StrDefaultsN(), StrDefaultsE(),
297  FltDefaultsN(), FltDefaultsE(), VecOfIntVecsN(), VecOfIntVecsE(),
298  VecOfStrVecsN(), VecOfStrVecsE(), VecOfFltVecsN(), VecOfFltVecsE() { }
300  TNEANetMP(TSIn& SIn) : MxNId(SIn), MxEId(SIn), NodeH(SIn), EdgeH(SIn),
301  KeyToIndexTypeN(SIn), KeyToIndexTypeE(SIn), IntDefaultsN(SIn), IntDefaultsE(SIn),
302  StrDefaultsN(SIn), StrDefaultsE(SIn), FltDefaultsN(SIn), FltDefaultsE(SIn),
303  VecOfIntVecsN(SIn), VecOfIntVecsE(SIn), VecOfStrVecsN(SIn),VecOfStrVecsE(SIn),
304  VecOfFltVecsN(SIn), VecOfFltVecsE(SIn) { }
306  void Save(TSOut& SOut) const {
307  MxNId.Save(SOut); MxEId.Save(SOut); NodeH.Save(SOut); EdgeH.Save(SOut);
308  KeyToIndexTypeN.Save(SOut); KeyToIndexTypeE.Save(SOut);
309  IntDefaultsN.Save(SOut); IntDefaultsE.Save(SOut);
310  StrDefaultsN.Save(SOut); StrDefaultsE.Save(SOut);
311  FltDefaultsN.Save(SOut); FltDefaultsE.Save(SOut);
312  VecOfIntVecsN.Save(SOut); VecOfIntVecsE.Save(SOut);
313  VecOfStrVecsN.Save(SOut); VecOfStrVecsE.Save(SOut);
314  VecOfFltVecsN.Save(SOut); VecOfFltVecsE.Save(SOut); }
316  static PNEANetMP New() { return PNEANetMP(new TNEANetMP()); }
318 
320  static PNEANetMP New(const int& Nodes, const int& Edges) { return PNEANetMP(new TNEANetMP(Nodes, Edges)); }
322  static PNEANetMP Load(TSIn& SIn) { return PNEANetMP(new TNEANetMP(SIn)); }
324  bool HasFlag(const TGraphFlag& Flag) const;
325  TNEANetMP& operator = (const TNEANetMP& Graph) { if (this!=&Graph) {
326  MxNId=Graph.MxNId; MxEId=Graph.MxEId; NodeH=Graph.NodeH; EdgeH=Graph.EdgeH; }
327  return *this; }
328 
330  int GetNodes() const { return NodeH.Len(); }
332  void SetNodes(const int& Length) { NodeH.SetLen(Length); }
334 
338  int AddNode(int NId = -1);
340  int AddNode(const TNodeI& NodeId) { return AddNode(NodeId.GetId()); }
342  void AddNodeWithEdges(const TInt& NId, TIntV& InEIdV, TIntV& OutEIdV);
343 // /// Deletes node of ID NId from the graph.
344 
346 // void DelNode(const int& NId);
347 // /// Deletes node of ID NodeI.GetId() from the graph.
348 // void DelNode(const TNode& NodeI) { DelNode(NodeI.GetId()); }
350  bool IsNode(const int& NId) const { return NodeH.IsKey(NId); }
352  TNodeI BegNI() const { return TNodeI(NodeH.BegI(), this); }
354  TNodeI EndNI() const { return TNodeI(NodeH.EndI(), this); }
356  TNodeI GetNI(const int& NId) const { return TNodeI(NodeH.GetI(NId), this); }
358  TAIntI BegNAIntI(const TStr& attr) const {
359  return TAIntI(VecOfIntVecsN[KeyToIndexTypeN.GetDat(attr).Val2].BegI(), attr, false, this); }
361  TAIntI EndNAIntI(const TStr& attr) const {
362  return TAIntI(VecOfIntVecsN[KeyToIndexTypeN.GetDat(attr).Val2].EndI(), attr, false, this); }
364  TAIntI GetNAIntI(const TStr& attr, const int& NId) const {
365  return TAIntI(VecOfIntVecsN[KeyToIndexTypeN.GetDat(attr).Val2].GetI(NodeH.GetKeyId(NId)), attr, false, this); }
367  TAStrI BegNAStrI(const TStr& attr) const {
368  return TAStrI(VecOfStrVecsN[KeyToIndexTypeN.GetDat(attr).Val2].BegI(), attr, false, this); }
370  TAStrI EndNAStrI(const TStr& attr) const {
371  return TAStrI(VecOfStrVecsN[KeyToIndexTypeN.GetDat(attr).Val2].EndI(), attr, false, this); }
373  TAStrI GetNAStrI(const TStr& attr, const int& NId) const {
374  return TAStrI(VecOfStrVecsN[KeyToIndexTypeN.GetDat(attr).Val2].GetI(NodeH.GetKeyId(NId)), attr, false, this); }
376  TAFltI BegNAFltI(const TStr& attr) const {
377  return TAFltI(VecOfFltVecsN[KeyToIndexTypeN.GetDat(attr).Val2].BegI(), attr, false, this); }
379  TAFltI EndNAFltI(const TStr& attr) const {
380  return TAFltI(VecOfFltVecsN[KeyToIndexTypeN.GetDat(attr).Val2].EndI(), attr, false, this); }
382  TAFltI GetNAFltI(const TStr& attr, const int& NId) const {
383  return TAFltI(VecOfFltVecsN[KeyToIndexTypeN.GetDat(attr).Val2].GetI(NodeH.GetKeyId(NId)), attr, false, this); }
384 
386  void AttrNameNI(const TInt& NId, TStrV& Names) const {
387  AttrNameNI(NId, KeyToIndexTypeN.BegI(), Names);}
388  void AttrNameNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TStrV& Names) const;
390  void AttrValueNI(const TInt& NId, TStrV& Values) const {
391  AttrValueNI(NId, KeyToIndexTypeN.BegI(), Values);}
392  void AttrValueNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TStrV& Values) const;
394  void IntAttrNameNI(const TInt& NId, TStrV& Names) const {
395  IntAttrNameNI(NId, KeyToIndexTypeN.BegI(), Names);}
396  void IntAttrNameNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TStrV& Names) const;
398  void IntAttrValueNI(const TInt& NId, TIntV& Values) const {
399  IntAttrValueNI(NId, KeyToIndexTypeN.BegI(), Values);}
400  void IntAttrValueNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TIntV& Values) const;
402  void StrAttrNameNI(const TInt& NId, TStrV& Names) const {
403  StrAttrNameNI(NId, KeyToIndexTypeN.BegI(), Names);}
404  void StrAttrNameNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TStrV& Names) const;
406  void StrAttrValueNI(const TInt& NId, TStrV& Values) const {
407  StrAttrValueNI(NId, KeyToIndexTypeN.BegI(), Values);}
408  void StrAttrValueNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TStrV& Values) const;
410  void FltAttrNameNI(const TInt& NId, TStrV& Names) const {
411  FltAttrNameNI(NId, KeyToIndexTypeN.BegI(), Names);}
412  void FltAttrNameNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TStrV& Names) const;
414  void FltAttrValueNI(const TInt& NId, TFltV& Values) const {
415  FltAttrValueNI(NId, KeyToIndexTypeN.BegI(), Values);}
416  void FltAttrValueNI(const TInt& NId, TStrIntPrH::TIter NodeHI, TFltV& Values) const;
417 
419  void AttrNameEI(const TInt& EId, TStrV& Names) const {
420  AttrNameEI(EId, KeyToIndexTypeE.BegI(), Names);}
421  void AttrNameEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TStrV& Names) const;
423  void AttrValueEI(const TInt& EId, TStrV& Values) const {
424  AttrValueEI(EId, KeyToIndexTypeE.BegI(), Values);}
425  void AttrValueEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TStrV& Values) const;
427  void IntAttrNameEI(const TInt& EId, TStrV& Names) const {
428  IntAttrNameEI(EId, KeyToIndexTypeE.BegI(), Names);}
429  void IntAttrNameEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TStrV& Names) const;
431  void IntAttrValueEI(const TInt& EId, TIntV& Values) const {
432  IntAttrValueEI(EId, KeyToIndexTypeE.BegI(), Values);}
433  void IntAttrValueEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TIntV& Values) const;
435  void StrAttrNameEI(const TInt& EId, TStrV& Names) const {
436  StrAttrNameEI(EId, KeyToIndexTypeE.BegI(), Names);}
437  void StrAttrNameEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TStrV& Names) const;
439  void StrAttrValueEI(const TInt& EId, TStrV& Values) const {
440  StrAttrValueEI(EId, KeyToIndexTypeE.BegI(), Values);}
441  void StrAttrValueEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TStrV& Values) const;
443  void FltAttrNameEI(const TInt& EId, TStrV& Names) const {
444  FltAttrNameEI(EId, KeyToIndexTypeE.BegI(), Names);}
445  void FltAttrNameEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TStrV& Names) const;
447  void FltAttrValueEI(const TInt& EId, TFltV& Values) const {
448  FltAttrValueEI(EId, KeyToIndexTypeE.BegI(), Values);}
449  void FltAttrValueEI(const TInt& EId, TStrIntPrH::TIter EdgeHI, TFltV& Values) const;
450 
452  TAIntI BegEAIntI(const TStr& attr) const {
453  return TAIntI(VecOfIntVecsE[KeyToIndexTypeE.GetDat(attr).Val2].BegI(), attr, true, this);
454  }
456  TAIntI EndEAIntI(const TStr& attr) const {
457  return TAIntI(VecOfIntVecsE[KeyToIndexTypeE.GetDat(attr).Val2].EndI(), attr, true, this);
458  }
460  TAIntI GetEAIntI(const TStr& attr, const int& EId) const {
461  return TAIntI(VecOfIntVecsE[KeyToIndexTypeE.GetDat(attr).Val2].GetI(EdgeH.GetKeyId(EId)), attr, true, this);
462  }
464  TAStrI BegEAStrI(const TStr& attr) const {
465  return TAStrI(VecOfStrVecsE[KeyToIndexTypeE.GetDat(attr).Val2].BegI(), attr, true, this); }
467  TAStrI EndEAStrI(const TStr& attr) const {
468  return TAStrI(VecOfStrVecsE[KeyToIndexTypeE.GetDat(attr).Val2].EndI(), attr, true, this);
469  }
471  TAStrI GetEAStrI(const TStr& attr, const int& EId) const {
472  return TAStrI(VecOfStrVecsE[KeyToIndexTypeE.GetDat(attr).Val2].GetI(EdgeH.GetKeyId(EId)), attr, true, this);
473  }
475  TAFltI BegEAFltI(const TStr& attr) const {
476  return TAFltI(VecOfFltVecsE[KeyToIndexTypeE.GetDat(attr).Val2].BegI(), attr, true, this);
477  }
479  TAFltI EndEAFltI(const TStr& attr) const {
480  return TAFltI(VecOfFltVecsE[KeyToIndexTypeE.GetDat(attr).Val2].EndI(), attr, true, this);
481  }
483  TAFltI GetEAFltI(const TStr& attr, const int& EId) const {
484  return TAFltI(VecOfFltVecsE[KeyToIndexTypeE.GetDat(attr).Val2].GetI(EdgeH.GetKeyId(EId)), attr, true, this);
485  }
487  int GetMxNId() const { return MxNId; }
489  int GetMxEId() const { return MxEId; }
490 
492  int Reserved() const {return NodeH.GetReservedKeyIds();}
494  int ReservedE() const {return EdgeH.GetReservedKeyIds();}
495 
497  int GetEdges() const { return EdgeH.Len(); }
499  void SetEdges(const int& Length) { EdgeH.SetLen(Length); }
501  void SetMxEId(const TInt& Id) { MxEId = Id; }
503 
508  int AddEdge(const int& SrcNId, const int& DstNId, int EId = -1);
510  int AddEdge(const TEdgeI& EdgeI) { return AddEdge(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), EdgeI.GetId()); }
512  void AddEdgeUnchecked(const TInt& EId, const int SrcNId, const int DstNId);
513 // /// Deletes an edge with edge ID EId from the graph.
514 // void DelEdge(const int& EId);
515 // /// Deletes all edges between node IDs SrcNId and DstNId from the graph.
516 
520 // void DelEdge(const int& SrcNId, const int& DstNId, const bool& IsDir = true);
522  bool IsEdge(const int& EId) const { return EdgeH.IsKey(EId); }
524  bool IsEdge(const int& SrcNId, const int& DstNId, const bool& IsDir = true) const { int EId; return IsEdge(SrcNId, DstNId, EId, IsDir); }
526  bool IsEdge(const int& SrcNId, const int& DstNId, int& EId, const bool& IsDir = true) const;
528  int GetEId(const int& SrcNId, const int& DstNId) const { int EId; return IsEdge(SrcNId, DstNId, EId)?EId:-1; }
530  TEdgeI BegEI() const { return TEdgeI(EdgeH.BegI(), this); }
532  TEdgeI EndEI() const { return TEdgeI(EdgeH.EndI(), this); }
534  TEdgeI GetEI(const int& EId) const { return TEdgeI(EdgeH.GetI(EId), this); }
536  TEdgeI GetEI(const int& SrcNId, const int& DstNId) const { return GetEI(GetEId(SrcNId, DstNId)); }
537 
539  int GetRndNId(TRnd& Rnd=TInt::Rnd) { return NodeH.GetKey(NodeH.GetRndKeyId(Rnd, 0.8)); }
541  TNodeI GetRndNI(TRnd& Rnd=TInt::Rnd) { return GetNI(GetRndNId(Rnd)); }
543  int GetRndEId(TRnd& Rnd=TInt::Rnd) { return EdgeH.GetKey(EdgeH.GetRndKeyId(Rnd, 0.8)); }
545  TEdgeI GetRndEI(TRnd& Rnd=TInt::Rnd) { return GetEI(GetRndEId(Rnd)); }
547  void GetNIdV(TIntV& NIdV) const;
549  void GetEIdV(TIntV& EIdV) const;
550 
552  bool Empty() const { return GetNodes()==0; }
554  void Clr() { MxNId=0; MxEId=0; NodeH.Clr(); EdgeH.Clr(),
555  KeyToIndexTypeN.Clr(), KeyToIndexTypeE.Clr(), IntDefaultsN.Clr(), IntDefaultsE.Clr(),
556  StrDefaultsN.Clr(), StrDefaultsE.Clr(), FltDefaultsN.Clr(), FltDefaultsE.Clr(),
557  VecOfIntVecsN.Clr(), VecOfIntVecsE.Clr(), VecOfStrVecsN.Clr(), VecOfStrVecsE.Clr(),
558  VecOfFltVecsN.Clr(), VecOfFltVecsE.Clr();}
560  void Reserve(const int& Nodes, const int& Edges) {
561  if (Nodes>0) { NodeH.Gen(Nodes); } if (Edges>0) { EdgeH.Gen(Edges); } }
563  void ReserveAttr(const int& NIntAttr, const int& NFltAttr, const int& NStrAttr, const int& EIntAttr,
564  const int& EFltAttr, const int& EStrAttr) {
565  if (NIntAttr > 0) { IntDefaultsN.Gen(NIntAttr); }
566  if (NFltAttr > 0) { FltDefaultsN.Gen(NFltAttr); }
567  if (NStrAttr > 0) { StrDefaultsN.Gen(NStrAttr); }
568  if (EIntAttr > 0) { IntDefaultsE.Gen(EIntAttr); }
569  if (EFltAttr > 0) { FltDefaultsE.Gen(EFltAttr); }
570  if (EStrAttr > 0) { StrDefaultsE.Gen(EStrAttr); }
571  }
572 // /// Defragments the graph.
573 
578  void Defrag(const bool& OnlyNodeLinks=false);
580 
583  bool IsOk(const bool& ThrowExcept=true) const;
585  void Dump(FILE *OutF=stdout) const;
586 
588 
590  int AddIntAttrDatN(const TNodeI& NodeId, const TInt& value, const TStr& attr) { return AddIntAttrDatN(NodeId.GetId(), value, attr); }
591  int AddIntAttrDatN(const int& NId, const TInt& value, const TStr& attr);
593 
595  int AddStrAttrDatN(const TNodeI& NodeId, const TStr& value, const TStr& attr) { return AddStrAttrDatN(NodeId.GetId(), value, attr); }
596  int AddStrAttrDatN(const int& NId, const TStr& value, const TStr& attr);
598 
600  int AddFltAttrDatN(const TNodeI& NodeId, const TFlt& value, const TStr& attr) { return AddFltAttrDatN(NodeId.GetId(), value, attr); }
601  int AddFltAttrDatN(const int& NId, const TFlt& value, const TStr& attr);
602 
604 
606  int AddIntAttrDatE(const TEdgeI& EdgeId, const TInt& value, const TStr& attr) { return AddIntAttrDatE(EdgeId.GetId(), value, attr); }
607  int AddIntAttrDatE(const int& EId, const TInt& value, const TStr& attr);
609 
611  int AddStrAttrDatE(const TEdgeI& EdgeId, const TStr& value, const TStr& attr) { return AddStrAttrDatE(EdgeId.GetId(), value, attr); }
612  int AddStrAttrDatE(const int& EId, const TStr& value, const TStr& attr);
614 
616  int AddFltAttrDatE(const TEdgeI& EdgeId, const TFlt& value, const TStr& attr) { return AddFltAttrDatE(EdgeId.GetId(), value, attr); }
617  int AddFltAttrDatE(const int& EId, const TFlt& value, const TStr& attr);
618 
620  TInt GetIntAttrDatN(const TNodeI& NodeId, const TStr& attr) { return GetIntAttrDatN(NodeId.GetId(), attr); }
621  TInt GetIntAttrDatN(const int& NId, const TStr& attr);
622 
624  TStr GetStrAttrDatN(const TNodeI& NodeId, const TStr& attr) { return GetStrAttrDatN(NodeId.GetId(), attr); }
625  TStr GetStrAttrDatN(const int& NId, const TStr& attr);
627  TFlt GetFltAttrDatN(const TNodeI& NodeId, const TStr& attr) { return GetFltAttrDatN(NodeId.GetId(), attr); }
628  TFlt GetFltAttrDatN(const int& NId, const TStr& attr);
629 
631  int GetIntAttrIndN(const TStr& attr);
633  TInt GetIntAttrIndDatN(const TNodeI& NodeId, const int& index) { return GetIntAttrIndDatN(NodeId.GetId(), index); }
634  TInt GetIntAttrIndDatN(const int& NId, const int& index);
635 
637  TInt GetIntAttrDatE(const TEdgeI& EdgeId, const TStr& attr) { return GetIntAttrDatE(EdgeId.GetId(), attr); }
638  TInt GetIntAttrDatE(const int& EId, const TStr& attr);
640  TStr GetStrAttrDatE(const TEdgeI& EdgeId, const TStr& attr) { return GetStrAttrDatE(EdgeId.GetId(), attr); }
641  TStr GetStrAttrDatE(const int& EId, const TStr& attr);
643  TFlt GetFltAttrDatE(const TEdgeI& EdgeId, const TStr& attr) { return GetFltAttrDatE(EdgeId.GetId(), attr); }
644  TFlt GetFltAttrDatE(const int& EId, const TStr& attr);
645 
647  int GetIntAttrIndE(const TStr& attr);
649  TInt GetIntAttrIndDatE(const TEdgeI& EdgeId, const int &index) { return GetIntAttrIndDatE(EdgeId.GetId(), index); }
650  TInt GetIntAttrIndDatE(const int& EId, const int& index);
651 
653  int DelAttrDatN(const TNodeI& NodeId, const TStr& attr) { return DelAttrDatN(NodeId.GetId(), attr); }
654  int DelAttrDatN(const int& NId, const TStr& attr);
656  int DelAttrDatE(const TEdgeI& EdgeId, const TStr& attr) { return DelAttrDatE(EdgeId.GetId(), attr); }
657  int DelAttrDatE(const int& EId, const TStr& attr);
658 
660  int AddIntAttrN(const TStr& attr, TInt defaultValue=TInt::Mn);
662  int AddStrAttrN(const TStr& attr, TStr defaultValue=TStr::GetNullStr());
664  int AddFltAttrN(const TStr& attr, TFlt defaultValue=TFlt::Mn);
665 
667  int AddIntAttrE(const TStr& attr, TInt defaultValue=TInt::Mn);
669  int AddStrAttrE(const TStr& attr, TStr defaultValue=TStr::GetNullStr());
671  int AddFltAttrE(const TStr& attr, TFlt defaultValue=TFlt::Mn);
672 
673 // /// Removes all the values for node attr.
674 // int DelAttrN(const TStr& attr);
675 // /// Removes all the values for edge attr.
676 // int DelAttrE(const TStr& attr);
677 
678  // Returns true if NId deleted for current node attr iterator.
679  bool NodeAttrIsDeleted(const int& NId, const TStrIntPrH::TIter& NodeHI) const;
680  // Returns true if NId deleted for current node int attr iterator.
681  bool NodeAttrIsIntDeleted(const int& NId, const TStrIntPrH::TIter& NodeHI) const;
682  // Returns true if NId deleted for current node str attr iterator.
683  bool NodeAttrIsStrDeleted(const int& NId, const TStrIntPrH::TIter& NodeHI) const;
684  // Returns true if NId deleted for current node flt attr iterator.
685  bool NodeAttrIsFltDeleted(const int& NId, const TStrIntPrH::TIter& NodeHI) const;
686 
687  // Returns true if EId deleted for current edge attr iterator.
688  bool EdgeAttrIsDeleted(const int& EId, const TStrIntPrH::TIter& EdgeHI) const;
689  // Returns true if EId deleted for current edge int attr iterator.
690  bool EdgeAttrIsIntDeleted(const int& EId, const TStrIntPrH::TIter& EdgeHI) const;
691  // Returns true if EId deleted for current edge str attr iterator.
692  bool EdgeAttrIsStrDeleted(const int& EId, const TStrIntPrH::TIter& EdgeHI) const;
693  // Returns true if EId deleted for current edge flt attr iterator.
694  bool EdgeAttrIsFltDeleted(const int& EId, const TStrIntPrH::TIter& EdgeHI) const;
695 
696  // Returns node attribute value, converted to Str type.
697  TStr GetNodeAttrValue(const int& NId, const TStrIntPrH::TIter& NodeHI) const;
698  // Returns edge attribute value, converted to Str type.
699  TStr GetEdgeAttrValue(const int& EId, const TStrIntPrH::TIter& EdgeHI) const;
700 
701  // Get the sum of the weights of all the outgoing edges of the node.
702  TFlt GetWeightOutEdges(const TNodeI& NI, const TStr& attr);
703  // Check if there is an edge attribute with name attr.
704  bool IsFltAttrE(const TStr& attr);
705  // Check if there is an edge attribute with name attr.
706  bool IsIntAttrE(const TStr& attr);
707  // Check if there is an edge attribute with name attr.
708  bool IsStrAttrE(const TStr& attr);
709  // Get Vector for the Flt Attribute attr.
710  TVec<TFlt>& GetFltAttrVecE(const TStr& attr);
711  // Get keyid for edge with id EId.
712  int GetFltKeyIdE(const int& EId);
713  //Fills OutWeights with the outgoing weight from each node.
714  void GetWeightOutEdgesV(TFltV& OutWeights, const TFltV& AttrVal) ;
715 
716  friend class TPt<TNEANetMP>;
717 };
718 
719 // set flags
720 namespace TSnap {
721 template <> struct IsMultiGraph<TNEANetMP> { enum { Val = 1 }; };
722 template <> struct IsDirected<TNEANetMP> { enum { Val = 1 }; };
723 }
724 
725 #else
726 
727 // substitute TNEANet for TNEANetMP on non-gcc platforms
728 //typedef TNEANet TNEANetMP;
729 //typedef TPt<TNEANetMP> PNEANetMP;
730 
731 #endif // GCC_ATOMIC
732 
733 #endif // NETWORKMP_H
TIntV::TIter TIntVecIter
Definition: networkmp.h:181
void SetNodes(const int &Length)
Sets the number of nodes in the graph.
Definition: networkmp.h:332
Definition: bd.h:440
TIter GetI(const TKey &Key) const
Definition: hashmp.h:158
void GetStrAttrNames(TStrV &Names) const
Gets vector of str attribute names.
Definition: networkmp.h:168
Main namespace for all the Snap global entities.
Definition: alg.h:1
TStr GetDat() const
Returns an attribute of the node.
Definition: networkmp.h:217
TIter EndI() const
Returns an iterator referring to the past-the-end element in the vector.
Definition: ds.h:595
TFlt GetFltAttrDatE(const TEdgeI &EdgeId, const TStr &attr)
Gets the value of flt attr from the edge attr value vector.
Definition: networkmp.h:643
bool IsInNId(const int &NId) const
Tests whether node with ID NId points to the current node.
Definition: networkmp.cpp:9
bool operator==(const TAFltI &I) const
Definition: networkmp.h:238
void GetStrAttrVal(TStrV &Val) const
Gets vector of str attribute values.
Definition: networkmp.h:131
int GetId() const
Returns ID of the current node.
Definition: networkmp.h:83
void Save(TSOut &SOut) const
Definition: networkmp.h:41
bool operator<(const TAStrI &I) const
Definition: networkmp.h:214
TEdge(const int &EId, const int &SourceNId, const int &DestNId)
Definition: networkmp.h:58
void FltAttrNameNI(const TInt &NId, TStrV &Names) const
Returns a vector of int attr names for node NId.
Definition: networkmp.h:410
void Save(TSOut &SOut) const
Definition: hashmp.h:129
void GetFltAttrVal(TFltV &Val) const
Gets vector of flt attribute values.
Definition: networkmp.h:135
TFltV::TIter TFltVecIter
Definition: networkmp.h:227
int GetOutDeg() const
Returns out-degree of the current node.
Definition: networkmp.h:89
TStrVecIter HI
Definition: networkmp.h:205
TNode(const TNode &Node)
Definition: networkmp.h:39
int GetNodes() const
Returns the number of nodes in the graph.
Definition: networkmp.h:330
Directed multigraph with node edge attributes.
Definition: networkmp.h:27
void StrAttrValueEI(const TInt &EId, TStrV &Values) const
Returns a vector of attr values for node NId.
Definition: networkmp.h:439
bool IsDeleted() const
Returns true if the attribute has been deleted.
Definition: networkmp.h:242
TEdgeI & operator=(const TEdgeI &EdgeI)
Definition: networkmp.h:148
int GetInNId(const int &EdgeN) const
Returns ID of EdgeN-th in-node (the node pointing to the current node).
Definition: networkmp.h:93
TStrIntPrH KeyToIndexTypeE
Definition: networkmp.h:272
int GetMxEId() const
Returns an ID that is larger than any edge ID in the network.
Definition: networkmp.h:489
Definition: dt.h:11
void Clr()
Deletes all nodes and edges from the graph.
Definition: networkmp.h:554
bool IsOutNId(const int &NId) const
Tests whether the current node points to node with ID NId.
Definition: networkmp.cpp:18
bool operator<(const TAIntI &I) const
Definition: networkmp.h:191
TPt< TNEANetMP > PNEANetMP
Pointer to a directed attribute multigraph (TNEANetMP)
Definition: networkmp.h:6
TInt GetIntAttrDefaultE(const TStr &attribute) const
Get Int edge attribute val. If not a proper attr, return default.
Definition: networkmp.h:260
int GetEdges() const
Returns the number of edges in the graph.
Definition: networkmp.h:497
TVec< TIntV > VecOfIntVecsN
Definition: networkmp.h:277
void Save(TSOut &SOut) const
Definition: dt.h:1153
const TNEANetMP * Graph
Definition: networkmp.h:72
TAIntI BegEAIntI(const TStr &attr) const
Returns an iterator referring to the first edge's int attribute.
Definition: networkmp.h:452
TStr GetStrAttrDefaultN(const TStr &attribute) const
Get Str node attribute val. If not a proper attr, return default.
Definition: networkmp.h:256
bool Empty() const
Tests whether the graph is empty (has zero nodes).
Definition: networkmp.h:552
bool EdgeAttrIsStrDeleted(const int &EId, const TStrIntPrH::TIter &EdgeHI) const
Definition: networkmp.cpp:245
bool IsOk(const bool &ThrowExcept=true) const
Checks the graph data structure for internal consistency.
Definition: networkmp.cpp:526
void ReserveAttr(const int &NIntAttr, const int &NFltAttr, const int &NStrAttr, const int &EIntAttr, const int &EFltAttr, const int &EStrAttr)
Reserves memory for dense attributes.
Definition: networkmp.h:563
static PNEANetMP New()
Static cons returns pointer to graph. Ex: PNEANetMP Graph=TNEANetMP::New().
Definition: networkmp.h:316
Tests (at compile time) if the graph is directed.
Definition: gbase.h:28
TStrIntPrH KeyToIndexTypeN
KeyToIndexType[N|E]: Key->(Type,Index).
Definition: networkmp.h:272
TIter BegI() const
Definition: hash.h:213
const TNEANetMP * Graph
Definition: networkmp.h:143
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
void SetEdges(const int &Length)
Sets the number of edges in the graph.
Definition: networkmp.h:499
bool operator<(const TNodeI &NodeI) const
Definition: networkmp.h:80
int AddIntAttrDatE(const TEdgeI &EdgeId, const TInt &value, const TStr &attr)
Attribute based add function for attr to Int value.
Definition: networkmp.h:606
int GetInEId(const int &EdgeN) const
Returns ID of EdgeN-th in-edge.
Definition: networkmp.h:109
TAIntI(const TIntVecIter &HIter, TStr attribute, bool isEdgeIter, const TNEANetMP *GraphPt)
Definition: networkmp.h:188
TNodeI & operator=(const TNodeI &NodeI)
Definition: networkmp.h:77
void Reserve(const int &Nodes, const int &Edges)
Reserves memory for a graph of Nodes nodes and Edges edges.
Definition: networkmp.h:560
TEdgeI GetEI(const int &EId) const
Returns an iterator referring to edge with edge ID EId.
Definition: networkmp.h:534
int GetDeg() const
Returns degree of the current node, the sum of in-degree and out-degree.
Definition: networkmp.h:85
void Save(TSOut &SOut) const
Definition: hash.h:183
TVec< TFltV > VecOfFltVecsN
Definition: networkmp.h:279
void GetAttrNames(TStrV &Names) const
Gets vector of attribute names.
Definition: networkmp.h:121
TNEANetMP TNet
Definition: networkmp.h:29
TEdgeI BegEI() const
Returns an iterator referring to the first edge in the graph.
Definition: networkmp.h:530
static PNEANetMP Load(TSIn &SIn)
Static constructor that loads the graph from a stream SIn and returns a pointer to it...
Definition: networkmp.h:322
void SetLen(const int &Length)
Definition: hashmp.h:166
void FltAttrNameEI(const TInt &EId, TStrV &Names) const
Returns a vector of int attr names for node NId.
Definition: networkmp.h:443
THashMP< TStr, TStr > StrDefaultsN
Definition: networkmp.h:275
int DelAttrDatN(const TNodeI &NodeId, const TStr &attr)
Deletes the node attribute for NodeId.
Definition: networkmp.h:653
void IntAttrNameNI(const TInt &NId, TStrV &Names) const
Returns a vector of int attr names for node NId.
Definition: networkmp.h:394
int AddIntAttrE(const TStr &attr, TInt defaultValue=TInt::Mn)
Adds a new Int edge attribute to the hashmap.
Definition: networkmp.cpp:917
bool operator==(const TNodeI &NodeI) const
Definition: networkmp.h:81
TStr GetStrAttrDatE(const TEdgeI &EdgeId, const TStr &attr)
Gets the value of str attr from the edge attr value vector.
Definition: networkmp.h:640
void GetFltAttrVal(TFltV &Val) const
Gets vector of flt attribute values.
Definition: networkmp.h:174
int AddFltAttrDatN(const TNodeI &NodeId, const TFlt &value, const TStr &attr)
Attribute based add function for attr to Flt value.
Definition: networkmp.h:600
void Save(TSOut &SOut) const
Saves the graph to a (binary) stream SOut.
Definition: networkmp.h:306
TAFltI BegNAFltI(const TStr &attr) const
Returns an iterator referring to the first node's flt attribute.
Definition: networkmp.h:376
TInt MxNId
Definition: networkmp.h:268
void Dump(FILE *OutF=stdout) const
Print the graph in a human readable form to an output stream OutF.
Definition: networkmp.cpp:579
TAFltI & operator=(const TAFltI &I)
Definition: networkmp.h:236
TAStrI & operator=(const TAStrI &I)
Definition: networkmp.h:213
void GetAttrVal(TStrV &Val) const
Gets vector of attribute values.
Definition: networkmp.h:162
TAIntI GetNAIntI(const TStr &attr, const int &NId) const
Returns an iterator referring to the node of ID NId in the graph.
Definition: networkmp.h:364
void GetIntAttrVal(TIntV &Val) const
Gets vector of int attribute values.
Definition: networkmp.h:127
int Reserved() const
Returns the number of nodes reserved in the network.
Definition: networkmp.h:492
static PNEANetMP 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: networkmp.h:320
TAIntI EndEAIntI(const TStr &attr) const
Returns an iterator referring to the past-the-end edge's attribute.
Definition: networkmp.h:456
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:262
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: networkmp.h:528
int GetNbrEId(const int &EdgeN) const
Returns ID of EdgeN-th in or out-edge.
Definition: networkmp.h:113
int GetNbrEId(const int &EdgeN) const
Definition: networkmp.h:48
int GetDeg() const
Definition: networkmp.h:43
static TRnd Rnd
Definition: dt.h:1146
TInt GetIntAttrIndDatN(const TNodeI &NodeId, const int &index)
Gets the value of node int attr specified by the attr index.
Definition: networkmp.h:633
void GetStrAttrVal(TStrV &Val) const
Gets vector of str attribute values.
Definition: networkmp.h:170
void GetIntAttrVal(TIntV &Val) const
Gets vector of int attribute values.
Definition: networkmp.h:166
TEdge & GetEdge(const int &EId)
Definition: networkmp.h:250
void StrAttrValueNI(const TInt &NId, TStrV &Values) const
Returns a vector of attr values for node NId.
Definition: networkmp.h:406
TStr GetNodeAttrValue(const int &NId, const TStrIntPrH::TIter &NodeHI) const
Definition: networkmp.cpp:135
TNEANetMP(TSIn &SIn)
Constructor for loading the graph from a (binary) stream SIn.
Definition: networkmp.h:300
Definition: dt.h:1386
bool IsIntAttrE(const TStr &attr)
Definition: networkmp.cpp:1047
THashMP< TStr, TInt > IntDefaultsN
Definition: networkmp.h:274
Definition: fl.h:58
void Save(TSOut &SOut) const
Definition: ds.h:954
TNodeI GetRndNI(TRnd &Rnd=TInt::Rnd)
Returns an interator referring to a random node in the graph.
Definition: networkmp.h:541
TAFltI & operator++(int)
Definition: networkmp.h:243
void AttrNameEI(const TInt &EId, TStrV &Names) const
Returns a vector of attr names for edge EId.
Definition: networkmp.h:419
TAFltI GetNAFltI(const TStr &attr, const int &NId) const
Returns an iterator referring to the node of ID NId in the graph.
Definition: networkmp.h:382
int GetId() const
Definition: networkmp.h:62
THashMP< TInt, TEdge > EdgeH
Definition: networkmp.h:270
TInt GetDat() const
Returns an attribute of the node.
Definition: networkmp.h:194
TInt GetIntAttrDefaultN(const TStr &attribute) const
Get Int node attribute val. If not a proper attr, return default.
Definition: networkmp.h:254
void GetAttrVal(TStrV &Val) const
Gets vector of attribute values.
Definition: networkmp.h:123
TStr GetEdgeAttrValue(const int &EId, const TStrIntPrH::TIter &EdgeHI) const
Definition: networkmp.cpp:257
bool IsStrAttrE(const TStr &attr)
Definition: networkmp.cpp:1052
void GetFltAttrNames(TStrV &Names) const
Gets vector of flt attribute names.
Definition: networkmp.h:172
THashMP< TStr, TStr > StrDefaultsE
Definition: networkmp.h:275
const TEdge & GetEdge(const int &EId) const
Definition: networkmp.h:251
TIter EndI() const
Definition: hashmp.h:156
int GetSrcNId() const
Returns the source of the edge.
Definition: networkmp.h:156
TNodeI EndNI() const
Returns an iterator referring to the past-the-end node in the graph.
Definition: networkmp.h:354
TAStrI GetNAStrI(const TStr &attr, const int &NId) const
Returns an iterator referring to the node of ID NId in the graph.
Definition: networkmp.h:373
void Save(TSOut &SOut) const
Definition: networkmp.h:61
Node/edge string attribute iterator. Iterates through all nodes/edges for one string attribute...
Definition: networkmp.h:202
const TNEANetMP * Graph
Definition: networkmp.h:185
static const int Mn
Definition: dt.h:1141
void Clr(const bool &DoDel=true, const TSizeTy &NoDelLim=-1)
Clears the contents of the vector.
Definition: ds.h:1022
TVec< TStrV > VecOfStrVecsE
Definition: networkmp.h:278
int GetIntAttrIndE(const TStr &attr)
Gets the index of the edge attr value vector specified by str attr.
Definition: networkmp.cpp:818
void StrAttrNameEI(const TInt &EId, TStrV &Names) const
Returns a vector of str attr names for node NId.
Definition: networkmp.h:435
TAFltI GetEAFltI(const TStr &attr, const int &EId) const
Returns an iterator referring to the edge of ID EId in the graph.
Definition: networkmp.h:483
bool operator<(const TEdgeI &EdgeI) const
Definition: networkmp.h:151
TAStrI(const TStrVecIter &HIter, TStr attribute, bool isEdgeIter, const TNEANetMP *GraphPt)
Definition: networkmp.h:211
void GetNIdV(TIntV &NIdV) const
Gets a vector IDs of all nodes in the graph.
Definition: networkmp.cpp:501
void IntAttrNameEI(const TInt &EId, TStrV &Names) const
Returns a vector of int attr names for edge EId.
Definition: networkmp.h:427
int GetRndNId(TRnd &Rnd=TInt::Rnd)
Returns an ID of a random node in the graph.
Definition: networkmp.h:539
TEdgeI GetEI(const int &SrcNId, const int &DstNId) const
Returns an iterator referring to edge (SrcNId, DstNId) in the graph.
Definition: networkmp.h:536
TInt MxEId
Definition: networkmp.h:268
TEdgeI(const THashIter &EdgeHIter, const TNEANetMP *GraphPt)
Definition: networkmp.h:146
TNode & GetNode(const int &NId)
Definition: networkmp.h:248
TNodeI(const THashIter &NodeHIter, const TNEANetMP *GraphPt)
Definition: networkmp.h:75
TVec< TFlt > & GetFltAttrVecE(const TStr &attr)
Definition: networkmp.cpp:782
bool IsFltAttrE(const TStr &attr)
Definition: networkmp.cpp:1042
bool NodeAttrIsFltDeleted(const int &NId, const TStrIntPrH::TIter &NodeHI) const
Definition: networkmp.cpp:129
TVec< TIntV > VecOfIntVecsE
Definition: networkmp.h:277
void GetStrAttrNames(TStrV &Names) const
Gets vector of str attribute names.
Definition: networkmp.h:129
Tests (at compile time) if the graph is a multigraph with multiple edges between the same nodes...
Definition: gbase.h:30
bool NodeAttrIsStrDeleted(const int &NId, const TStrIntPrH::TIter &NodeHI) const
Definition: networkmp.cpp:123
TAFltI(const TFltVecIter &HIter, TStr attribute, bool isEdgeIter, const TNEANetMP *GraphPt)
Definition: networkmp.h:234
int AddStrAttrN(const TStr &attr, TStr defaultValue=TStr::GetNullStr())
Adds a new Str node attribute to the hashmap.
Definition: networkmp.cpp:878
int GetIntAttrIndN(const TStr &attr)
Gets the index of the node attr value vector specified by str attr.
Definition: networkmp.cpp:798
int GetMxNId() const
Returns an ID that is larger than any node ID in the network.
Definition: networkmp.h:487
TFlt GetWeightOutEdges(const TNodeI &NI, const TStr &attr)
Definition: networkmp.cpp:1023
TAIntI GetEAIntI(const TStr &attr, const int &EId) const
Returns an iterator referring to the edge of ID EId in the graph.
Definition: networkmp.h:460
TAIntI(const TAIntI &I)
Definition: networkmp.h:189
TFlt GetFltAttrDefaultE(const TStr &attribute) const
Get Flt edge attribute val. If not a proper attr, return default.
Definition: networkmp.h:264
bool IsNode(const int &NId) const
If the node of ID NId does not exist the function aborts.
Definition: networkmp.h:350
bool operator==(const TEdgeI &EdgeI) const
Definition: networkmp.h:152
TStr GetStrAttrDefaultE(const TStr &attribute) const
Get Str edge attribute val. If not a proper attr, return default.
Definition: networkmp.h:262
void GetEIdV(TIntV &EIdV) const
Gets a vector IDs of all edges in the graph.
Definition: networkmp.cpp:508
void FltAttrValueNI(const TInt &NId, TFltV &Values) const
Returns a vector of attr values for node NId.
Definition: networkmp.h:414
TAStrI(const TAStrI &I)
Definition: networkmp.h:212
int AddStrAttrDatE(const TEdgeI &EdgeId, const TStr &value, const TStr &attr)
Attribute based add function for attr to Str value.
Definition: networkmp.h:611
bool IsKey(const TKey &Key) const
Definition: hashmp.h:191
TInt GetIntAttrIndDatE(const TEdgeI &EdgeId, const int &index)
Gets the value of edge int attr specified by the attr index.
Definition: networkmp.h:649
void GetIntAttrNames(TStrV &Names) const
Gets vector of int attribute names.
Definition: networkmp.h:125
int GetInDeg() const
Definition: networkmp.h:44
THashIter EdgeHI
Definition: networkmp.h:142
static TStr GetNullStr()
Definition: dt.cpp:1626
bool NodeAttrIsIntDeleted(const int &NId, const TStrIntPrH::TIter &NodeHI) const
Definition: networkmp.cpp:117
TFlt GetFltAttrDefaultN(const TStr &attribute) const
Get Flt node attribute val. If not a proper attr, return default.
Definition: networkmp.h:258
TNodeI & operator++(int)
Increment iterator.
Definition: networkmp.h:79
void GetFltAttrNames(TStrV &Names) const
Gets vector of flt attribute names.
Definition: networkmp.h:133
Definition: fl.h:128
TAFltI BegEAFltI(const TStr &attr) const
Returns an iterator referring to the first edge's flt attribute.
Definition: networkmp.h:475
THashMP< TStr, TInt > IntDefaultsE
Definition: networkmp.h:274
TSizeTy SearchBin(const TVal &Val) const
Returns the position of an element with value Val.
Definition: ds.h:1519
TNEANetMP(const int &Nodes, const int &Edges)
Constructor that reserves enough memory for a graph of nodes and edges.
Definition: networkmp.h:288
TNodeI(const TNodeI &NodeI)
Definition: networkmp.h:76
Node iterator. Only forward iteration (operator++) is supported.
Definition: networkmp.h:68
int GetInEId(const int &EdgeN) const
Definition: networkmp.h:46
TIntVecIter HI
Definition: networkmp.h:182
TNEANetMP(const TNEANetMP &Graph)
Definition: networkmp.h:294
int AddEdge(const int &SrcNId, const int &DstNId, int EId=-1)
Adds an edge with ID EId between node IDs SrcNId and DstNId to the graph.
Definition: networkmp.cpp:388
Definition: dt.h:1137
TNode(TSIn &SIn)
Definition: networkmp.h:40
TVal * TIter
Random access iterator to TVal.
Definition: ds.h:432
TEdgeI & operator++(int)
Increment iterator.
Definition: networkmp.h:150
bool IsNbrEId(const int &EId) const
Tests whether the edge with ID EId is an in or out-edge of current node.
Definition: networkmp.h:119
int GetReservedKeyIds() const
Definition: hashmp.h:169
TAStrI GetEAStrI(const TStr &attr, const int &EId) const
Returns an iterator referring to the edge of ID EId in the graph.
Definition: networkmp.h:471
int GetInDeg() const
Returns in-degree of the current node.
Definition: networkmp.h:87
int AddStrAttrDatN(const TNodeI &NodeId, const TStr &value, const TStr &attr)
Attribute based add function for attr to Str value.
Definition: networkmp.h:595
Node/edge float attribute iterator. Iterates through all nodes/edges for one float attribute...
Definition: networkmp.h:225
THashMP< TInt, TNode >::TIter THashIter
Definition: networkmp.h:70
TAFltI EndEAFltI(const TStr &attr) const
Returns an iterator referring to the past-the-end edge's attribute.
Definition: networkmp.h:479
void AddNodeWithEdges(const TInt &NId, TIntV &InEIdV, TIntV &OutEIdV)
Adds a node along with its neighbor edges.
Definition: networkmp.cpp:319
TNodeI GetNI(const int &NId) const
Returns an iterator referring to the node of ID NId in the graph.
Definition: networkmp.h:356
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: hashmp.h:558
TAStrI & operator++(int)
Definition: networkmp.h:220
void Gen(const int &ExpectVals)
Definition: hashmp.h:160
int GetSrcNId() const
Definition: networkmp.h:63
int GetOutNId(const int &EdgeN) const
Returns ID of EdgeN-th out-node (the node the current node points to).
Definition: networkmp.h:97
Edge iterator. Only forward iteration (operator++) is supported.
Definition: networkmp.h:139
TStr GetStrAttrDatN(const TNodeI &NodeId, const TStr &attr)
Gets the value of str attr from the node attr value vector.
Definition: networkmp.h:624
TAIntI EndNAIntI(const TStr &attr) const
Returns an iterator referring to the past-the-end node's attribute.
Definition: networkmp.h:361
TNEANetMP & operator=(const TNEANetMP &Graph)
Definition: networkmp.h:325
void AttrNameNI(const TInt &NId, TStrV &Names) const
Returns a vector of attr names for node NId.
Definition: networkmp.h:386
TIter BegI() const
Definition: hashmp.h:153
int DelAttrDatE(const TEdgeI &EdgeId, const TStr &attr)
Deletes the edge attribute for NodeId.
Definition: networkmp.h:656
bool IsOutEId(const int &EId) const
Definition: networkmp.h:50
TAStrI EndNAStrI(const TStr &attr) const
Returns an iterator referring to the past-the-end node's attribute.
Definition: networkmp.h:370
TInt GetIntAttrDatN(const TNodeI &NodeId, const TStr &attr)
Gets the value of int attr from the node attr value vector.
Definition: networkmp.h:620
int GetNbrNId(const int &EdgeN) const
Returns ID of EdgeN-th neighboring node.
Definition: networkmp.h:101
bool operator==(const TAStrI &I) const
Definition: networkmp.h:215
THashMP< TInt, TNode > NodeH
Definition: networkmp.h:269
TFlt GetFltAttrDatN(const TNodeI &NodeId, const TStr &attr)
Gets the value of flt attr from the node attr value vector.
Definition: networkmp.h:627
const TNode & GetNode(const int &NId) const
Definition: networkmp.h:249
TVec< TFltV > VecOfFltVecsE
Definition: networkmp.h:279
TNodeI BegNI() const
Returns an iterator referring to the first node in the graph.
Definition: networkmp.h:352
Definition: dt.h:412
TFlt GetDat() const
Returns an attribute of the node.
Definition: networkmp.h:240
void GetAttrNames(TStrV &Names) const
Gets vector of attribute names.
Definition: networkmp.h:160
bool IsDeleted() const
Returns true if the attribute has been deleted.
Definition: networkmp.h:196
TFltVecIter HI
Definition: networkmp.h:228
TIter BegI() const
Returns an iterator pointing to the first element in the vector.
Definition: ds.h:593
Node/edge integer attribute iterator. Iterates through all nodes/edges for one integer attribute...
Definition: networkmp.h:179
bool IsInEId(const int &EId) const
Definition: networkmp.h:49
TAIntI & operator++(int)
Definition: networkmp.h:197
enum TGraphFlag_ TGraphFlag
Graph Flags, used for quick testing of graph types.
TEdgeI GetRndEI(TRnd &Rnd=TInt::Rnd)
Returns an interator referring to a random edge in the graph.
Definition: networkmp.h:545
bool HasFlag(const TGraphFlag &Flag) const
Allows for run-time checking the type of the graph (see the TGraphFlag for flags).
Definition: networkmp.cpp:5
int GetOutDeg() const
Definition: networkmp.h:45
int AddNode(int NId=-1)
Adds a node of ID NId to the graph.
Definition: networkmp.cpp:271
TAStrI BegNAStrI(const TStr &attr) const
Returns an iterator referring to the first node's str attribute.
Definition: networkmp.h:367
TAFltI EndNAFltI(const TStr &attr) const
Returns an iterator referring to the past-the-end node's attribute.
Definition: networkmp.h:379
TPt< TNEANetMP > PNet
Definition: networkmp.h:30
int ReservedE() const
Returns the number of edges reserved in the network.
Definition: networkmp.h:494
int AddIntAttrN(const TStr &attr, TInt defaultValue=TInt::Mn)
Adds a new Int node attribute to the hashmap.
Definition: networkmp.cpp:859
bool operator<(const TAFltI &I) const
Definition: networkmp.h:237
TEdgeI EndEI() const
Returns an iterator referring to the past-the-end edge in the graph.
Definition: networkmp.h:532
int AddFltAttrE(const TStr &attr, TFlt defaultValue=TFlt::Mn)
Adds a new Flt edge attribute to the hashmap.
Definition: networkmp.cpp:956
void StrAttrNameNI(const TInt &NId, TStrV &Names) const
Returns a vector of str attr names for node NId.
Definition: networkmp.h:402
Hash-Table with multiprocessing support.
Definition: hashmp.h:81
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: networkmp.h:524
int AddIntAttrDatN(const TNodeI &NodeId, const TInt &value, const TStr &attr)
Attribute based add function for attr to Int value.
Definition: networkmp.h:590
TVal2 Val2
Definition: ds.h:35
void Clr(const bool &DoDel=true, const int &NoDelLim=-1, const bool &ResetDat=true)
Definition: hash.h:361
TEdgeI(const TEdgeI &EdgeI)
Definition: networkmp.h:147
TEdge(TSIn &SIn)
Definition: networkmp.h:60
Definition: bd.h:196
int AddEdge(const TEdgeI &EdgeI)
Adds an edge between EdgeI.GetSrcNId() and EdgeI.GetDstNId() to the graph.
Definition: networkmp.h:510
int GetDstNId() const
Returns the destination of the edge.
Definition: networkmp.h:158
TStrV::TIter TStrVecIter
Definition: networkmp.h:204
bool IsOutEId(const int &EId) const
Tests whether the edge with ID EId is an out-edge of current node.
Definition: networkmp.h:117
bool IsDeleted() const
Returns true if the attribute has been deleted.
Definition: networkmp.h:219
void Clr(const bool &DoDel=true)
Definition: hashmp.h:474
TEdge(const TEdge &Edge)
Definition: networkmp.h:59
void IntAttrValueEI(const TInt &EId, TIntV &Values) const
Returns a vector of attr values for edge EId.
Definition: networkmp.h:431
void FltAttrValueEI(const TInt &EId, TFltV &Values) const
Returns a vector of attr values for node NId.
Definition: networkmp.h:447
TInt GetIntAttrDatE(const TEdgeI &EdgeId, const TStr &attr)
Gets the value of int attr from the edge attr value vector.
Definition: networkmp.h:637
bool IsInEId(const int &EId) const
Tests whether the edge with ID EId is an in-edge of current node.
Definition: networkmp.h:115
THashMP< TStr, TFlt > FltDefaultsE
Definition: networkmp.h:276
TAStrI BegEAStrI(const TStr &attr) const
Returns an iterator referring to the first edge's str attribute.
Definition: networkmp.h:464
void AttrValueNI(const TInt &NId, TStrV &Values) const
Returns a vector of attr values for node NId.
Definition: networkmp.h:390
int GetRndEId(TRnd &Rnd=TInt::Rnd)
Returns an ID of a random edge in the graph.
Definition: networkmp.h:543
void AttrValueEI(const TInt &EId, TStrV &Values) const
Returns a vector of attr values for edge EId.
Definition: networkmp.h:423
TAFltI(const TAFltI &I)
Definition: networkmp.h:235
TAStrI EndEAStrI(const TStr &attr) const
Returns an iterator referring to the past-the-end edge's attribute.
Definition: networkmp.h:467
TNode(const int &NId)
Definition: networkmp.h:38
TAIntI BegNAIntI(const TStr &attr) const
Returns an iterator referring to the first node's int attribute.
Definition: networkmp.h:358
const TNEANetMP * Graph
Definition: networkmp.h:231
int GetOutEId(const int &EdgeN) const
Returns ID of EdgeN-th out-edge.
Definition: networkmp.h:111
THashIter NodeHI
Definition: networkmp.h:71
int GetOutEId(const int &EdgeN) const
Definition: networkmp.h:47
bool IsEdge(const int &EId) const
Tests whether an edge with edge ID EId exists in the graph.
Definition: networkmp.h:522
void GetIntAttrNames(TStrV &Names) const
Gets vector of int attribute names.
Definition: networkmp.h:164
bool NodeAttrIsDeleted(const int &NId, const TStrIntPrH::TIter &NodeHI) const
Definition: networkmp.cpp:110
bool EdgeAttrIsDeleted(const int &EId, const TStrIntPrH::TIter &EdgeHI) const
Definition: networkmp.cpp:232
int AddStrAttrE(const TStr &attr, TStr defaultValue=TStr::GetNullStr())
Adds a new Str edge attribute to the hashmap.
Definition: networkmp.cpp:937
THashMP< TInt, TEdge >::TIter THashIter
Definition: networkmp.h:141
THashMP< TStr, TFlt > FltDefaultsN
Definition: networkmp.h:276
bool operator==(const TAIntI &I) const
Definition: networkmp.h:192
void Defrag(const bool &OnlyNodeLinks=false)
Definition: networkmp.cpp:515
int GetKeyId(const TKey &Key) const
Definition: hashmp.h:459
int AddNode(const TNodeI &NodeId)
Adds a node of ID NodeI.GetId() to the graph.
Definition: networkmp.h:340
bool IsNbrNId(const int &NId) const
Tests whether node with ID NId is a neighbor of the current node.
Definition: networkmp.h:107
const TNEANetMP * Graph
Definition: networkmp.h:208
TIter GetI(const TSizeTy &ValN) const
Returns an iterator an element at position ValN.
Definition: ds.h:597
void IntAttrValueNI(const TInt &NId, TIntV &Values) const
Returns a vector of attr values for node NId.
Definition: networkmp.h:398
bool EdgeAttrIsIntDeleted(const int &EId, const TStrIntPrH::TIter &EdgeHI) const
Definition: networkmp.cpp:239
int AddFltAttrDatE(const TEdgeI &EdgeId, const TFlt &value, const TStr &attr)
Attribute based add function for attr to Flt value.
Definition: networkmp.h:616
int GetFltKeyIdE(const int &EId)
Definition: networkmp.cpp:786
const TDat & GetDat(const TKey &Key) const
Definition: hashmp.h:195
TVec< TStrV > VecOfStrVecsN
Definition: networkmp.h:278
void GetWeightOutEdgesV(TFltV &OutWeights, const TFltV &AttrVal)
Definition: networkmp.cpp:1034
void SetMxEId(const TInt &Id)
Sets the MaxEId. Used since AddEdgeUnchecked doesn't affect EId for efficiency.
Definition: networkmp.h:501
int AddFltAttrN(const TStr &attr, TFlt defaultValue=TFlt::Mn)
Adds a new Flt node attribute to the hashmap.
Definition: networkmp.cpp:897
static const double Mn
Definition: dt.h:1390
int GetId() const
Returns edge ID.
Definition: networkmp.h:154
int GetDstNId() const
Definition: networkmp.h:64
int Len() const
Definition: hashmp.h:165
TAIntI & operator=(const TAIntI &I)
Definition: networkmp.h:190
bool EdgeAttrIsFltDeleted(const int &EId, const TStrIntPrH::TIter &EdgeHI) const
Definition: networkmp.cpp:251
TCRef CRef
Definition: networkmp.h:267
int GetId() const
Definition: networkmp.h:42
const TKey & GetKey(const int &KeyId) const
Definition: hashmp.h:185
void AddEdgeUnchecked(const TInt &EId, const int SrcNId, const int DstNId)
Adds an edge without checking its adjacent nodes' neighborhood.
Definition: networkmp.cpp:438