13 template <
class TNodeData>
75 int GetInNId(
const int& NodeN)
const {
return NodeHI.GetDat().GetInNId(NodeN); }
79 int GetOutNId(
const int& NodeN)
const {
return NodeHI.GetDat().GetOutNId(NodeN); }
83 int GetNbrNId(
const int& NodeN)
const {
return NodeHI.GetDat().GetNbrNId(NodeN); }
85 bool IsInNId(
const int& NId)
const {
return NodeHI.GetDat().IsInNId(NId); }
87 bool IsOutNId(
const int& NId)
const {
return NodeHI.GetDat().IsOutNId(NId); }
92 const TNodeData&
GetDat()
const {
return NodeHI.GetDat().GetDat(); }
169 int AddNode(
int NId,
const TNodeData& NodeDat);
171 int AddNode(
const TNodeI& NodeId) {
return AddNode(NodeId.GetId(), NodeId.GetDat()); }
189 void SetNDat(
const int& NId,
const TNodeData& NodeDat);
207 int AddEdge(
const int& SrcNId,
const int& DstNId);
209 int AddEdge(
const TEdgeI& EdgeI) {
return AddEdge(EdgeI.GetSrcNId(), EdgeI.GetDstNId()); }
215 void DelEdge(
const int& SrcNId,
const int& DstNId,
const bool& IsDir =
true);
217 bool IsEdge(
const int& SrcNId,
const int& DstNId,
const bool& IsDir =
true)
const;
223 TEdgeI
GetEI(
const int& EId)
const;
225 TEdgeI
GetEI(
const int& SrcNId,
const int& DstNId)
const;
237 void Clr(
const bool& DoDel=
true,
const bool& ResetDat=
true) {
240 void Reserve(
const int& Nodes,
const int& Edges) {
if (Nodes>0) {
NodeH.
Gen(Nodes/2); } }
251 void Defrag(
const bool& OnlyNodeLinks=
false);
256 bool IsOk(
const bool& ThrowExcept=
true)
const;
267 template <
class TNodeData>
272 template <
class TNodeData>
275 NId = MxNId; MxNId++;
280 NodeH.AddDat(NId,
TNode(NId));
284 template <
class TNodeData>
287 NId = MxNId; MxNId++;
292 NodeH.AddDat(NId,
TNode(NId, NodeDat));
296 template <
class TNodeData>
298 {
TNode& Node = GetNode(NId);
299 for (
int e = 0; e < Node.
GetOutDeg(); e++) {
301 if (nbr == NId) {
continue; }
302 TNode& N = GetNode(nbr);
306 for (
int e = 0; e < Node.
GetInDeg(); e++) {
308 if (nbr == NId) {
continue; }
309 TNode& N = GetNode(nbr);
316 template <
class TNodeData>
319 NodeH.GetDat(NId).NodeDat = NodeDat;
322 template <
class TNodeData>
325 for (
int N=NodeH.FFirstKeyId(); NodeH.FNextKeyId(N);) {
326 edges+=NodeH[N].GetOutDeg(); }
330 template <
class TNodeData>
332 IAssertR(IsNode(SrcNId) && IsNode(DstNId),
TStr::Fmt(
"%d or %d not a node.", SrcNId, DstNId).CStr());
333 if (IsEdge(SrcNId, DstNId)) {
return -2; }
334 GetNode(SrcNId).OutNIdV.AddSorted(DstNId);
335 GetNode(DstNId).InNIdV.AddSorted(SrcNId);
339 template <
class TNodeData>
341 IAssertR(IsNode(SrcNId) && IsNode(DstNId),
TStr::Fmt(
"%d or %d not a node.", SrcNId, DstNId).CStr());
342 GetNode(SrcNId).OutNIdV.DelIfIn(DstNId);
343 GetNode(DstNId).InNIdV.DelIfIn(SrcNId);
345 GetNode(DstNId).OutNIdV.DelIfIn(SrcNId);
346 GetNode(SrcNId).InNIdV.DelIfIn(DstNId);
350 template <
class TNodeData>
352 if (! IsNode(SrcNId) || ! IsNode(DstNId)) {
return false; }
353 if (IsDir) {
return GetNode(SrcNId).IsOutNId(DstNId); }
354 else {
return GetNode(SrcNId).IsOutNId(DstNId) || GetNode(DstNId).IsOutNId(SrcNId); }
357 template <
class TNodeData>
360 for (
int N=NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
361 NIdV.
Add(NodeH.GetKey(N)); }
364 template <
class TNodeData>
366 const TNodeI SrcNI = GetNI(SrcNId);
367 const int NodeN = SrcNI.
NodeHI.GetDat().OutNIdV.SearchBin(DstNId);
368 if (NodeN == -1) {
return EndEI(); }
369 return TEdgeI(SrcNI, EndNI(), NodeN);
372 template <
class TNodeData>
374 for (
int n = NodeH.FFirstKeyId(); NodeH.FNextKeyId(n); ) {
375 TNode& Node = NodeH[n];
378 if (! OnlyNodeLinks && ! NodeH.IsKeyIdEqKeyN()) {
382 template <
class TNodeData>
385 for (
int N = NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
386 const TNode& Node = NodeH[N];
388 const TStr Msg =
TStr::Fmt(
"Out-neighbor list of node %d is not sorted.", Node.
GetId());
392 const TStr Msg =
TStr::Fmt(
"In-neighbor list of node %d is not sorted.", Node.
GetId());
397 for (
int e = 0; e < Node.
GetOutDeg(); e++) {
399 const TStr Msg =
TStr::Fmt(
"Out-edge %d --> %d: node %d does not exist.",
403 if (e > 0 && prevNId == Node.
GetOutNId(e)) {
404 const TStr Msg =
TStr::Fmt(
"Node %d has duplidate out-edge %d --> %d.",
412 for (
int e = 0; e < Node.
GetInDeg(); e++) {
414 const TStr Msg =
TStr::Fmt(
"In-edge %d <-- %d: node %d does not exist.",
418 if (e > 0 && prevNId == Node.
GetInNId(e)) {
419 const TStr Msg =
TStr::Fmt(
"Node %d has duplidate in-edge %d <-- %d.",
440 template <
class TNodeData,
class TEdgeData>
535 const TEdgeData&
GetOutEDat(
const int& EdgeN)
const {
return NodeHI.GetDat().GetOutEDat(EdgeN); }
614 int AddNode(
int NId,
const TNodeData& NodeDat);
616 int AddNode(
const TNodeI& NodeId) {
return AddNode(NodeId.GetId(), NodeId.GetDat()); }
634 void SetNDat(
const int& NId,
const TNodeData& NodeDat);
652 int AddEdge(
const int& SrcNId,
const int& DstNId);
660 int AddEdge(
const int& SrcNId,
const int& DstNId,
const TEdgeData& EdgeDat);
662 int AddEdge(
const TEdgeI& EdgeI) {
return AddEdge(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), EdgeI()); }
668 void DelEdge(
const int& SrcNId,
const int& DstNId,
const bool& IsDir =
true);
670 bool IsEdge(
const int& SrcNId,
const int& DstNId,
const bool& IsDir =
true)
const;
676 TEdgeI
GetEI(
const int& EId)
const;
678 TEdgeI
GetEI(
const int& SrcNId,
const int& DstNId)
const;
680 void SetEDat(
const int& SrcNId,
const int& DstNId,
const TEdgeData& EdgeDat);
684 bool GetEDat(
const int& SrcNId,
const int& DstNId, TEdgeData& EdgeDat)
const;
686 TEdgeData&
GetEDat(
const int& SrcNId,
const int& DstNId);
688 const TEdgeData&
GetEDat(
const int& SrcNId,
const int& DstNId)
const;
702 void Clr(
const bool& DoDel=
true,
const bool& ResetDat=
true) {
705 void Reserve(
const int& Nodes,
const int& Edges) {
if (Nodes>0) {
NodeH.
Gen(Nodes/2); } }
716 void Defrag(
const bool& OnlyNodeLinks=
false);
721 bool IsOk(
const bool& ThrowExcept=
true)
const;
733 template <
class TNodeData,
class TEdgeData>
738 template <
class TNodeData,
class TEdgeData>
740 int LValN=0, RValN = NIdV.Len()-1;
741 while (RValN >= LValN) {
742 const int ValN = (LValN+RValN)/2;
743 const int CurNId = NIdV[ValN].Val1;
744 if (NId == CurNId) {
return ValN; }
745 if (NId < CurNId) { RValN=ValN-1; }
746 else { LValN=ValN+1; }
751 template <
class TNodeData,
class TEdgeData>
754 NId = MxNId; MxNId++;
759 NodeH.AddDat(NId,
TNode(NId));
763 template <
class TNodeData,
class TEdgeData>
766 NId = MxNId; MxNId++;
771 NodeH.AddDat(NId,
TNode(NId, NodeDat));
775 template <
class TNodeData,
class TEdgeData>
778 NodeH.GetDat(NId).NodeDat = NodeDat;
781 template <
class TNodeData,
class TEdgeData>
783 const TNode& Node = GetNode(NId);
784 for (
int out = 0; out < Node.
GetOutDeg(); out++) {
786 if (nbr == NId) {
continue; }
787 TIntV& NIdV = GetNode(nbr).InNIdV;
789 if (pos != -1) { NIdV.
Del(pos); }
791 for (
int in = 0; in < Node.
GetInDeg(); in++) {
793 if (nbr == NId) {
continue; }
795 const int pos = GetNIdPos(NIdDatV, NId);
796 if (pos != -1) { NIdDatV.
Del(pos); }
801 template <
class TNodeData,
class TEdgeData>
804 for (
int N=NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
805 edges+=NodeH[N].GetOutDeg(); }
809 template <
class TNodeData,
class TEdgeData>
811 return AddEdge(SrcNId, DstNId, TEdgeData());
814 template <
class TNodeData,
class TEdgeData>
816 IAssertR(IsNode(SrcNId) && IsNode(DstNId),
TStr::Fmt(
"%d or %d not a node.", SrcNId, DstNId).CStr());
818 if (IsEdge(SrcNId, DstNId)) {
819 GetEDat(SrcNId, DstNId) = EdgeDat;
823 GetNode(DstNId).InNIdV.AddSorted(SrcNId);
827 template <
class TNodeData,
class TEdgeData>
829 IAssertR(IsNode(SrcNId) && IsNode(DstNId),
TStr::Fmt(
"%d or %d not a node.", SrcNId, DstNId).CStr());
830 int pos = GetNIdPos(GetNode(SrcNId).OutNIdV, DstNId);
831 if (pos != -1) { GetNode(SrcNId).OutNIdV.Del(pos); }
832 pos = GetNode(DstNId).InNIdV.SearchBin(SrcNId);
833 if (pos != -1) { GetNode(DstNId).InNIdV.Del(pos); }
835 pos = GetNIdPos(GetNode(DstNId).OutNIdV, SrcNId);
836 if (pos != -1) { GetNode(DstNId).OutNIdV.Del(pos); }
837 pos = GetNode(SrcNId).InNIdV.SearchBin(DstNId);
838 if (pos != -1) { GetNode(SrcNId).InNIdV.Del(pos); }
842 template <
class TNodeData,
class TEdgeData>
844 if (! IsNode(SrcNId) || ! IsNode(DstNId)) {
return false; }
845 if (IsDir) {
return GetNode(SrcNId).IsOutNId(DstNId); }
846 else {
return GetNode(SrcNId).IsOutNId(DstNId) || GetNode(DstNId).IsOutNId(SrcNId); }
849 template <
class TNodeData,
class TEdgeData>
851 IAssertR(IsNode(SrcNId) && IsNode(DstNId),
TStr::Fmt(
"%d or %d not a node.", SrcNId, DstNId).CStr());
852 IAssertR(IsEdge(SrcNId, DstNId),
TStr::Fmt(
"Edge between %d and %d does not exist.", SrcNId, DstNId).CStr());
853 GetEDat(SrcNId, DstNId) = EdgeDat;
856 template <
class TNodeData,
class TEdgeData>
858 if (! IsEdge(SrcNId, DstNId)) {
return false; }
859 const TNode& N = GetNode(SrcNId);
864 template <
class TNodeData,
class TEdgeData>
866 Assert(IsEdge(SrcNId, DstNId));
867 TNode& N = GetNode(SrcNId);
871 template <
class TNodeData,
class TEdgeData>
873 Assert(IsEdge(SrcNId, DstNId));
874 const TNode& N = GetNode(SrcNId);
878 template <
class TNodeData,
class TEdgeData>
880 for (
TEdgeI EI = BegEI(); EI < EndEI(); EI++) {
885 template <
class TNodeData,
class TEdgeData>
887 const TNodeI SrcNI = GetNI(SrcNId);
891 int LValN=0, RValN=NIdDatV.
Len()-1;
892 while (RValN>=LValN){
893 int ValN=(LValN+RValN)/2;
894 if (DstNId==NIdDatV[ValN].Val1){ NodeN=ValN;
break; }
895 if (DstNId<NIdDatV[ValN].Val1){RValN=ValN-1;}
else {LValN=ValN+1;}
897 if (NodeN == -1) {
return EndEI(); }
898 else {
return TEdgeI(SrcNI, EndNI(), NodeN); }
901 template <
class TNodeData,
class TEdgeData>
904 for (
int N=NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
905 NIdV.
Add(NodeH.GetKey(N)); }
908 template <
class TNodeData,
class TEdgeData>
910 for (
int n = NodeH.FFirstKeyId(); NodeH.FNextKeyId(n);) {
911 TNode& Node = NodeH[n];
914 if (! OnlyNodeLinks && ! NodeH.IsKeyIdEqKeyN()) {
919 template <
class TNodeData,
class TEdgeData>
922 for (
int N = NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
923 const TNode& Node = NodeH[N];
925 const TStr Msg =
TStr::Fmt(
"Out-neighbor list of node %d is not sorted.", Node.
GetId());
929 const TStr Msg =
TStr::Fmt(
"In-neighbor list of node %d is not sorted.", Node.
GetId());
934 for (
int e = 0; e < Node.
GetOutDeg(); e++) {
936 const TStr Msg =
TStr::Fmt(
"Out-edge %d --> %d: node %d does not exist.",
940 if (e > 0 && prevNId == Node.
GetOutNId(e)) {
941 const TStr Msg =
TStr::Fmt(
"Node %d has duplidate out-edge %d --> %d.",
949 for (
int e = 0; e < Node.
GetInDeg(); e++) {
951 const TStr Msg =
TStr::Fmt(
"In-edge %d <-- %d: node %d does not exist.",
955 if (e > 0 && prevNId == Node.
GetInNId(e)) {
956 const TStr Msg =
TStr::Fmt(
"Node %d has duplidate in-edge %d <-- %d.",
977 template <
class TNodeData,
class TEdgeData>
1020 TEdge(
const int& EId,
const int& SourceNId,
const int& DestNId,
const TEdgeData& EdgeData) :
Id(EId),
SrcNId(SourceNId),
DstNId(DestNId),
EdgeDat(EdgeData) { }
1070 bool IsInNId(
const int& NId)
const;
1072 bool IsOutNId(
const int& NId)
const;
1184 int AddNode(
int NId,
const TNodeData& NodeDat);
1186 int AddNode(
const TNodeI& NodeId) {
return AddNode(NodeId.GetId(), NodeId.GetDat()); }
1202 void SetNDat(
const int& NId,
const TNodeData& NodeDat);
1221 int AddEdge(
const int& SrcNId,
const int& DstNId,
int EId = -1);
1228 int AddEdge(
const int& SrcNId,
const int& DstNId,
int EId,
const TEdgeData& EdgeDat);
1230 int AddEdge(
const TEdgeI& EdgeI) {
return AddEdge(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), EdgeI.GetId(), EdgeI.GetDat()); }
1238 void DelEdge(
const int& SrcNId,
const int& DstNId,
const bool& IsDir =
true);
1242 bool IsEdge(
const int& SrcNId,
const int& DstNId,
const bool& IsDir =
true)
const {
int EId;
return IsEdge(SrcNId, DstNId, EId, IsDir); }
1244 bool IsEdge(
const int& SrcNId,
const int& DstNId,
int& EId,
const bool& IsDir =
true)
const;
1245 int GetEId(
const int& SrcNId,
const int& DstNId)
const {
int EId;
return IsEdge(SrcNId, DstNId, EId)?EId:-1; }
1253 TEdgeI
GetEI(
const int& SrcNId,
const int& DstNId)
const {
return GetEI(
GetEId(SrcNId, DstNId)); }
1255 void SetEDat(
const int& EId,
const TEdgeData& EdgeDat);
1281 void Reserve(
const int& Nodes,
const int& Edges) {
1282 if (Nodes>0) {
NodeH.
Gen(Nodes/2); }
if (Edges>0) {
EdgeH.
Gen(Edges/2); } }
1297 void Defrag(
const bool& OnlyNodeLinks=
false);
1302 bool IsOk(
const bool& ThrowExcept=
true)
const;
1315 template <
class TNodeData,
class TEdgeData>
1320 template <
class TNodeData,
class TEdgeData>
1323 for (
int edge = 0; edge < Node.
GetInDeg(); edge++) {
1330 template <
class TNodeData,
class TEdgeData>
1333 for (
int edge = 0; edge < Node.
GetOutDeg(); edge++) {
1334 if (NId == Net->GetEdge(Node.
GetOutEId(edge)).GetDstNId())
1340 template <
class TNodeData,
class TEdgeData>
1352 template <
class TNodeData,
class TEdgeData>
1364 template <
class TNodeData,
class TEdgeData>
1367 for (
int out = 0; out < Node.
GetOutDeg(); out++) {
1374 for (
int in = 0; in < Node.
GetInDeg(); in++) {
1384 template <
class TNodeData,
class TEdgeData>
1390 template <
class TNodeData,
class TEdgeData>
1394 const int Src = EI.GetSrcNId();
1395 const int Dst = EI.GetDstNId();
1399 return UniqESet.
Len();
1402 template <
class TNodeData,
class TEdgeData>
1414 template <
class TNodeData,
class TEdgeData>
1426 template <
class TNodeData,
class TEdgeData>
1436 template <
class TNodeData,
class TEdgeData>
1445 template <
class TNodeData,
class TEdgeData>
1447 if (!
IsNode(SrcNId)) {
return false; }
1448 if (!
IsNode(DstNId)) {
return false; }
1450 for (
int edge = 0; edge < SrcNode.
GetOutDeg(); edge++) {
1453 EId = Edge.
GetId();
return true; }
1456 for (
int edge = 0; edge < SrcNode.
GetInDeg(); edge++) {
1459 EId = Edge.
GetId();
return true; }
1465 template <
class TNodeData,
class TEdgeData>
1471 template <
class TNodeData,
class TEdgeData>
1479 template <
class TNodeData,
class TEdgeData>
1487 template <
class TNodeData,
class TEdgeData>
1495 template <
class TNodeData,
class TEdgeData>
1505 template <
class TNodeData,
class TEdgeData>
1520 for (
int e = 0; e < Node.
GetOutDeg(); e++) {
1525 if (e > 0 && prevEId == Node.
GetOutEId(e)) {
1533 for (
int e = 0; e < Node.
GetInDeg(); e++) {
1538 if (e > 0 && prevEId == Node.
GetInEId(e)) {
1597 TNode() : Id(-1), InEIdV(), OutEIdV() { }
1598 TNode(
const int& NId) : Id(NId), InEIdV(), OutEIdV() { }
1599 TNode(
const TNode& Node) : Id(Node.Id), InEIdV(Node.InEIdV), OutEIdV(Node.OutEIdV) { }
1601 void Save(
TSOut& SOut)
const { Id.Save(SOut); InEIdV.Save(SOut); OutEIdV.Save(SOut); }
1603 int GetDeg()
const {
return GetInDeg() + GetOutDeg(); }
1606 int GetInEId(
const int& EdgeN)
const {
return InEIdV[EdgeN]; }
1607 int GetOutEId(
const int& EdgeN)
const {
return OutEIdV[EdgeN]; }
1608 int GetNbrEId(
const int& EdgeN)
const {
return EdgeN<GetOutDeg()?GetOutEId(EdgeN):GetInEId(EdgeN-GetOutDeg()); }
1609 bool IsInEId(
const int& EId)
const {
return InEIdV.SearchBin(EId) != -1; }
1610 bool IsOutEId(
const int& EId)
const {
return OutEIdV.SearchBin(EId) != -1; }
1617 TEdge() : Id(-1), SrcNId(-1), DstNId(-1) { }
1618 TEdge(
const int& EId,
const int& SourceNId,
const int& DestNId) : Id(EId), SrcNId(SourceNId), DstNId(DestNId) { }
1619 TEdge(
const TEdge& Edge) : Id(Edge.Id), SrcNId(Edge.SrcNId), DstNId(Edge.DstNId) { }
1621 void Save(
TSOut& SOut)
const { Id.Save(SOut); SrcNId.Save(SOut); DstNId.Save(SOut); }
1639 TNodeI& operator++ (
int) { NodeHI++;
return *
this; }
1640 bool operator < (
const TNodeI& NodeI)
const {
return NodeHI < NodeI.
NodeHI; }
1641 bool operator == (
const TNodeI& NodeI)
const {
return NodeHI == NodeI.
NodeHI; }
1643 int GetId()
const {
return NodeHI.GetDat().GetId(); }
1645 int GetDeg()
const {
return NodeHI.GetDat().GetDeg(); }
1647 int GetInDeg()
const {
return NodeHI.GetDat().GetInDeg(); }
1649 int GetOutDeg()
const {
return NodeHI.GetDat().GetOutDeg(); }
1653 int GetInNId(
const int& EdgeN)
const {
return Graph->GetEdge(NodeHI.GetDat().GetInEId(EdgeN)).GetSrcNId(); }
1657 int GetOutNId(
const int& EdgeN)
const {
return Graph->GetEdge(NodeHI.GetDat().GetOutEId(EdgeN)).GetDstNId(); }
1663 bool IsInNId(
const int& NId)
const;
1665 bool IsOutNId(
const int& NId)
const;
1667 bool IsNbrNId(
const int& NId)
const {
return IsOutNId(NId) || IsInNId(NId); }
1669 int GetInEId(
const int& EdgeN)
const {
return NodeHI.GetDat().GetInEId(EdgeN); }
1671 int GetOutEId(
const int& EdgeN)
const {
return NodeHI.GetDat().GetOutEId(EdgeN); }
1673 int GetNbrEId(
const int& EdgeN)
const {
return NodeHI.GetDat().GetNbrEId(EdgeN); }
1675 bool IsInEId(
const int& EId)
const {
return NodeHI.GetDat().IsInEId(EId); }
1677 bool IsOutEId(
const int& EId)
const {
return NodeHI.GetDat().IsOutEId(EId); }
1679 bool IsNbrEId(
const int& EId)
const {
return IsInEId(EId) || IsOutEId(EId); }
1710 TEdgeI& operator++ (
int) { EdgeHI++;
return *
this; }
1711 bool operator < (
const TEdgeI& EdgeI)
const {
return EdgeHI < EdgeI.
EdgeHI; }
1712 bool operator == (
const TEdgeI& EdgeI)
const {
return EdgeHI == EdgeI.
EdgeHI; }
1714 int GetId()
const {
return EdgeHI.GetDat().GetId(); }
1716 int GetSrcNId()
const {
return EdgeHI.GetDat().GetSrcNId(); }
1718 int GetDstNId()
const {
return EdgeHI.GetDat().GetDstNId(); }
1748 TAIntI(
const TIntVecIter& HIter,
TStr attribute,
bool isEdgeIter,
const TNEANet* GraphPt) : HI(HIter), attr(), Graph(GraphPt) { isNode = !isEdgeIter; attr = attribute; }
1751 bool operator < (
const TAIntI& I)
const {
return HI < I.
HI; }
1752 bool operator == (
const TAIntI& I)
const {
return HI == I.
HI; }
1756 bool IsDeleted()
const {
return isNode ? GetDat() == Graph->GetIntAttrDefaultN(attr) : GetDat() == Graph->GetIntAttrDefaultE(attr); };
1771 TAStrI(
const TStrVecIter& HIter,
TStr attribute,
bool isEdgeIter,
const TNEANet* GraphPt) : HI(HIter), attr(), Graph(GraphPt) { isNode = !isEdgeIter; attr = attribute; }
1774 bool operator < (
const TAStrI& I)
const {
return HI < I.
HI; }
1775 bool operator == (
const TAStrI& I)
const {
return HI == I.
HI; }
1779 bool IsDeleted()
const {
return isNode ? GetDat() == Graph->GetStrAttrDefaultN(attr) : GetDat() == Graph->GetStrAttrDefaultE(attr); };
1794 TAFltI(
const TFltVecIter& HIter,
TStr attribute,
bool isEdgeIter,
const TNEANet* GraphPt) : HI(HIter), attr(), Graph(GraphPt) { isNode = !isEdgeIter; attr = attribute; }
1797 bool operator < (
const TAFltI& I)
const {
return HI < I.
HI; }
1798 bool operator == (
const TAFltI& I)
const {
return HI == I.
HI; }
1802 bool IsDeleted()
const {
return isNode ? GetDat() == Graph->GetFltAttrDefaultN(attr) : GetDat() == Graph->GetFltAttrDefaultE(attr); };
2056 int AddEdge(
const int& SrcNId,
const int& DstNId,
int EId = -1);
2066 void DelEdge(
const int& SrcNId,
const int& DstNId,
const bool& IsDir =
true);
2070 bool IsEdge(
const int& SrcNId,
const int& DstNId,
const bool& IsDir =
true)
const {
int EId;
return IsEdge(SrcNId, DstNId, EId, IsDir); }
2072 bool IsEdge(
const int& SrcNId,
const int& DstNId,
int& EId,
const bool& IsDir =
true)
const;
2074 int GetEId(
const int& SrcNId,
const int& DstNId)
const {
int EId;
return IsEdge(SrcNId, DstNId, EId)?EId:-1; }
2106 void Reserve(
const int& Nodes,
const int& Edges) {
2107 if (Nodes>0) {
NodeH.
Gen(Nodes/2); }
if (Edges>0) {
EdgeH.
Gen(Edges/2); } }
2114 void Defrag(
const bool& OnlyNodeLinks=
false);
2119 bool IsOk(
const bool& ThrowExcept=
true)
const;
2121 void Dump(FILE *OutF=stdout)
const;
int GetNbrEId(const int &EdgeN) const
int AddEdge(const TEdgeI &EdgeI)
Adds an edge from EdgeI.GetSrcNId() to EdgeI.GetDstNId() to the network.
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
TEdgeI GetEI(const int &EId) const
Not supported/implemented!
TEdgeDat & GetOutEDat(const int &EdgeN)
static int GetNIdPos(const TVec< TPair< TInt, TEdgeData > > &NIdV, const int &NId)
TVec< TIntV > VecOfIntVecsN
TNEANet(TSIn &SIn)
Constructor for loading the graph from a (binary) stream SIn.
bool IsNbrNId(const int &NId) const
Tests whether node with ID NId is a neighbor of the current node.
TEdgeI(const THashIter &EdgeHIter, const TNodeEdgeNet *NetPt)
static const T & Mn(const T &LVal, const T &RVal)
TNodeI & operator++(int)
Increment iterator.
TNodeNet(const TNodeNet &NodeNet)
TNodeI(const THashIter &NodeHIter, const TNodeNet *NetPt)
TPair< TInt, TInt > TIntPr
Tests (at compile time) if the graph is a network with data on nodes.
int AddIntAttrDatE(const TEdgeI &EdgeId, const TInt &value, const TStr &attr)
Attribute based add function for attr to Int value.
TNodeData & GetOutNDat(const int &EdgeN)
bool IsDeleted() const
Returns true if the attribute has been deleted.
bool IsOutNId(const int &NId) const
int GetRndNId(TRnd &Rnd=TInt::Rnd)
Returns an ID of a random node in the graph.
bool DelIfIn(const TVal &Val)
Removes the first occurrence of element Val.
void Clr()
Deletes all nodes and edges from the network.
int GetInEId(const int &EdgeN) const
Returns ID of EdgeN-th in-edge.
const TNodeData & GetInNDat(const int &EdgeN) const
int GetNbrEId(const int &EdgeN) const
Returns ID of EdgeN-th in or out-edge.
int GetNodes() const
Returns the number of nodes in the graph.
TPt< TIntNEDNet > PIntNEDNet
const TEdgeDat & GetOutEDat(const int &EdgeN) const
void SetNDat(const int &NId, const TNodeData &NodeDat)
Sets node data for the node of ID NId in the network.
bool IsKeyIdEqKeyN() const
TPt< TIntFltNEDNet > PIntFltNEDNet
void SortEIdByDat(const bool &Asc=true)
Sorts edges by edge data.
#define IAssertR(Cond, Reason)
int GetOutNId(const int &EdgeN) const
Returns ID of EdgeN-th out-node (the node the current node points to).
int AddStrAttrDatN(const TNodeI &NodeId, const TStr &value, const TStr &attr)
Attribute based add function for attr to Str value.
THash< TStr, TFlt > FltDefaultsE
virtual void Save(TSOut &SOut) const
Saves the network to a (binary) stream SOut.
int GetDeg() const
Returns degree of the current node.
TNode(const int &NId, const TNodeData &NodeData)
int GetOutNId(const int &EdgeN) const
Returns ID of EdgeN-th out-node (the node the current node points to).
TNode & GetNode(const int &NId)
TAStrI GetNAStrI(const TStr &attr, const int &NId) const
Returns an iterator referring to the node of ID NId in the graph.
TStr GetEdgeAttrValue(const int &EId, const TStrIntPrH::TIter &EdgeHI) const
int GetOutDeg() const
Returns out-degree of the current node.
TEdgeI(const TNodeI &NodeI, const TNodeI &EndNodeI, const int &EdgeN=0)
int DelAttrDatN(const TNodeI &NodeId, const TStr &attr)
Deletes the node attribute for NodeId.
TEdgeI BegEI() const
Returns an iterator referring to the first edge in the network.
const TNodeData & GetNDat(const int &NId) const
Returns node data for the node of ID NId in the network.
const TNodeData & GetDat() const
TVec< TStrV > VecOfStrVecsE
TStr GetStrAttrDatE(const TEdgeI &EdgeId, const TStr &attr)
Gets the value of str attr from the edge attr value vector.
THash< TStr, TInt > IntDefaultsE
int GetInNId(const int &EdgeN) const
Returns ID of EdgeN-th in-node (the node pointing to the current node).
void Save(TSOut &SOut) const
TNodeEDatNet & operator=(const TNodeEDatNet &NodeNet)
const TNodeData & operator()() const
int GetIntAttrIndN(const TStr &attr)
Gets the index of the node attr value vector specified by str attr.
void Save(TSOut &SOut) const
bool NodeAttrIsStrDeleted(const int &NId, const TStrIntPrH::TIter &NodeHI) const
int DelAttrN(const TStr &attr)
Removes all the values for node attr.
int GetInNId(const int &NodeN) const
Returns ID of NodeN-th in-node (the node pointing to the current node).
int AddEdge(const TEdgeI &EdgeI)
Adds an edge from EdgeI.GetSrcNId() to EdgeI.GetDstNId() and its edge data to the network...
bool NodeAttrIsDeleted(const int &NId, const TStrIntPrH::TIter &NodeHI) const
void SortNIdById(const bool &Asc=true)
Sorts nodes by node IDs.
int AddNode(const TNodeI &NodeId)
Adds a node NodeId and its node data to the network.
bool Empty() const
Tests whether the network is empty (has zero nodes).
int GetInNId(const int &NodeN) const
void Reserve(const int &Nodes, const int &Edges)
Reserves memory for a network of Nodes nodes and Edges edges.
TEdgeI GetEI(const int &EId) const
Returns an iterator referring to edge with edge ID EId.
void DelNode(const int &NId)
Deletes node of ID NId from the network.
int GetEdges() const
Returns the number of edges in the network.
void DelEdge(const int &SrcNId, const int &DstNId, const bool &IsDir=true)
Deletes an edge from node IDs SrcNId to DstNId from the network.
int AddEdge(const TEdgeI &EdgeI)
Adds an edge between EdgeI.GetSrcNId() and EdgeI.GetDstNId() to the graph.
bool operator<(const TEdgeI &EdgeI) const
const TNode & GetNode(const int &NId) const
Returns node element for the node of ID NId in the network.
bool IsNbrEId(const int &EId) const
TEdgeI(const THashIter &EdgeHIter, const TNEANet *GraphPt)
TPt< TStrIntNEDNet > PStrIntNEDNet
THash< TInt, TNode >::TIter THashIter
TNodeData & GetNDat(const int &NId)
Returns node data for the node of ID NId in the network.
void Del(const TSizeTy &ValN)
Removes the element at position ValN.
TEdgeI EndEI() const
Returns an iterator referring to the past-the-end edge in the network.
void AttrNameEI(const TInt &EId, TStrV &Names) const
Returns a vector of attr names for edge EId.
static const T & Mx(const T &LVal, const T &RVal)
void SortNIdByDat(const bool &Asc=true)
Sorts nodes by node data.
TNodeData & GetOutNDat(const int &NodeN)
TInt GetIntAttrDatN(const TNodeI &NodeId, const TStr &attr)
Gets the value of int attr from the node attr value vector.
void GetNIdV(TIntV &NIdV) const
Returns a vector of all node IDs in the network.
int AddFltAttrDatN(const TNodeI &NodeId, const TFlt &value, const TStr &attr)
Attribute based add function for attr to Flt value.
const TNodeData & GetDat() const
void Save(TSOut &SOut) const
static PNEANet Load(TSIn &SIn)
Static constructor that loads the graph from a stream SIn and returns a pointer to it...
TEdgeData & GetInEDat(const int &EdgeN)
TNode & GetNode(const int &NId)
TNodeI BegNI() const
Returns an iterator referring to the first node in the network.
void StrAttrNameNI(const TInt &NId, TStrV &Names) const
Returns a vector of str attr names for node NId.
TNodeI(const TNodeI &NodeI)
void DelNode(const TNode &NodeI)
Deletes node of ID NodeI.GetId() from the network.
void FltAttrNameNI(const TInt &NId, TStrV &Names) const
Returns a vector of int attr names for node NId.
bool IsInEId(const int &EId) const
Tests whether the edge with ID EId is an in-edge of current node.
TNodeI(const THashIter &NodeHIter, const TNodeEdgeNet *NetPt)
bool operator<(const TNodeI &NodeI) const
int AddNode(int NId=-1)
Adds a node of ID NId to the network.
bool EdgeAttrIsFltDeleted(const int &EId, const TStrIntPrH::TIter &EdgeHI) const
bool IsOutNId(const int &NId) const
const TNodeData & GetOutNDat(const int &EdgeN) const
TInt GetIntAttrDefaultE(const TStr &attribute) const
Get Int edge attribute val. If not a proper attr, return default.
bool IsNbrNId(const int &NId) const
Tests whether node with ID NId is a neighbor of the current node.
bool EdgeAttrIsDeleted(const int &EId, const TStrIntPrH::TIter &EdgeHI) const
TNodeI(const TNodeI &NodeI)
TNodeEdgeNet< TFlt, TFlt > TFltNENet
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.
bool operator<(const TEdgeI &EdgeI) const
TNodeEDatNet(const int &Nodes, const int &Edges)
Constructor that reserves enough memory for a network of Nodes nodes and Edges edges.
THash< TInt, TNode >::TIter THashIter
TPt< TIntNENet > PIntNENet
void DelEdge(const int &SrcNId, const int &DstNId, const bool &IsDir=true)
Deletes an edge from node IDs SrcNId to DstNId from the network.
Tests (at compile time) if the graph is directed.
int GetInNId(const int &EdgeN) const
Returns ID of EdgeN-th in-node (the node pointing to the current node).
bool operator<(const TNodeI &NodeI) const
const TEdge & GetEdgeKId(const int &EdgeKeyId) const
const TNode & GetNode(const int &NId) const
bool IsInNId(const int &NId) const
Tests whether node with ID NId points to the current node.
TSizeTy Len() const
Returns the number of elements in the vector.
TNodeI GetRndNI(TRnd &Rnd=TInt::Rnd)
Returns an interator referring to a random node in the network.
void GetFltAttrVal(TFltV &Val) const
Gets vector of flt attribute values.
TEdgeI(const TEdgeI &EdgeI)
bool EdgeAttrIsIntDeleted(const int &EId, const TStrIntPrH::TIter &EdgeHI) const
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.
bool operator<(const TNode &Node) const
void Save(TSOut &SOut) const
int GetMxNId() const
Returns an ID that is larger than any node ID in the network.
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
TEdge(const int &EId, const int &SourceNId, const int &DestNId, const TEdgeData &EdgeData)
int DelAttrE(const TStr &attr)
Removes all the values for edge attr.
TNodeEdgeNet(const TNodeEdgeNet &Net)
void StrAttrValueNI(const TInt &NId, TStrV &Values) const
Returns a vector of attr values for node NId.
static PNet New()
Static constructor that returns a pointer to the network. Call: TPt > Net = TNod...
const TNodeData & GetInNDat(const int &NodeN) const
int GetNodes() const
Returns the number of nodes in the network.
TNodeI & operator++(int)
Increment iterator.
TStrIntPrH KeyToIndexTypeE
const TNodeData & GetInNDat(const int &NodeN) const
TEdgeData & GetOutEDat(const int &EdgeN)
Edge iterator. Only forward iteration (operator++) is supported.
void SetAllEDat(const TEdgeData &EdgeDat)
Sets edge data for all the edges in the network to EDat.
bool IsInNId(const int &NId) const
TNodeI & operator=(const TNodeI &NodeI)
TEdgeI GetEI(const int &SrcNId, const int &DstNId) const
Returns an iterator referring to edge (SrcNId, DstNId) in the graph.
TNodeI EndNI() const
Returns an iterator referring to the past-the-end node in the network.
TNodeI(const TNodeI &NodeI)
int GetEdges() const
Returns the number of edges in the network.
int GetRndEId(TRnd &Rnd=TInt::Rnd)
Returns an ID of a random edge in the graph.
bool IsOutEId(const int &EId) const
Tests whether the edge with ID EId is an out-edge of current node.
int GetOutEId(const int &EdgeN) const
Returns ID of EdgeN-th out-edge.
TInt GetIntAttrIndDatN(const TNodeI &NodeId, const int &index)
Gets the value of node int attr specified by the attr index.
THash< TInt, TNode > NodeH
TStr GetDat() const
Returns an attribute of the node.
int GetOutNId(const int &NodeN) const
TNodeData & GetNbrNDat(const int &NodeN)
TNodeI & operator++(int)
Increment iterator.
TInt GetDat() const
Returns an attribute of the node.
bool IsNbrNId(const int &NId) const
THash< TStr, TFlt > FltDefaultsN
void SortNIdById(const bool &Asc=true)
Sorts nodes by node IDs.
TEdgeI GetRndEI(TRnd &Rnd=TInt::Rnd)
Returns an interator referring to a random edge in the graph.
const TEdge & GetEdge(const int &EId) const
bool IsEdge(const int &EId) const
Tests whether an edge with edge ID EId exists in the graph.
const TNodeData & GetNbrNDat(const int &NodeN) const
int GetUniqEdges(const bool &IsDir=true) const
Returns the number of edges in the network with a unique pair of nodes.
TNodeEDatNet< TInt, TFlt > TIntFltNEDNet
int AddNode(int NId=-1)
Adds a node of ID NId to the network.
TNodeData & GetNbrNDat(const int &EdgeN)
TNodeData & GetInNDat(const int &NodeN)
void IntAttrValueEI(const TInt &EId, TIntV &Values) const
Returns a vector of attr values for edge EId.
int AddNode(const TNodeI &NodeId)
Adds a node NodeId and its node data to the network.
TEdgeI GetEI(const int &EId) const
Not supported/implemented!
int GetNbrNId(const int &EdgeN) const
Returns ID of EdgeN-th neighboring node.
TNodeData & GetNDat(const int &NId)
Returns node data for the node of ID NId in the network.
TFlt GetDat() const
Returns an attribute of the node.
TNodeData & GetNDat(const int &NId)
Returns node data for the node of ID NId in the network.
bool IsOutEId(const int &EId) const
TAIntI BegNAIntI(const TStr &attr) const
Returns an iterator referring to the first node's int attribute.
const TDat & GetDat(const TKey &Key) const
Node iterator. Only forward iteration (operator++) is supported.
Node/edge integer attribute iterator. Iterates through all nodes/edges for one integer attribute...
int GetInNId(const int &EdgeN) const
void AttrValueNI(const TInt &NId, TStrV &Values) const
Returns a vector of attr values for node NId.
int GetSrcNId() const
Gets the source node of an edge.
void GetStrAttrNames(TStrV &Names) const
Gets vector of str attribute names.
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.
TVec< TIntV > VecOfIntVecsE
void Defrag(const bool &OnlyNodeLinks=false)
Defragments the network.
TNodeI & operator=(const TNodeI &NodeI)
const TEdgeData & GetInEDat(const int &EdgeN) const
bool IsNbrEId(const int &EId) const
Tests whether the edge with ID EId is an in or out-edge of current node.
void IntAttrNameNI(const TInt &NId, TStrV &Names) const
Returns a vector of int attr names for node NId.
int GetSrcNId() const
Gets the source node of an edge.
TNodeI GetRndNI(TRnd &Rnd=TInt::Rnd)
Returns an interator referring to a random node in the network.
int GetNodes() const
Returns the number of nodes in the network.
bool IsNbrNId(const int &NId) const
TEdgeI GetEI(const int &EId) const
Not supported/implemented!
TAFltI GetEAFltI(const TStr &attr, const int &EId) const
Returns an iterator referring to the edge of ID EId in the graph.
TNodeI BegNI() const
Returns an iterator referring to the first node in the network.
int GetNbrEId(const int &EdgeN) const
bool IsDeleted() const
Returns true if the attribute has been deleted.
int GetInDeg() const
Returns in-degree of the current node.
TAFltI BegEAFltI(const TStr &attr) const
Returns an iterator referring to the first edge's flt attribute.
void SetNDat(const int &NId, const TNodeData &NodeDat)
Sets node data for the node of ID NId in the network.
TAStrI GetEAStrI(const TStr &attr, const int &EId) const
Returns an iterator referring to the edge of ID EId in the graph.
Node/edge float attribute iterator. Iterates through all nodes/edges for one float attribute...
TInt GetIntAttrDatE(const TEdgeI &EdgeId, const TStr &attr)
Gets the value of int attr from the edge attr value vector.
Node Edge Network (directed multigraph, TNEGraph with data on nodes and edges).
int GetId() const
Returns edge ID.
int AddStrAttrDatE(const TEdgeI &EdgeId, const TStr &value, const TStr &attr)
Attribute based add function for attr to Str value.
int GetOutNId(const int &EdgeN) const
TSizeTy AddSorted(const TVal &Val, const bool &Asc=true, const TSizeTy &_MxVals=-1)
Adds element Val to a sorted vector.
void ErrNotify(const char *NotifyCStr)
TNodeEDatNet< TInt, TInt > TIntNEDNet
bool IsOutEId(const int &EId) const
TAIntI BegEAIntI(const TStr &attr) const
Returns an iterator referring to the first edge's int attribute.
virtual void Save(TSOut &SOut) const
Saves the network to a (binary) stream SOut.
const TNodeData & GetNDat(const int &NId) const
Returns node data for the node of ID NId in the network.
bool operator==(const TEdgeI &EdgeI) const
TEdge(const int &EId, const int &SourceNId, const int &DestNId)
TVec< TStrV > VecOfStrVecsN
void GetStrAttrVal(TStrV &Val) const
Gets vector of str attribute values.
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
TNodeEDatNet(const TNodeEDatNet &NodeNet)
int GetNbrNId(const int &NodeN) const
Returns ID of NodeN-th neighboring node.
void Save(TSOut &SOut) const
TEdgeI & operator++(int)
Increment iterator.
TNodeI GetNI(const int &NId) const
Returns an iterator referring to the node of ID NId in the network.
int AddEdge(const int &SrcNId, const int &DstNId, int EId=-1)
Adds an edge between node IDs SrcNId and DstNId to the graph.
int GetDeg() const
Returns degree of the current node, the sum of in-degree and out-degree.
void Dump(FILE *OutF=stdout) const
Print the graph in a human readable form to an output stream OutF.
int GetInEId(const int &EdgeN) const
Returns ID of EdgeN-th in-edge.
bool NodeAttrIsFltDeleted(const int &NId, const TStrIntPrH::TIter &NodeHI) const
int GetInDeg() const
Returns in-degree of the current node.
bool IsOutNId(const int &NId) const
Tests whether the current node points to node with ID NId.
THash< TInt, TEdge > EdgeH
static PNet New()
Static constructor that returns a pointer to the network. Call: TPt > Net = TNodeEDatNet::New().
TAIntI GetEAIntI(const TStr &attr, const int &EId) const
Returns an iterator referring to the edge of ID EId in the graph.
const TNodeData & GetSrcNDat() const
TAStrI EndEAStrI(const TStr &attr) const
Returns an iterator referring to the past-the-end edge's attribute.
int GetDstNId() const
Returns the destination of the edge.
TNode(const int &NId, const TNodeData &NodeData)
const TEdgeData & GetOutEDat(const int &EdgeN) const
bool operator==(const TNodeI &NodeI) const
bool operator==(const TEdgeI &EdgeI) const
TEdgeI(const TEdgeI &EdgeI)
TAStrI BegEAStrI(const TStr &attr) const
Returns an iterator referring to the first edge's str attribute.
void DelNode(const int &NId)
Deletes node of ID NId from the network.
int AddEdge(const int &SrcNId, const int &DstNId)
Adds an edge from node IDs SrcNId to node DstNId to the network.
const TNodeData & GetDat() const
TNodeData & GetInNDat(const int &EdgeN)
TAStrI EndNAStrI(const TStr &attr) const
Returns an iterator referring to the past-the-end node's attribute.
void Save(TSOut &SOut) const
TEdgeI(const TNodeI &NodeI, const TNodeI &EndNodeI, const int &EdgeN=0)
TNodeData & GetInNDat(const int &NodeN)
THash< TInt, TNode > NodeH
void DelKey(const TKey &Key)
Edge iterator. Only forward iteration (operator++) is supported.
TAIntI EndNAIntI(const TStr &attr) const
Returns an iterator referring to the past-the-end node's attribute.
Edge iterator. Only forward iteration (operator++) is supported.
int GetId() const
Returns ID of the current node.
void GetStrAttrVal(TStrV &Val) const
Gets vector of str attribute values.
int AddIntAttrDatN(const TNodeI &NodeId, const TInt &value, const TStr &attr)
Attribute based add function for attr to Int value.
bool IsOutEId(const int &EId) const
Tests whether the edge with ID EId is an out-edge of current node.
TAIntI EndEAIntI(const TStr &attr) const
Returns an iterator referring to the past-the-end edge's attribute.
int GetOutDeg() const
Returns out-degree of the current node.
TAFltI BegNAFltI(const TStr &attr) const
Returns an iterator referring to the first node's flt attribute.
void Clr(const bool &DoDel=true, const bool &ResetDat=true)
Deletes all nodes and edges from the network.
const TNodeData & GetDat() const
Node Edge Network (directed graph, TNGraph with data on nodes and edges).
TVec< TFltV > VecOfFltVecsE
TNode & GetNode(const int &NId)
TStrIntPrH KeyToIndexTypeN
KeyToIndexType[N|E]: Key->(Type,Index).
TAFltI EndNAFltI(const TStr &attr) const
Returns an iterator referring to the past-the-end node's attribute.
TNodeI GetNI(const int &NId) const
Returns an iterator referring to the node of ID NId in the network.
virtual void Save(TSOut &SOut) const
Saves the network to a (binary) stream SOut.
void Gen(const int &ExpectVals)
void StrAttrValueEI(const TInt &EId, TStrV &Values) const
Returns a vector of attr values for node NId.
#define HasGraphFlag(TGraph, Flag)
For quick testing of the properties of the graph/network object (see TGraphFlag). ...
TNode & GetNode(const int &NId)
TEdgeI BegEI() const
Returns an iterator referring to the first edge in the network.
Tests (at compile time) if the graph is a network with data on edges.
TAIntI(const TIntVecIter &HIter, TStr attribute, bool isEdgeIter, const TNEANet *GraphPt)
bool Empty() const
Tests whether the network is empty (has zero nodes).
int GetInNId(const int &NodeN) const
Returns ID of NodeN-th in-node (the node pointing to the current node).
void FltAttrValueEI(const TInt &EId, TFltV &Values) const
Returns a vector of attr values for node NId.
TEdgeDat & GetNbrEDat(const int &EdgeN)
static PNet Load(TSIn &SIn)
Static constructor that loads the network from a stream SIn and returns a pointer to it...
void SortNIdByDat(const bool &Asc=true)
Sorts nodes by node data.
int GetId() const
Gets edge ID. Always returns -1 since only edges in multigraphs have explicit IDs.
int GetNbrNId(const int &EdgeN) const
Returns ID of EdgeN-th neighboring node.
void Reserve(const int &Nodes, const int &Edges)
Reserves memory for a graph of Nodes nodes and Edges edges.
TEdgeI & operator=(const TEdgeI &EdgeI)
TEdgeI & operator++(int)
Increment iterator.
int AddEdge(const int &SrcNId, const int &DstNId)
Adds an edge from node IDs SrcNId to node DstNId to the network.
TEdgeI GetRndEI(TRnd &Rnd=TInt::Rnd)
Returns an interator referring to a random edge in the network.
int GetDstNId() const
Gets the destination node of an edge.
bool operator<(const TNode &Node) const
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.
int AddIntAttrN(const TStr &attr, TInt defaultValue=TInt::Mn)
Adds a new Int node attribute to the hashmap.
const TNodeData & GetDat() const
TStr GetStrAttrDefaultE(const TStr &attribute) const
Get Str edge attribute val. If not a proper attr, return default.
const TNodeData & GetSrcNDat() const
void SortNIdById(const bool &Asc=true)
Sorts nodes by node IDs.
TNEANet(const int &Nodes, const int &Edges)
Constructor that reserves enough memory for a graph of nodes and edges.
bool IsOutNId(const int &NId) const
Tests whether the current node points to node with ID NId.
int GetMxNId() const
Returns an ID that is larger than any node ID in the network.
bool FNextKeyId(int &KeyId) const
THash< TStr, TStr > StrDefaultsN
void AttrNameNI(const TInt &NId, TStrV &Names) const
Returns a vector of attr names for node NId.
const TEdgeData & GetDat() const
Tests (at compile time) if the graph is a multigraph with multiple edges between the same nodes...
THash< TInt, TNode > NodeH
void DelNode(const TNode &NodeI)
Deletes node of ID NodeI.GetId() from the graph.
TNodeNet(TSIn &SIn)
Constructor that loads the network from a (binary) stream SIn.
int AddStrAttrE(const TStr &attr, TStr defaultValue=TStr::GetNullStr())
Adds a new Str edge attribute to the hashmap.
TEdgeI BegEI() const
Returns an iterator referring to the first edge in the graph.
TNodeEDatNet(TSIn &SIn)
Constructor that loads the network from a (binary) stream SIn.
void SortNIdByDat(const bool &Asc=true)
Sorts nodes by node data.
const TNodeData & operator()() const
bool IsOk(const bool &ThrowExcept=true) const
Checks the network data structure for internal consistency.
TNodeEDatNet< TNodeData, TEdgeData > TNet
bool IsInNId(const int &NId) const
Tests whether node with ID NId points to the current node.
int AddKey(const TKey &Key)
int GetId() const
Gets edge ID. Always returns -1 since only edges in multigraphs have explicit IDs.
TAIntI GetNAIntI(const TStr &attr, const int &NId) const
Returns an iterator referring to the node of ID NId in the graph.
int GetOutEId(const int &EdgeN) const
Returns ID of EdgeN-th out-edge.
TEdgeI EndEI() const
Returns an iterator referring to the past-the-end edge in the graph.
bool HasFlag(const TGraphFlag &Flag) const
Allows for run-time checking the type of the network (see the TGraphFlag for flags).
int GetInDeg() const
Returns in-degree of the current node.
TNodeI(const THashIter &NodeHIter, const TNodeEDatNet *NetPt)
TVec< TPair< TInt, TEdgeData > > TNIdDatPrV
TStr GetStrAttrDefaultN(const TStr &attribute) const
Get Str node attribute val. If not a proper attr, return default.
int GetSrcNId() const
Returns the source of the edge.
TStr GetNodeAttrValue(const int &NId, const TStrIntPrH::TIter &NodeHI) const
const TNodeData & GetNDat(const int &NId) const
Returns node data for the node of ID NId in the network.
int GetRndNId(TRnd &Rnd=TInt::Rnd)
Returns an ID of a random node in the network.
Node iterator. Only forward iteration (operator++) is supported.
TNodeEdgeNet & operator=(const TNodeEdgeNet &Net)
void GetAttrVal(TStrV &Val) const
Gets vector of attribute values.
int GetRndNId(TRnd &Rnd=TInt::Rnd)
Returns an ID of a random node in the network.
bool IsInNId(const int &NId) const
THash< TInt, TEdge > EdgeH
void SetAllEDat(const TEdgeData &EdgeDat)
Sets edge data for all the edges in the network to EDat.
bool HasFlag(const TGraphFlag &Flag) const
Allows for run-time checking the type of the network (see the TGraphFlag for flags).
void AttrValueEI(const TInt &EId, TStrV &Values) const
Returns a vector of attr values for edge EId.
int GetOutDeg() const
Returns out-degree of the current node.
void FltAttrValueNI(const TInt &NId, TFltV &Values) const
Returns a vector of attr values for node NId.
Directed multigraph with node edge attributes.
bool operator==(const TEdgeI &EdgeI) const
TEdgeData & GetOutEDat(const int &EdgeN)
void GetAttrNames(TStrV &Names) const
Gets vector of attribute names.
void GetFltAttrVal(TFltV &Val) const
Gets vector of flt attribute values.
bool Empty() const
Tests whether the graph is empty (has zero nodes).
int AddFltAttrDatE(const TEdgeI &EdgeId, const TFlt &value, const TStr &attr)
Attribute based add function for attr to Flt value.
TInt GetIntAttrIndDatE(const TEdgeI &EdgeId, const int &index)
Gets the value of edge int attr specified by the attr index.
TSizeTy SearchBin(const TVal &Val) const
Returns the position of an element with value Val.
TAStrI BegNAStrI(const TStr &attr) const
Returns an iterator referring to the first node's str attribute.
void GetFltAttrNames(TStrV &Names) const
Gets vector of flt attribute names.
TNodeNet(const int &Nodes, const int &Edges)
Constructor that reserves enough memory for a network of Nodes nodes and Edges edges.
bool IsEdge(const int &EId) const
Tests whether an edge with ID EId exists in the network.
bool IsDeleted() const
Returns true if the attribute has been deleted.
const TNodeData & operator()() const
TEdgeData & GetEDat(const int &EId)
Returns edge data for the edge with ID EId.
int GetSrcNId() const
Gets the source of an edge.
bool IsInEId(const int &EId) const
static PNEANet GetSmallGraph()
Returns a small multigraph on 5 nodes and 6 edges.
void SortByKey(const bool &Asc=true)
void SetEDat(const int &EId, const TEdgeData &EdgeDat)
Sets edge data for the edge of ID NId in the network.
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.
TEdge & GetEdge(const int &EId)
TVal * TIter
Random access iterator to TVal.
int GetNbrNId(const int &NodeN) const
Returns ID of NodeN-th neighboring node.
int GetNbrNId(const int &EdgeN) const
void DelNode(const TNode &NodeI)
Deletes node of ID NodeI.GetId() from the network.
TNodeI GetRndNI(TRnd &Rnd=TInt::Rnd)
Returns an interator referring to a random node in the graph.
int GetEId(const int &SrcNId, const int &DstNId) const
int GetId() const
Returns ID of the current node.
int GetKeyId(const TKey &Key) const
THash< TInt, TEdge >::TIter THashIter
void IntAttrValueNI(const TInt &NId, TIntV &Values) const
Returns a vector of attr values for node NId.
TNodeI EndNI() const
Returns an iterator referring to the past-the-end node in the graph.
int GetRndNId(TRnd &Rnd=TInt::Rnd)
Returns an ID of a random node in the network.
int AddNode(const TNodeI &NodeId)
Adds a node NodeId and its node data to the network.
void GetIntAttrNames(TStrV &Names) const
Gets vector of int attribute names.
int AddStrAttrN(const TStr &attr, TStr defaultValue=TStr::GetNullStr())
Adds a new Str node attribute to the hashmap.
const TNodeData & GetOutNDat(const int &NodeN) const
const TEdgeData & operator()() const
int GetId() const
Gets edge ID.
const TEdgeDat & GetNbrEDat(const int &EdgeN) const
TNodeNet< TInt > TIntNNet
TNodeNet< TFlt > TFltNNet
int AddNode(int NId=-1)
Adds a node of ID NId to the network.
Edge iterator. Only forward iteration (operator++) is supported.
void Reserve(const int &Nodes, const int &Edges)
Reserves memory for a network of Nodes nodes and Edges edges.
void SortEIdById(const bool &Asc=true)
Sorts edges by edge IDs.
bool IsOutNId(const int &NId) const
Tests whether the current node points to node with ID NId.
THash< TInt, TEdge >::TIter THashIter
void FltAttrNameEI(const TInt &EId, TStrV &Names) const
Returns a vector of int attr names for node NId.
TNodeEdgeNet(TSIn &SIn)
Constructor that loads the network from a (binary) stream SIn.
TNodeI BegNI() const
Returns an iterator referring to the first node in the network.
TNodeEdgeNet< TNodeData, TEdgeData > TNet
bool operator<(const TEdgeI &EdgeI) const
THash< TStr, TStr > StrDefaultsE
const TEdgeData & GetDat() const
int GetInEId(const int &NodeN) const
void SetNDat(const int &NId, const TNodeData &NodeDat)
Sets node data for the node of ID NId in the network.
TNodeI GetNI(const int &NId) const
Returns an iterator referring to the node of ID NId in the network.
const TNode & GetNodeKId(const int &NodeKeyId) const
const TNodeData & GetSrcNDat() const
void StrAttrNameEI(const TInt &EId, TStrV &Names) const
Returns a vector of str attr names for node NId.
TFlt GetFltAttrDefaultE(const TStr &attribute) const
Get Flt edge attribute val. If not a proper attr, return default.
int GetEdges() const
Returns the number of edges in the graph.
void Save(TSOut &SOut) const
TNodeNet< TNodeData > TNet
TNodeNet< TStr > TStrNNet
int GetOutEId(const int &EdgeN) const
int GetInDeg() const
Returns in-degree of the current node.
bool EdgeAttrIsStrDeleted(const int &EId, const TStrIntPrH::TIter &EdgeHI) const
void Save(TSOut &SOut) const
Saves the graph to a (binary) stream SOut.
void GetEIdV(TIntV &EIdV) const
Returns a vector of all edge IDs in the network.
bool IsInEId(const int &EId) const
TEdgeI(const TEdgeI &EdgeI)
void GetAttrVal(TStrV &Val) const
Gets vector of attribute values.
const TEdgeDat & GetInEDat(const int &EdgeN) const
const TNodeData & GetDstNDat() const
TNodeNet & operator=(const TNodeNet &NodeNet)
const TNodeData & GetNbrNDat(const int &NodeN) const
TNEANet(const TNEANet &Graph)
TEdgeI(const TEdgeI &EdgeI)
static TStr Fmt(const char *FmtStr,...)
bool IsSorted(const bool &Asc=true) const
Checks whether the vector is sorted in ascending (if Asc=true) or descending (if Asc=false) order...
void Pack()
The vector reduces its capacity (frees memory) to match its size.
static PNet New()
Static constructor that returns a pointer to the network. Call: TPt > Net = TNodeEdgeNet::New().
void DelEdge(const int &EId)
Deletes an edge with ID EId from the network.
enum TGraphFlag_ TGraphFlag
Graph Flags, used for quick testing of graph types.
int GetOutNId(const int &NodeN) const
Returns ID of NodeN-th out-node (the node the current node points to).
bool operator<(const TEdge &Edge) const
const TNode & GetNode(const int &NId) const
int GetOutNId(const int &NodeN) const
Returns ID of NodeN-th out-node (the node the current node points to).
int DelAttrDatE(const TEdgeI &EdgeId, const TStr &attr)
Deletes the edge attribute for NodeId.
int GetMxEId() const
Returns an ID that is larger than any edge ID in the network.
int GetEdges() const
Returns the number of edges in the network.
int GetNbrEId(const int &EdgeN) const
Returns ID of EdgeN-th in or out-edge.
const TEdgeData & GetDat() const
TVec< TFltV > VecOfFltVecsN
TAFltI EndEAFltI(const TStr &attr) const
Returns an iterator referring to the past-the-end edge's attribute.
TAFltI GetNAFltI(const TStr &attr, const int &NId) const
Returns an iterator referring to the node of ID NId in the graph.
#define EAssertR(Cond, MsgStr)
bool HasFlag(const TGraphFlag &Flag) const
Allows for run-time checking the type of the network (see the TGraphFlag for flags).
void Clr()
Deletes all nodes and edges from the graph.
void Clr(const bool &DoDel=true, const bool &ResetDat=true)
Deletes all nodes and edges from the network.
TEdgeData & GetNbrEDat(const int &EdgeN)
const TNodeData & GetNbrNDat(const int &EdgeN) const
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.
bool Empty() const
Tests whether the network is empty (has zero nodes).
bool IsNbrNId(const int &NId) const
Tests whether node with ID NId is a neighbor of the current node.
const TNodeData & GetOutNDat(const int &NodeN) const
void DelNode(const TNode &NodeI)
Deletes node of ID NodeI.GetId() from the network.
TEdgeI GetEI(const int &SrcNId, const int &DstNId) const
Returns an iterator referring to edge (SrcNId, DstNId) in the graph.
void Clr(const bool &DoDel=true, const int &NoDelLim=-1, const bool &ResetDat=true)
bool IsInEId(const int &EId) const
Tests whether the edge with ID EId is an in-edge of current node.
bool operator<(const TNode &Node) const
int AddEdge(const TEdgeI &EdgeI)
Adds an edge from EdgeI.GetSrcNId() to EdgeI.GetDstNId() and its edge data to the network...
void GetNIdV(TIntV &NIdV) const
Gets a vector IDs of all nodes in the network.
THash< TStr, TInt > IntDefaultsN
TNodeI(const THashIter &NodeHIter, const TNEANet *GraphPt)
const TNode & GetNode(const int &NId) const
Returns node element for the node of ID NId in the network.
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
void Defrag(const bool &OnlyNodeLinks=false)
Defragments the network.
TFlt GetFltAttrDatN(const TNodeI &NodeId, const TStr &attr)
Gets the value of flt attr from the node attr value vector.
void Defrag(const bool &OnlyNodeLinks=false)
Defragments the network.
void DelNode(const int &NId)
Deletes node of ID NId from the network.
bool NodeAttrIsIntDeleted(const int &NId, const TStrIntPrH::TIter &NodeHI) const
int GetOutDeg() const
Returns out-degree of the current node.
THash< TInt, TNode > NodeH
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...
bool IsNbrNId(const int &NId) const
Tests whether node with ID NId is a neighbor of the current node.
TEdge & GetEdge(const int &EId)
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
TEdgeI & operator=(const TEdgeI &EdgeI)
int GetDstNId() const
Gets the destination node of an edge.
TEdgeI & operator=(const TEdgeI &EdgeI)
bool IsNbrEId(const int &EId) const
Tests whether the edge with ID EId is an in or out-edge of current node.
TNodeI BegNI() const
Returns an iterator referring to the first node in the graph.
void GetNIdV(TIntV &NIdV) const
Gets a vector IDs of all nodes in the network.
int AddIntAttrE(const TStr &attr, TInt defaultValue=TInt::Mn)
Adds a new Int edge attribute to the hashmap.
TFlt GetFltAttrDatE(const TEdgeI &EdgeId, const TStr &attr)
Gets the value of flt attr from the edge attr value vector.
TEdgeI BegEI() const
Returns an iterator referring to the first edge in the network.
void Reserve(const TSizeTy &_MxVals)
Reserves enough memory for the vector to store _MxVals elements.
TEdge(const int &EId, const int &SourceNId, const int &DestNId)
TNodeI GetNI(const int &NId) const
Returns an iterator referring to the node of ID NId in the graph.
TNodeI EndNI() const
Returns an iterator referring to the past-the-end node in the network.
const TEdgeData & GetOutEDat(const int &EdgeN) const
TFlt GetFltAttrDefaultN(const TStr &attribute) const
Get Flt node attribute val. If not a proper attr, return default.
bool IsInNId(const int &NId) const
Tests whether node with ID NId points to the current node.
int GetInEId(const int &EdgeN) const
void IntAttrNameEI(const TInt &EId, TStrV &Names) const
Returns a vector of int attr names for edge EId.
void GetIntAttrNames(TStrV &Names) const
Gets vector of int attribute names.
void Reserve(const int &Nodes, const int &Edges)
Reserves memory for a network of Nodes nodes and Edges edges.
TNodeI & operator=(const TNodeI &NodeI)
TInt GetIntAttrDefaultN(const TStr &attribute) const
Get Int node attribute val. If not a proper attr, return default.
TAStrI(const TStrVecIter &HIter, TStr attribute, bool isEdgeIter, const TNEANet *GraphPt)
TNodeEdgeNet< TInt, TInt > TIntNENet
static PNet Load(TSIn &SIn)
Static constructor that loads the network from a stream SIn and returns a pointer to it...
bool IsOk(const bool &ThrowExcept=true) const
Checks the network data structure for internal consistency.
TNodeData & GetNbrNDat(const int &NodeN)
Node iterator. Only forward iteration (operator++) is supported.
TPt< TNEANet > PNEANet
Pointer to a directed attribute multigraph (TNEANet)
bool IsKey(const TKey &Key) const
const TEdge & GetEdge(const int &EId) const
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
static PNEANet New()
Static cons returns pointer to graph. Ex: PNEANet Graph=TNEANet::New().
void GetFltAttrNames(TStrV &Names) const
Gets vector of flt attribute names.
int AddNode(const TNodeI &NodeId)
Adds a node of ID NodeI.GetId() to the graph.
bool IsOk(const bool &ThrowExcept=true) const
Checks the network data structure for internal consistency.
TNodeI(const TNodeI &NodeI)
TNodeData & GetOutNDat(const int &NodeN)
int GetDeg() const
Returns degree of the current node, the sum of in-degree and out-degree.
void GetStrAttrNames(TStrV &Names) const
Gets vector of str attribute names.
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.
TDat & AddDat(const TKey &Key)
TEdgeI EndEI() const
Returns an iterator referring to the past-the-end edge in the network.
bool operator==(const TNodeI &NodeI) const
TEdgeDat & GetInEDat(const int &EdgeN)
void Save(TSOut &SOut) const
Node/edge string attribute iterator. Iterates through all nodes/edges for one string attribute...
bool operator<(const TNodeI &NodeI) const
void GetAttrNames(TStrV &Names) const
Gets vector of attribute names.
Node iterator. Only forward iteration (operator++) is supported.
void GetIntAttrVal(TIntV &Val) const
Gets vector of int attribute values.
int GetIntAttrIndE(const TStr &attr)
Gets the index of the edge attr value vector specified by str attr.
TAFltI(const TFltVecIter &HIter, TStr attribute, bool isEdgeIter, const TNEANet *GraphPt)
void Save(TSOut &SOut) const
THash< TInt, TNode >::TIter THashIter
TNodeI EndNI() const
Returns an iterator referring to the past-the-end node in the network.
void GetIntAttrVal(TIntV &Val) const
Gets vector of int attribute values.
int GetOutEId(const int &NodeN) const
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...
int GetRndEId(TRnd &Rnd=TInt::Rnd)
Returns an ID of a random edge in the network.
const TKey & GetKey(const int &KeyId) const
int GetMxNId() const
Returns an ID that is larger than any node ID in the network.
THash< TInt, TNode >::TIter THashIter
Node Network (directed graph, TNGraph with data on nodes only).
int GetId() const
Returns ID of the current node.
int GetDeg() const
Returns degree of the current node.
const TEdgeData & GetEDat(const int &EId) const
Returns edge data for the edge with ID EId.
TNodeEDatNet< TStr, TInt > TStrIntNEDNet
const TEdgeData & GetNbrEDat(const int &EdgeN) const
int GetId() const
Returns ID of the current node.
const TNodeData & GetDstNDat() const
const TNodeData & GetDat() const
int AddFltAttrE(const TStr &attr, TFlt defaultValue=TFlt::Mn)
Adds a new Flt edge attribute to the hashmap.
TNode(const int &NId, const TNodeData &NodeData)
int GetDstNId() const
Gets destination of an edge.
int GetNbrNId(const int &NodeN) const
bool operator==(const TNodeI &NodeI) const
static PNet Load(TSIn &SIn)
Static constructor that loads the network from a stream SIn and returns a pointer to it...
TNodeEdgeNet(const int &Nodes, const int &Edges)
Constructor that reserves enough memory for a network of Nodes nodes and Edges edges.
int GetNodes() const
Returns the number of nodes in the network.
TNodeI GetRndNI(TRnd &Rnd=TInt::Rnd)
Returns an interator referring to a random node in the network.
TIter GetI(const TKey &Key) const
void SortByDat(const bool &Asc=true)
TPt< TFltNENet > PFltNENet
int GetMxNId() const
Returns an ID that is larger than any node ID in the network.
TEdgeI EndEI() const
Returns an iterator referring to the past-the-end edge in the network.
int AddFltAttrN(const TStr &attr, TFlt defaultValue=TFlt::Mn)
Adds a new Flt node attribute to the hashmap.
TStr GetStrAttrDatN(const TNodeI &NodeId, const TStr &attr)
Gets the value of str attr from the node attr value vector.