16 template <
class TNodeData>
78 int GetInNId(
const int& NodeN)
const {
return NodeHI.GetDat().GetInNId(NodeN); }
82 int GetOutNId(
const int& NodeN)
const {
return NodeHI.GetDat().GetOutNId(NodeN); }
86 int GetNbrNId(
const int& NodeN)
const {
return NodeHI.GetDat().GetNbrNId(NodeN); }
88 bool IsInNId(
const int& NId)
const {
return NodeHI.GetDat().IsInNId(NId); }
90 bool IsOutNId(
const int& NId)
const {
return NodeHI.GetDat().IsOutNId(NId); }
95 const TNodeData&
GetDat()
const {
return NodeHI.GetDat().GetDat(); }
172 int AddNode(
int NId,
const TNodeData& NodeDat);
174 int AddNode(
const TNodeI& NodeI) {
return AddNode(NodeI.GetId(), NodeI.GetDat()); }
178 virtual void DelNode(
const int& NId);
192 void SetNDat(
const int& NId,
const TNodeData& NodeDat);
210 int AddEdge(
const int& SrcNId,
const int& DstNId);
212 int AddEdge(
const TEdgeI& EdgeI) {
return AddEdge(EdgeI.GetSrcNId(), EdgeI.GetDstNId()); }
218 void DelEdge(
const int& SrcNId,
const int& DstNId,
const bool& IsDir =
true);
220 bool IsEdge(
const int& SrcNId,
const int& DstNId,
const bool& IsDir =
true)
const;
226 TEdgeI
GetEI(
const int& EId)
const;
228 TEdgeI
GetEI(
const int& SrcNId,
const int& DstNId)
const;
240 void Clr(
const bool& DoDel=
true,
const bool& ResetDat=
true) {
243 void Reserve(
const int& Nodes,
const int& Edges) {
if (Nodes>0) {
NodeH.
Gen(Nodes/2); } }
254 void Defrag(
const bool& OnlyNodeLinks=
false);
259 bool IsOk(
const bool& ThrowExcept=
true)
const;
270 template <
class TNodeData>
275 template <
class TNodeData>
278 NId = MxNId; MxNId++;
283 NodeH.AddDat(NId,
TNode(NId));
287 template <
class TNodeData>
290 NId = MxNId; MxNId++;
295 NodeH.AddDat(NId,
TNode(NId, NodeDat));
299 template <
class TNodeData>
301 {
TNode& Node = GetNode(NId);
302 for (
int e = 0; e < Node.
GetOutDeg(); e++) {
304 if (nbr == NId) {
continue; }
305 TNode& N = GetNode(nbr);
309 for (
int e = 0; e < Node.
GetInDeg(); e++) {
311 if (nbr == NId) {
continue; }
312 TNode& N = GetNode(nbr);
319 template <
class TNodeData>
322 NodeH.GetDat(NId).NodeDat = NodeDat;
325 template <
class TNodeData>
328 for (
int N=NodeH.FFirstKeyId(); NodeH.FNextKeyId(N);) {
329 edges+=NodeH[N].GetOutDeg(); }
333 template <
class TNodeData>
335 IAssertR(IsNode(SrcNId) && IsNode(DstNId),
TStr::Fmt(
"%d or %d not a node.", SrcNId, DstNId).CStr());
336 if (IsEdge(SrcNId, DstNId)) {
return -2; }
337 GetNode(SrcNId).OutNIdV.AddSorted(DstNId);
338 GetNode(DstNId).InNIdV.AddSorted(SrcNId);
342 template <
class TNodeData>
344 IAssertR(IsNode(SrcNId) && IsNode(DstNId),
TStr::Fmt(
"%d or %d not a node.", SrcNId, DstNId).CStr());
345 GetNode(SrcNId).OutNIdV.DelIfIn(DstNId);
346 GetNode(DstNId).InNIdV.DelIfIn(SrcNId);
348 GetNode(DstNId).OutNIdV.DelIfIn(SrcNId);
349 GetNode(SrcNId).InNIdV.DelIfIn(DstNId);
353 template <
class TNodeData>
355 if (! IsNode(SrcNId) || ! IsNode(DstNId)) {
return false; }
356 if (IsDir) {
return GetNode(SrcNId).IsOutNId(DstNId); }
357 else {
return GetNode(SrcNId).IsOutNId(DstNId) || GetNode(DstNId).IsOutNId(SrcNId); }
360 template <
class TNodeData>
363 for (
int N=NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
364 NIdV.
Add(NodeH.GetKey(N)); }
367 template <
class TNodeData>
369 const TNodeI SrcNI = GetNI(SrcNId);
370 const int NodeN = SrcNI.
NodeHI.GetDat().OutNIdV.SearchBin(DstNId);
371 if (NodeN == -1) {
return EndEI(); }
372 return TEdgeI(SrcNI, EndNI(), NodeN);
375 template <
class TNodeData>
377 for (
int n = NodeH.FFirstKeyId(); NodeH.FNextKeyId(n); ) {
378 TNode& Node = NodeH[n];
381 if (! OnlyNodeLinks && ! NodeH.IsKeyIdEqKeyN()) {
385 template <
class TNodeData>
388 for (
int N = NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
389 const TNode& Node = NodeH[N];
391 const TStr Msg =
TStr::Fmt(
"Out-neighbor list of node %d is not sorted.", Node.
GetId());
395 const TStr Msg =
TStr::Fmt(
"In-neighbor list of node %d is not sorted.", Node.
GetId());
400 for (
int e = 0; e < Node.
GetOutDeg(); e++) {
402 const TStr Msg =
TStr::Fmt(
"Out-edge %d --> %d: node %d does not exist.",
406 if (e > 0 && prevNId == Node.
GetOutNId(e)) {
407 const TStr Msg =
TStr::Fmt(
"Node %d has duplidate out-edge %d --> %d.",
415 for (
int e = 0; e < Node.
GetInDeg(); e++) {
417 const TStr Msg =
TStr::Fmt(
"In-edge %d <-- %d: node %d does not exist.",
421 if (e > 0 && prevNId == Node.
GetInNId(e)) {
422 const TStr Msg =
TStr::Fmt(
"Node %d has duplidate in-edge %d <-- %d.",
443 template <
class TNodeData,
class TEdgeData>
538 const TEdgeData&
GetOutEDat(
const int& EdgeN)
const {
return NodeHI.GetDat().GetOutEDat(EdgeN); }
617 int AddNode(
int NId,
const TNodeData& NodeDat);
619 int AddNode(
const TNodeI& NodeI) {
return AddNode(NodeI.GetId(), NodeI.GetDat()); }
637 void SetNDat(
const int& NId,
const TNodeData& NodeDat);
655 int AddEdge(
const int& SrcNId,
const int& DstNId);
663 int AddEdge(
const int& SrcNId,
const int& DstNId,
const TEdgeData& EdgeDat);
665 int AddEdge(
const TEdgeI& EdgeI) {
return AddEdge(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), EdgeI()); }
671 void DelEdge(
const int& SrcNId,
const int& DstNId,
const bool& IsDir =
true);
673 bool IsEdge(
const int& SrcNId,
const int& DstNId,
const bool& IsDir =
true)
const;
679 TEdgeI
GetEI(
const int& EId)
const;
681 TEdgeI
GetEI(
const int& SrcNId,
const int& DstNId)
const;
683 void SetEDat(
const int& SrcNId,
const int& DstNId,
const TEdgeData& EdgeDat);
687 bool GetEDat(
const int& SrcNId,
const int& DstNId, TEdgeData& EdgeDat)
const;
689 TEdgeData&
GetEDat(
const int& SrcNId,
const int& DstNId);
691 const TEdgeData&
GetEDat(
const int& SrcNId,
const int& DstNId)
const;
705 void Clr(
const bool& DoDel=
true,
const bool& ResetDat=
true) {
708 void Reserve(
const int& Nodes,
const int& Edges) {
if (Nodes>0) {
NodeH.
Gen(Nodes/2); } }
719 void Defrag(
const bool& OnlyNodeLinks=
false);
724 bool IsOk(
const bool& ThrowExcept=
true)
const;
736 template <
class TNodeData,
class TEdgeData>
741 template <
class TNodeData,
class TEdgeData>
743 int LValN=0, RValN = NIdV.Len()-1;
744 while (RValN >= LValN) {
745 const int ValN = (LValN+RValN)/2;
746 const int CurNId = NIdV[ValN].Val1;
747 if (NId == CurNId) {
return ValN; }
748 if (NId < CurNId) { RValN=ValN-1; }
749 else { LValN=ValN+1; }
754 template <
class TNodeData,
class TEdgeData>
757 NId = MxNId; MxNId++;
762 NodeH.AddDat(NId,
TNode(NId));
766 template <
class TNodeData,
class TEdgeData>
769 NId = MxNId; MxNId++;
774 NodeH.AddDat(NId,
TNode(NId, NodeDat));
778 template <
class TNodeData,
class TEdgeData>
781 NodeH.GetDat(NId).NodeDat = NodeDat;
784 template <
class TNodeData,
class TEdgeData>
786 const TNode& Node = GetNode(NId);
787 for (
int out = 0; out < Node.
GetOutDeg(); out++) {
789 if (nbr == NId) {
continue; }
790 TIntV& NIdV = GetNode(nbr).InNIdV;
792 if (pos != -1) { NIdV.
Del(pos); }
794 for (
int in = 0; in < Node.
GetInDeg(); in++) {
796 if (nbr == NId) {
continue; }
798 const int pos = GetNIdPos(NIdDatV, NId);
799 if (pos != -1) { NIdDatV.
Del(pos); }
804 template <
class TNodeData,
class TEdgeData>
807 for (
int N=NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
808 edges+=NodeH[N].GetOutDeg(); }
812 template <
class TNodeData,
class TEdgeData>
814 return AddEdge(SrcNId, DstNId, TEdgeData());
817 template <
class TNodeData,
class TEdgeData>
819 IAssertR(IsNode(SrcNId) && IsNode(DstNId),
TStr::Fmt(
"%d or %d not a node.", SrcNId, DstNId).CStr());
821 if (IsEdge(SrcNId, DstNId)) {
822 GetEDat(SrcNId, DstNId) = EdgeDat;
826 GetNode(DstNId).InNIdV.AddSorted(SrcNId);
830 template <
class TNodeData,
class TEdgeData>
832 IAssertR(IsNode(SrcNId) && IsNode(DstNId),
TStr::Fmt(
"%d or %d not a node.", SrcNId, DstNId).CStr());
833 int pos = GetNIdPos(GetNode(SrcNId).OutNIdV, DstNId);
834 if (pos != -1) { GetNode(SrcNId).OutNIdV.Del(pos); }
835 pos = GetNode(DstNId).InNIdV.SearchBin(SrcNId);
836 if (pos != -1) { GetNode(DstNId).InNIdV.Del(pos); }
838 pos = GetNIdPos(GetNode(DstNId).OutNIdV, SrcNId);
839 if (pos != -1) { GetNode(DstNId).OutNIdV.Del(pos); }
840 pos = GetNode(SrcNId).InNIdV.SearchBin(DstNId);
841 if (pos != -1) { GetNode(SrcNId).InNIdV.Del(pos); }
845 template <
class TNodeData,
class TEdgeData>
847 if (! IsNode(SrcNId) || ! IsNode(DstNId)) {
return false; }
848 if (IsDir) {
return GetNode(SrcNId).IsOutNId(DstNId); }
849 else {
return GetNode(SrcNId).IsOutNId(DstNId) || GetNode(DstNId).IsOutNId(SrcNId); }
852 template <
class TNodeData,
class TEdgeData>
854 IAssertR(IsNode(SrcNId) && IsNode(DstNId),
TStr::Fmt(
"%d or %d not a node.", SrcNId, DstNId).CStr());
855 IAssertR(IsEdge(SrcNId, DstNId),
TStr::Fmt(
"Edge between %d and %d does not exist.", SrcNId, DstNId).CStr());
856 GetEDat(SrcNId, DstNId) = EdgeDat;
859 template <
class TNodeData,
class TEdgeData>
861 if (! IsEdge(SrcNId, DstNId)) {
return false; }
862 const TNode& N = GetNode(SrcNId);
867 template <
class TNodeData,
class TEdgeData>
869 Assert(IsEdge(SrcNId, DstNId));
870 TNode& N = GetNode(SrcNId);
874 template <
class TNodeData,
class TEdgeData>
876 Assert(IsEdge(SrcNId, DstNId));
877 const TNode& N = GetNode(SrcNId);
881 template <
class TNodeData,
class TEdgeData>
883 for (
TEdgeI EI = BegEI(); EI < EndEI(); EI++) {
888 template <
class TNodeData,
class TEdgeData>
890 const TNodeI SrcNI = GetNI(SrcNId);
894 int LValN=0, RValN=NIdDatV.
Len()-1;
895 while (RValN>=LValN){
896 int ValN=(LValN+RValN)/2;
897 if (DstNId==NIdDatV[ValN].Val1){ NodeN=ValN;
break; }
898 if (DstNId<NIdDatV[ValN].Val1){RValN=ValN-1;}
else {LValN=ValN+1;}
900 if (NodeN == -1) {
return EndEI(); }
901 else {
return TEdgeI(SrcNI, EndNI(), NodeN); }
904 template <
class TNodeData,
class TEdgeData>
907 for (
int N=NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
908 NIdV.
Add(NodeH.GetKey(N)); }
911 template <
class TNodeData,
class TEdgeData>
913 for (
int n = NodeH.FFirstKeyId(); NodeH.FNextKeyId(n);) {
914 TNode& Node = NodeH[n];
917 if (! OnlyNodeLinks && ! NodeH.IsKeyIdEqKeyN()) {
922 template <
class TNodeData,
class TEdgeData>
925 for (
int N = NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
926 const TNode& Node = NodeH[N];
928 const TStr Msg =
TStr::Fmt(
"Out-neighbor list of node %d is not sorted.", Node.
GetId());
932 const TStr Msg =
TStr::Fmt(
"In-neighbor list of node %d is not sorted.", Node.
GetId());
937 for (
int e = 0; e < Node.
GetOutDeg(); e++) {
939 const TStr Msg =
TStr::Fmt(
"Out-edge %d --> %d: node %d does not exist.",
943 if (e > 0 && prevNId == Node.
GetOutNId(e)) {
944 const TStr Msg =
TStr::Fmt(
"Node %d has duplidate out-edge %d --> %d.",
952 for (
int e = 0; e < Node.
GetInDeg(); e++) {
954 const TStr Msg =
TStr::Fmt(
"In-edge %d <-- %d: node %d does not exist.",
958 if (e > 0 && prevNId == Node.
GetInNId(e)) {
959 const TStr Msg =
TStr::Fmt(
"Node %d has duplidate in-edge %d <-- %d.",
980 template <
class TNodeData,
class TEdgeData>
1023 TEdge(
const int& EId,
const int& SourceNId,
const int& DestNId,
const TEdgeData& EdgeData) :
Id(EId),
SrcNId(SourceNId),
DstNId(DestNId),
EdgeDat(EdgeData) { }
1073 bool IsInNId(
const int& NId)
const;
1075 bool IsOutNId(
const int& NId)
const;
1187 int AddNode(
int NId,
const TNodeData& NodeDat);
1206 void SetNDat(
const int& NId,
const TNodeData& NodeDat);
1225 int AddEdge(
const int& SrcNId,
const int& DstNId,
int EId = -1);
1232 int AddEdge(
const int& SrcNId,
const int& DstNId,
int EId,
const TEdgeData& EdgeDat);
1234 int AddEdge(
const TEdgeI& EdgeI) {
return AddEdge(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), EdgeI.GetId(), EdgeI.GetDat()); }
1242 void DelEdge(
const int& SrcNId,
const int& DstNId,
const bool& IsDir =
true);
1246 bool IsEdge(
const int& SrcNId,
const int& DstNId,
const bool& IsDir =
true)
const {
int EId;
return IsEdge(SrcNId, DstNId, EId, IsDir); }
1248 bool IsEdge(
const int& SrcNId,
const int& DstNId,
int& EId,
const bool& IsDir =
true)
const;
1249 int GetEId(
const int& SrcNId,
const int& DstNId)
const {
int EId;
return IsEdge(SrcNId, DstNId, EId)?EId:-1; }
1257 TEdgeI
GetEI(
const int& SrcNId,
const int& DstNId)
const {
return GetEI(
GetEId(SrcNId, DstNId)); }
1259 void SetEDat(
const int& EId,
const TEdgeData& EdgeDat);
1285 void Reserve(
const int& Nodes,
const int& Edges) {
1286 if (Nodes>0) {
NodeH.
Gen(Nodes/2); }
if (Edges>0) {
EdgeH.
Gen(Edges/2); } }
1301 void Defrag(
const bool& OnlyNodeLinks=
false);
1306 bool IsOk(
const bool& ThrowExcept=
true)
const;
1319 template <
class TNodeData,
class TEdgeData>
1324 template <
class TNodeData,
class TEdgeData>
1334 template <
class TNodeData,
class TEdgeData>
1344 template <
class TNodeData,
class TEdgeData>
1356 template <
class TNodeData,
class TEdgeData>
1368 template <
class TNodeData,
class TEdgeData>
1371 for (
int out = 0; out < Node.
GetOutDeg(); out++) {
1378 for (
int in = 0; in < Node.
GetInDeg(); in++) {
1388 template <
class TNodeData,
class TEdgeData>
1394 template <
class TNodeData,
class TEdgeData>
1398 const int Src = EI.GetSrcNId();
1399 const int Dst = EI.GetDstNId();
1403 return UniqESet.
Len();
1406 template <
class TNodeData,
class TEdgeData>
1418 template <
class TNodeData,
class TEdgeData>
1430 template <
class TNodeData,
class TEdgeData>
1440 template <
class TNodeData,
class TEdgeData>
1449 template <
class TNodeData,
class TEdgeData>
1451 if (!
IsNode(SrcNId)) {
return false; }
1452 if (!
IsNode(DstNId)) {
return false; }
1457 EId = Edge.
GetId();
return true; }
1463 EId = Edge.
GetId();
return true; }
1469 template <
class TNodeData,
class TEdgeData>
1475 template <
class TNodeData,
class TEdgeData>
1483 template <
class TNodeData,
class TEdgeData>
1491 template <
class TNodeData,
class TEdgeData>
1499 template <
class TNodeData,
class TEdgeData>
1509 template <
class TNodeData,
class TEdgeData>
1524 for (
int e = 0; e < Node.
GetOutDeg(); e++) {
1529 if (e > 0 && prevEId == Node.
GetOutEId(e)) {
1537 for (
int e = 0; e < Node.
GetInDeg(); e++) {
1542 if (e > 0 && prevEId == Node.
GetInEId(e)) {
1601 TNode() : Id(-1), InEIdV(), OutEIdV() { }
1602 TNode(
const int& NId) : Id(NId), InEIdV(), OutEIdV() { }
1603 TNode(
const TNode& Node) : Id(Node.Id), InEIdV(Node.InEIdV), OutEIdV(Node.OutEIdV) { }
1605 void Save(
TSOut& SOut)
const { Id.Save(SOut); InEIdV.Save(SOut); OutEIdV.Save(SOut); }
1607 int GetDeg()
const {
return GetInDeg() + GetOutDeg(); }
1610 int GetInEId(
const int& EdgeN)
const {
return InEIdV[EdgeN]; }
1611 int GetOutEId(
const int& EdgeN)
const {
return OutEIdV[EdgeN]; }
1612 int GetNbrEId(
const int& EdgeN)
const {
return EdgeN<GetOutDeg()?GetOutEId(EdgeN):GetInEId(EdgeN-GetOutDeg()); }
1613 bool IsInEId(
const int& EId)
const {
return InEIdV.SearchBin(EId) != -1; }
1614 bool IsOutEId(
const int& EId)
const {
return OutEIdV.SearchBin(EId) != -1; }
1621 TEdge() : Id(-1), SrcNId(-1), DstNId(-1) { }
1622 TEdge(
const int& EId,
const int& SourceNId,
const int& DestNId) : Id(EId), SrcNId(SourceNId), DstNId(DestNId) { }
1623 TEdge(
const TEdge& Edge) : Id(Edge.Id), SrcNId(Edge.SrcNId), DstNId(Edge.DstNId) { }
1625 void Save(
TSOut& SOut)
const { Id.Save(SOut); SrcNId.Save(SOut); DstNId.Save(SOut); }
1643 TNodeI& operator++ (
int) { NodeHI++;
return *
this; }
1644 bool operator < (
const TNodeI& NodeI)
const {
return NodeHI < NodeI.
NodeHI; }
1645 bool operator == (
const TNodeI& NodeI)
const {
return NodeHI == NodeI.
NodeHI; }
1647 int GetId()
const {
return NodeHI.GetDat().GetId(); }
1649 int GetDeg()
const {
return NodeHI.GetDat().GetDeg(); }
1651 int GetInDeg()
const {
return NodeHI.GetDat().GetInDeg(); }
1653 int GetOutDeg()
const {
return NodeHI.GetDat().GetOutDeg(); }
1657 int GetInNId(
const int& EdgeN)
const {
return Graph->GetEdge(NodeHI.GetDat().GetInEId(EdgeN)).GetSrcNId(); }
1661 int GetOutNId(
const int& EdgeN)
const {
return Graph->GetEdge(NodeHI.GetDat().GetOutEId(EdgeN)).GetDstNId(); }
1667 bool IsInNId(
const int& NId)
const;
1669 bool IsOutNId(
const int& NId)
const;
1671 bool IsNbrNId(
const int& NId)
const {
return IsOutNId(NId) || IsInNId(NId); }
1673 int GetInEId(
const int& EdgeN)
const {
return NodeHI.GetDat().GetInEId(EdgeN); }
1675 int GetOutEId(
const int& EdgeN)
const {
return NodeHI.GetDat().GetOutEId(EdgeN); }
1677 int GetNbrEId(
const int& EdgeN)
const {
return NodeHI.GetDat().GetNbrEId(EdgeN); }
1679 bool IsInEId(
const int& EId)
const {
return NodeHI.GetDat().IsInEId(EId); }
1681 bool IsOutEId(
const int& EId)
const {
return NodeHI.GetDat().IsOutEId(EId); }
1683 bool IsNbrEId(
const int& EId)
const {
return IsInEId(EId) || IsOutEId(EId); }
1718 TEdgeI& operator++ (
int) { EdgeHI++;
return *
this; }
1719 bool operator < (
const TEdgeI& EdgeI)
const {
return EdgeHI < EdgeI.
EdgeHI; }
1720 bool operator == (
const TEdgeI& EdgeI)
const {
return EdgeHI == EdgeI.
EdgeHI; }
1722 int GetId()
const {
return EdgeHI.GetDat().GetId(); }
1724 int GetSrcNId()
const {
return EdgeHI.GetDat().GetSrcNId(); }
1726 int GetDstNId()
const {
return EdgeHI.GetDat().GetDstNId(); }
1760 TAIntI(
const TIntVecIter& HIter,
TStr attribute,
bool isEdgeIter,
const TNEANet* GraphPt) : HI(HIter), attr(), Graph(GraphPt) { isNode = !isEdgeIter; attr = attribute; }
1763 bool operator < (
const TAIntI& I)
const {
return HI < I.
HI; }
1764 bool operator == (
const TAIntI& I)
const {
return HI == I.
HI; }
1768 bool IsDeleted()
const {
return isNode ? GetDat() == Graph->GetIntAttrDefaultN(attr) : GetDat() == Graph->GetIntAttrDefaultE(attr); };
1782 TAIntVI(
const TIntVVecIter& HIter,
TStr attribute,
bool isEdgeIter,
const TNEANet* GraphPt) : HI(HIter), attr(), Graph(GraphPt) { isNode = !isEdgeIter; attr = attribute; }
1785 bool operator < (
const TAIntVI& I)
const {
return HI < I.
HI; }
1786 bool operator == (
const TAIntVI& I)
const {
return HI == I.
HI; }
1803 TAStrI(
const TStrVecIter& HIter,
TStr attribute,
bool isEdgeIter,
const TNEANet* GraphPt) : HI(HIter), attr(), Graph(GraphPt) { isNode = !isEdgeIter; attr = attribute; }
1806 bool operator < (
const TAStrI& I)
const {
return HI < I.
HI; }
1807 bool operator == (
const TAStrI& I)
const {
return HI == I.
HI; }
1811 bool IsDeleted()
const {
return isNode ? GetDat() == Graph->GetStrAttrDefaultN(attr) : GetDat() == Graph->GetStrAttrDefaultE(attr); };
1826 TAFltI(
const TFltVecIter& HIter,
TStr attribute,
bool isEdgeIter,
const TNEANet* GraphPt) : HI(HIter), attr(), Graph(GraphPt) { isNode = !isEdgeIter; attr = attribute; }
1829 bool operator < (
const TAFltI& I)
const {
return HI < I.
HI; }
1830 bool operator == (
const TAFltI& I)
const {
return HI == I.
HI; }
1834 bool IsDeleted()
const {
return isNode ? GetDat() == Graph->GetFltAttrDefaultN(attr) : GetDat() == Graph->GetFltAttrDefaultE(attr); };
1950 Graph->MxNId.Load(SIn); Graph->MxEId.Load(SIn);
1951 Graph->NodeH.Load(SIn); Graph->EdgeH.Load(SIn);
1952 Graph->KeyToIndexTypeN.Load(SIn); Graph->KeyToIndexTypeE.Load(SIn);
1953 Graph->IntDefaultsN.Load(SIn); Graph->IntDefaultsE.Load(SIn);
1954 Graph->StrDefaultsN.Load(SIn); Graph->StrDefaultsE.Load(SIn);
1955 Graph->FltDefaultsN.Load(SIn); Graph->FltDefaultsE.Load(SIn);
1956 Graph->VecOfIntVecsN.Load(SIn); Graph->VecOfIntVecsE.Load(SIn);
1957 Graph->VecOfStrVecsN.Load(SIn); Graph->VecOfStrVecsE.Load(SIn);
1958 Graph->VecOfFltVecsN.Load(SIn); Graph->VecOfFltVecsE.Load(SIn);
1981 virtual void DelNode(
const int& NId);
2186 int AddEdge(
const int& SrcNId,
const int& DstNId,
int EId = -1);
2196 void DelEdge(
const int& SrcNId,
const int& DstNId,
const bool& IsDir =
true);
2200 bool IsEdge(
const int& SrcNId,
const int& DstNId,
const bool& IsDir =
true)
const {
int EId;
return IsEdge(SrcNId, DstNId, EId, IsDir); }
2202 bool IsEdge(
const int& SrcNId,
const int& DstNId,
int& EId,
const bool& IsDir =
true)
const;
2204 int GetEId(
const int& SrcNId,
const int& DstNId)
const {
int EId;
return IsEdge(SrcNId, DstNId, EId)?EId:-1; }
2237 void Reserve(
const int& Nodes,
const int& Edges) {
2238 if (Nodes>0) {
NodeH.
Gen(Nodes/2); }
if (Edges>0) {
EdgeH.
Gen(Edges/2); } }
2245 void Defrag(
const bool& OnlyNodeLinks=
false);
2250 bool IsOk(
const bool& ThrowExcept=
true)
const;
2252 void Dump(FILE *OutF=stdout)
const;
2759 TNode(
const int& NId) : Id(NId), NIdV() { }
2762 void Save(
TSOut& SOut)
const { Id.Save(SOut); NIdV.Save(SOut); }
2767 int GetInNId(
const int& NodeN)
const {
return GetNbrNId(NodeN); }
2768 int GetOutNId(
const int& NodeN)
const {
return GetNbrNId(NodeN); }
2769 int GetNbrNId(
const int& NodeN)
const {
return NIdV[NodeN]; }
2770 bool IsNbrNId(
const int& NId)
const {
return NIdV.SearchBin(NId)!=-1; }
2771 bool IsInNId(
const int& NId)
const {
return IsNbrNId(NId); }
2772 bool IsOutNId(
const int& NId)
const {
return IsNbrNId(NId); }
2776 friend class TUndirNetMtx;
2790 TNodeI& operator++ (
int) { NodeHI++;
return *
this; }
2792 TNodeI& operator-- (
int) { NodeHI--;
return *
this; }
2795 bool operator < (
const TNodeI& NodeI)
const {
return NodeHI < NodeI.
NodeHI; }
2796 bool operator == (
const TNodeI& NodeI)
const {
return NodeHI == NodeI.
NodeHI; }
2799 int GetId()
const {
return NodeHI.GetDat().GetId(); }
2801 int GetDeg()
const {
return NodeHI.GetDat().GetDeg(); }
2803 int GetInDeg()
const {
return NodeHI.GetDat().GetInDeg(); }
2805 int GetOutDeg()
const {
return NodeHI.GetDat().GetOutDeg(); }
2810 int GetInNId(
const int& NodeN)
const {
return NodeHI.GetDat().GetInNId(NodeN); }
2815 int GetOutNId(
const int& NodeN)
const {
return NodeHI.GetDat().GetOutNId(NodeN); }
2820 int GetNbrNId(
const int& NodeN)
const {
return NodeHI.GetDat().GetNbrNId(NodeN); }
2822 bool IsInNId(
const int& NId)
const {
return NodeHI.GetDat().IsInNId(NId); }
2824 bool IsOutNId(
const int& NId)
const {
return NodeHI.GetDat().IsOutNId(NId); }
2826 bool IsNbrNId(
const int& NId)
const {
return NodeHI.GetDat().IsNbrNId(NId); }
2835 TEdgeI() : CurNode(), EndNode(), CurEdge(0) { }
2836 TEdgeI(
const TNodeI& NodeI,
const TNodeI& EndNodeI,
const int& EdgeN=0) : CurNode(NodeI), EndNode(EndNodeI), CurEdge(EdgeN) { }
2837 TEdgeI(
const TEdgeI& EdgeI) : CurNode(EdgeI.CurNode), EndNode(EdgeI.EndNode), CurEdge(EdgeI.CurEdge) { }
2840 TEdgeI& operator++ (
int) {
do { CurEdge++;
if (CurEdge >= CurNode.GetOutDeg()) { CurEdge=0; CurNode++;
while (CurNode < EndNode && CurNode.GetOutDeg()==0) { CurNode++; } } }
while (CurNode < EndNode && GetSrcNId()>GetDstNId());
return *
this; }
2848 int GetDstNId()
const {
return CurNode.GetOutNId(CurEdge); }
2880 static PUndirNet
New(
const int& Nodes,
const int& Edges) {
return new TUndirNet(Nodes, Edges); }
2885 Graph->MxNId.Load(SIn); Graph->NEdges.Load(SIn); Graph->NodeH.Load(SIn);
return Graph;
2951 int AddEdge(
const int& SrcNId,
const int& DstNId);
2959 void DelEdge(
const int& SrcNId,
const int& DstNId);
2961 bool IsEdge(
const int& SrcNId,
const int& DstNId)
const;
2967 TEdgeI
GetEI(
const int& EId)
const;
2972 TEdgeI
GetEI(
const int& SrcNId,
const int& DstNId)
const;
2995 void Defrag(
const bool& OnlyNodeLinks=
false);
3000 bool IsOk(
const bool& ThrowExcept=
true)
const;
3002 void Dump(FILE *OutF=stdout)
const;
3173 int GetSAttrDatE(
const int& SrcNId,
const int& DstNId,
const TStr& AttrName,
TInt& ValX)
const;
3187 int GetSAttrDatE(
const int& SrcNId,
const int& DstNId,
const TStr& AttrName,
TFlt& ValX)
const;
3201 int GetSAttrDatE(
const int& SrcNId,
const int& DstNId,
const TStr& AttrName,
TStr& ValX)
const;
3215 int DelSAttrDatE(
const int& SrcNId,
const int& DstNId,
const TStr& AttrName);
3217 int DelSAttrDatE(
const int& SrcNId,
const int& DstNId,
const TInt& AttrId);
3247 friend class TUndirNetMtx;
3277 TNode() : Id(-1), InNIdV(), OutNIdV() { }
3278 TNode(
const int& NId) : Id(NId), InNIdV(), OutNIdV() { }
3279 TNode(
const TNode& Node) : Id(Node.Id), InNIdV(Node.InNIdV), OutNIdV(Node.OutNIdV) { }
3281 void Save(
TSOut& SOut)
const { Id.Save(SOut); InNIdV.Save(SOut); OutNIdV.Save(SOut); }
3283 int GetDeg()
const {
return GetInDeg() + GetOutDeg(); }
3286 int GetInNId(
const int& NodeN)
const {
return InNIdV[NodeN]; }
3287 int GetOutNId(
const int& NodeN)
const {
return OutNIdV[NodeN]; }
3288 int GetNbrNId(
const int& NodeN)
const {
return NodeN<GetOutDeg()?GetOutNId(NodeN):GetInNId(NodeN-GetOutDeg()); }
3289 bool IsInNId(
const int& NId)
const {
return InNIdV.SearchBin(NId) != -1; }
3290 bool IsOutNId(
const int& NId)
const {
return OutNIdV.SearchBin(NId) != -1; }
3291 bool IsNbrNId(
const int& NId)
const {
return IsOutNId(NId) || IsInNId(NId); }
3295 friend class TDirNetMtx;
3308 TNodeI& operator++ (
int) { NodeHI++;
return *
this; }
3310 TNodeI& operator-- (
int) { NodeHI--;
return *
this; }
3312 bool operator < (
const TNodeI& NodeI)
const {
return NodeHI < NodeI.
NodeHI; }
3313 bool operator == (
const TNodeI& NodeI)
const {
return NodeHI == NodeI.
NodeHI; }
3315 int GetId()
const {
return NodeHI.GetDat().GetId(); }
3317 int GetDeg()
const {
return NodeHI.GetDat().GetDeg(); }
3319 int GetInDeg()
const {
return NodeHI.GetDat().GetInDeg(); }
3321 int GetOutDeg()
const {
return NodeHI.GetDat().GetOutDeg(); }
3325 int GetInNId(
const int& NodeN)
const {
return NodeHI.GetDat().GetInNId(NodeN); }
3329 int GetOutNId(
const int& NodeN)
const {
return NodeHI.GetDat().GetOutNId(NodeN); }
3333 int GetNbrNId(
const int& NodeN)
const {
return NodeHI.GetDat().GetNbrNId(NodeN); }
3335 bool IsInNId(
const int& NId)
const {
return NodeHI.GetDat().IsInNId(NId); }
3337 bool IsOutNId(
const int& NId)
const {
return NodeHI.GetDat().IsOutNId(NId); }
3339 bool IsNbrNId(
const int& NId)
const {
return IsOutNId(NId) || IsInNId(NId); }
3348 TEdgeI() : CurNode(), EndNode(), CurEdge(0) { }
3349 TEdgeI(
const TNodeI& NodeI,
const TNodeI& EndNodeI,
const int& EdgeN=0) : CurNode(NodeI), EndNode(EndNodeI), CurEdge(EdgeN) { }
3350 TEdgeI(
const TEdgeI& EdgeI) : CurNode(EdgeI.CurNode), EndNode(EdgeI.EndNode), CurEdge(EdgeI.CurEdge) { }
3353 TEdgeI& operator++ (
int) { CurEdge++;
if (CurEdge >= CurNode.GetOutDeg()) { CurEdge=0; CurNode++;
3354 while (CurNode < EndNode && CurNode.GetOutDeg()==0) { CurNode++; } }
return *
this; }
3362 int GetDstNId()
const {
return CurNode.GetOutNId(CurEdge); }
3390 static PDirNet
New(
const int& Nodes,
const int& Edges) {
return new TDirNet(Nodes, Edges); }
3395 Graph->MxNId.Load(SIn); Graph->NodeH.Load(SIn);
return Graph;
3463 int AddEdge(
const int& SrcNId,
const int& DstNId);
3471 void DelEdge(
const int& SrcNId,
const int& DstNId,
const bool& IsDir =
true);
3473 bool IsEdge(
const int& SrcNId,
const int& DstNId,
const bool& IsDir =
true)
const;
3479 TEdgeI
GetEI(
const int& EId)
const;
3481 TEdgeI
GetEI(
const int& SrcNId,
const int& DstNId)
const;
3506 void Defrag(
const bool& OnlyNodeLinks=
false);
3511 bool IsOk(
const bool& ThrowExcept=
true)
const;
3513 void Dump(FILE *OutF=stdout)
const;
3682 int GetSAttrDatE(
const int& SrcNId,
const int& DstNId,
const TStr& AttrName,
TInt& ValX)
const;
3696 int GetSAttrDatE(
const int& SrcNId,
const int& DstNId,
const TStr& AttrName,
TFlt& ValX)
const;
3710 int GetSAttrDatE(
const int& SrcNId,
const int& DstNId,
const TStr& AttrName,
TStr& ValX)
const;
3724 int DelSAttrDatE(
const int& SrcNId,
const int& DstNId,
const TStr& AttrName);
3726 int DelSAttrDatE(
const int& SrcNId,
const int& DstNId,
const TInt& AttrId);
3757 friend class TDirNetMtx;
int GetSAttrVE(const TEdgeI &EdgeI, const TAttrType AttrType, TAttrPrV &AttrV) const
Gets a list of all sparse attributes of type AttrType for EdgeI.
int GetNbrEId(const int &EdgeN) const
int AddEdge(const TEdgeI &EdgeI)
Adds an edge from EdgeI.GetSrcNId() to EdgeI.GetDstNId() to the network.
TEdgeI EndEI() const
Returns an iterator referring to the past-the-end edge in 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
int AddSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to NodeI.
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.
int GetSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, TFlt &ValX) const
Gets Flt sparse attribute with name AttrName from EdgeI.
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.
void IntVAttrNameNI(const TInt &NId, TStrV &Names) const
Returns a vector of int attr names for node NId.
int DelSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName)
Deletes sparse attribute with name AttrName from EdgeI.
void Reserve(const int &Nodes, const int &Edges)
Reserves memory for a network of Nodes nodes and Edges edges.
TNodeData & GetOutNDat(const int &EdgeN)
bool IsDeleted() const
Returns true if the attribute has been deleted.
TInt GetIntAttrDatN(const TNodeI &NodeI, const TStr &attr)
Gets the value of int attr from the node attr value vector.
bool IsOutNId(const int &NId) const
int GetSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, TFlt &ValX) const
Gets Flt sparse attribute with name AttrName from NodeI.
int GetRndNId(TRnd &Rnd=TInt::Rnd)
Returns an ID of a random node in the graph.
int GetAttrIndE(const TStr &attr)
Gets the index of the edge attr value vector specified by attr.
bool DelIfIn(const TVal &Val)
Removes the first occurrence of element Val.
int GetDeg() const
Returns degree of the current node.
void Clr()
Deletes all nodes and edges from the network.
TIter EndI() const
Returns an iterator referring to the past-the-end element in the vector.
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 GetSAttrIdE(const TStr &Name, TInt &AttrIdX, TAttrType &AttrTypeX) const
Gets id and type for attribute with name Name.
static PUndirNet New()
Static constructor that returns a pointer to the network. Call: PUndirNet Graph = TUndirNet::New()...
void GetAttrENames(TStrV &IntAttrNames, TStrV &FltAttrNames, TStrV &StrAttrNames) const
Fills each of the vectors with the names of edge attributes of the given type.
int GetNodes() const
Returns the number of nodes in the graph.
TPt< TIntNEDNet > PIntNEDNet
const TEdgeDat & GetOutEDat(const int &EdgeN) const
int GetSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, TInt &ValX) const
Gets Int sparse attribute with id AttrId from NodeI.
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.
int GetSAttrIdN(const TStr &Name, TInt &AttrIdX, TAttrType &AttrTypeX) const
Gets id and type for attribute with name Name.
THash< TInt, TNode >::TIter THashIter
int GetSAttrVN(const TInt &NId, const TAttrType AttrType, TAttrPrV &AttrV) const
Gets a list of all sparse attributes of type AttrType for node with id NId.
int GetSAttrIdE(const TStr &Name, TInt &AttrIdX, TAttrType &AttrTypeX) const
Gets id and type for attribute with name Name.
#define IAssertR(Cond, Reason)
int GetOutNId(const int &EdgeN) const
Returns ID of EdgeN-th out-node (the node the current node points to).
TStr GetStrAttrDatN(const TNodeI &NodeI, const TStr &attr)
Gets the value of str attr from the node attr value vector.
THash< TStr, TFlt > FltDefaultsE
int AppendIntVAttrDatN(const TNodeI &NodeI, const TInt &value, const TStr &attr)
Appends value onto the TIntV attribute for the given node.
virtual void Save(TSOut &SOut) const
Saves the network to a (binary) stream SOut.
int AddSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, const TInt &Val)
Adds Int sparse attribute with id AttrId to EdgeI.
int GetDeg() const
Returns degree of the current node.
int AddFltAttrDatE(const TEdgeI &EdgeI, const TFlt &value, const TStr &attr)
Attribute based add function for attr to Flt value.
bool IsOutNId(const int &NId) const
Tests whether the current node points to node with ID NId.
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).
TDirNet(const TDirNet &Graph)
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.
void Save_V1(TSOut &SOut) const
Saves the network to a (binary) stream SOut. Available for backwards compatibility.
TStr GetEdgeAttrValue(const int &EId, const TStrIntPrH::TIter &EdgeHI) const
Returns edge attribute value, converted to Str type.
THash< TInt, TNode > NodeH
int GetOutDeg() const
Returns out-degree of the current node.
TEdgeI(const TNodeI &NodeI, const TNodeI &EndNodeI, const int &EdgeN=0)
int GetSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from NodeI.
enum TAttrType_ TAttrType
Types for tables, sparse and dense attributes.
TEdgeI BegEI() const
Returns an iterator referring to the first edge in the network.
int GetSAttrIdN(const TStr &Name, TInt &AttrIdX, TAttrType &AttrTypeX) const
Gets id and type for attribute with name Name.
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
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
int GetSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, TFlt &ValX) const
Gets Flt sparse attribute with id AttrId from NodeI.
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 attr (same as GetAttrIndN for compatibility...
void Save(TSOut &SOut) const
bool NodeAttrIsStrDeleted(const int &NId, const TStrIntPrH::TIter &NodeHI) const
Returns true if NId attr deleted value for current node str attr iterator.
void Save_V1(TSOut &SOut) const
Saves the graph to a (binary) stream SOut. Available for backwards compatibility. ...
int AddNode(const TNodeI &NodeI)
Adds a node NodeI and its node data to the network.
TFlt GetWeightOutEdges(const TNodeI &NI, const TStr &attr)
Gets the sum of the weights of all the outgoing edges of the node.
int DelAttrN(const TStr &attr)
Removes all the values for node attr.
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
TNode & GetNode(const int &NId)
int GetId() const
Returns edge ID. Always returns -1 since only edges in multigraphs have explicit IDs.
int GetSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, TStr &ValX) const
Gets Str sparse attribute with name AttrName from EdgeI.
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
Returns true if NId attr deleted for current node attr iterator.
int GetOutDeg() const
Returns out-degree of the current node (returns same as value GetDeg() since the network is undirecte...
int DelSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId)
Deletes sparse attribute with id AttrId from EdgeI.
int GetSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, TFlt &ValX) const
Gets Flt sparse attribute with name AttrName from NodeI.
void SortNIdById(const bool &Asc=true)
Sorts nodes by node IDs.
bool Empty() const
Tests whether the network is empty (has zero nodes).
int GetInNId(const int &NodeN) const
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 AddSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to EdgeI.
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.
int GetSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, TInt &ValX) const
Gets Int sparse attribute with id AttrId from NodeI.
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 IsStrAttrDeletedN(const int &NId, const TStr &attr) const
Returns true if Str attr exists for node NId and has default value.
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.
int AddEdge(const TEdgeI &EdgeI)
Adds an edge from EdgeI.GetSrcNId() to EdgeI.GetDstNId() to the network.
void Del(const TSizeTy &ValN)
Removes the element at position ValN.
Edge iterator. Only forward iteration (operator++) is supported.
TEdgeI EndEI() const
Returns an iterator referring to the past-the-end edge in the network.
int GetIdVSAttrN(const TStr &AttrName, TIntV &IdV) const
Gets a list of all nodes that have a sparse attribute with name AttrName.
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)
int GetSAttrVE(const TEdgeI &EdgeI, const TAttrType AttrType, TAttrPrV &AttrV) const
Gets a list of all sparse attributes of type AttrType for EdgeI.
int GetOutNId(const int &NodeN) const
void SortNIdByDat(const bool &Asc=true)
Sorts nodes by node data.
TNodeData & GetOutNDat(const int &NodeN)
int GetSAttrNameE(const TInt &AttrId, TStr &NameX, TAttrType &AttrTypeX) const
Gets name and type for attribute with id AttrId.
int GetNbrNId(const int &NodeN) const
Returns ID of NodeN-th neighboring node.
void GetNIdV(TIntV &NIdV) const
Returns a vector of all node IDs in the network.
int GetSAttrVE(const TInt &EId, const TAttrType AttrType, TAttrPrV &AttrV) const
Gets a list of all sparse attributes of type AttrType for edge with id EId.
const TNodeData & GetDat() const
int GetSAttrNameE(const TInt &AttrId, TStr &NameX, TAttrType &AttrTypeX) const
Gets name and type for attribute with id AttrId.
int GetId() const
Returns ID of the current node.
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)
int GetSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, TStr &ValX) const
Gets Str sparse attribute with id AttrId from EdgeI.
TNode & GetNode(const int &NId)
TNodeI BegNI() const
Returns an iterator referring to the first node in the network.
int AddNode(const TNodeI &NodeI)
void StrAttrNameNI(const TInt &NId, TStrV &Names) const
Returns a vector of str attr names for node NId.
TNodeI(const TNodeI &NodeI)
int AddSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to EdgeI.
int AddSAttrDatE(const TInt &EId, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to the given edge with id EId.
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)
void IntVAttrValueEI(const TInt &EId, TVec< TIntV > &Values) const
Returns a vector of attr values for edge EId.
bool operator<(const TNodeI &NodeI) const
void ReserveNIdInDeg(const int &NId, const int &InDeg)
Reserves memory for node ID NId having InDeg in-edges.
int AddNode(int NId=-1)
Adds a node of ID NId to the network.
void Save(TSOut &SOut) const
Saves the network to a (binary) stream SOut. Expects data structures for sparse attributes.
bool EdgeAttrIsFltDeleted(const int &EId, const TStrIntPrH::TIter &EdgeHI) const
Returns true if EId attr deleted for current edge flt attr iterator.
bool IsOutNId(const int &NId) const
int AddIntVAttrN(const TStr &attr)
Adds a new IntV node attribute to the hashmap.
const TNodeData & GetOutNDat(const int &EdgeN) const
TInt GetIntAttrDefaultE(const TStr &attribute) const
Gets 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
Returns true if EId attr deleted for current edge attr iterator.
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.
TFlt GetFltAttrDatE(const TEdgeI &EdgeI, const TStr &attr)
Gets the value of flt attr from the edge attr value vector.
bool operator<(const TEdgeI &EdgeI) const
TEdgeI(const TEdgeI &EdgeI)
TNodeEDatNet(const int &Nodes, const int &Edges)
Constructor that reserves enough memory for a network of Nodes nodes and Edges edges.
bool IsInNId(const int &NId) const
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.
int GetSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, TStr &ValX) const
Gets Str sparse attribute with id AttrId from EdgeI.
int AddSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, const TInt &Val)
Adds Int sparse attribute with id AttrId to EdgeI.
Tests (at compile time) if the graph is directed.
int AddIntVAttrDatE(const TEdgeI &EdgeI, const TIntV &value, const TStr &attr)
Attribute based add function for attr to IntV value.
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
bool IsAttrDeletedE(const int &EId, const TStr &attr) const
Returns true if attr exists for edge EId and has default value.
const TEdge & GetEdgeKId(const int &EdgeKeyId) const
bool IsFltAttrDeletedE(const int &EId, const TStr &attr) const
Returns true if Flt attr exists for edge NId and has default value.
const TNode & GetNode(const int &NId) const
int AddSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, const TFlt &Val)
Adds Flt sparse attribute with id AttrId to EdgeI.
bool IsNbrNId(const int &NId) const
Tests whether node with ID NId is a neighbor of the current node.
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.
int GetInDeg() const
Returns in-degree of the current node.
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 IsOutNId(const int &NId) const
Tests whether the current node points to node with ID NId.
bool EdgeAttrIsIntDeleted(const int &EId, const TStrIntPrH::TIter &EdgeHI) const
Returns true if EId attr deleted for current edge int attr iterator.
int AddSAttrDatN(const TInt &NId, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to the given node with id NId.
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...
int GetSAttrNameN(const TInt &AttrId, TStr &NameX, TAttrType &AttrTypeX) const
Gets name and type for attribute with id AttrId.
TIntV GetIntVAttrDatE(const TEdgeI &EdgeI, const TStr &attr)
Gets the value of the intv attr from the edge attr value vector.
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)
int GetSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, TInt &ValX) const
Gets Int sparse attribute with id AttrId from EdgeI.
int GetSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from EdgeI.
TStr GetStrAttrDatE(const TEdgeI &EdgeI, const TStr &attr)
Gets the value of str attr from the edge attr value vector.
Edge iterator. Only forward iteration (operator++) is supported.
int GetNbrNId(const int &NodeN) const
void SetAllEDat(const TEdgeData &EdgeDat)
Sets edge data for all the edges in the network to EDat.
bool IsInNId(const int &NId) const
void Save(TSOut &SOut) const
Saves the network to a (binary) stream SOut. Expects data structures for sparse attributes.
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.
int GetSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, TFlt &ValX) const
Gets Flt sparse attribute with id AttrId from NodeI.
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.
int GetSAttrDatN(const TInt &NId, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from node with id NId.
THash< TInt, TNode > NodeH
Node iterator. Only forward iteration (operator++) is supported.
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.
TVec< TIntV >::TIter TIntVVecIter
bool IsNbrNId(const int &NId) const
THash< TStr, TFlt > FltDefaultsN
void SortNIdById(const bool &Asc=true)
Sorts nodes by node IDs.
void Reserve(const int &Nodes, const int &Edges)
Reserves memory for a network of Nodes nodes and Edges edges.
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.
TEdgeI GetEI(const int &EId) const
Not supported/implemented!
static PUndirNet GetSmallGraph()
Returns a small network on 5 nodes and 5 edges.
int AddIntAttrDatE(const TEdgeI &EdgeI, const TInt &value, const TStr &attr)
Attribute based add function for attr to Int value.
void ReserveNIdOutDeg(const int &NId, const int &OutDeg)
Reserves memory for node ID NId having OutDeg out-edges.
int GetNbrNId(const int &EdgeN) const
Returns ID of EdgeN-th neighboring node.
int AddSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, const TStr &Val)
Adds Str sparse attribute with id AttrId to EdgeI.
int AddSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, const TInt &Val)
Adds Int sparse attribute with id AttrId to NodeI.
TEdgeI(const TNodeI &NodeI, const TNodeI &EndNodeI, const int &EdgeN=0)
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.
int GetDeg() const
Returns degree of the current node, the sum of in-degree and out-degree.
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
int AddSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, const TFlt &Val)
Adds Flt sparse attribute with name AttrName to NodeI.
TIntV GetIntVAttrDatN(const TNodeI &NodeI, const TStr &attr) const
Gets the value of the intv attr from the node attr value vector.
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
int DelSAttrDatN(const TNodeI &NodeI, const TStr &AttrName)
Deletes sparse attribute with name AttrName from NodeI.
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.
TAIntVI EndNAIntVI(const TStr &attr) const
Returns an iterator referring to the past-the-end node's attribute.
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
static PUndirNet New(const int &Nodes, const int &Edges)
Static constructor that returns a pointer to the network and reserves enough memory for Nodes nodes a...
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
int AddSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, const TInt &Val)
Adds Int sparse attribute with id AttrId to NodeI.
bool IsDeleted() const
Returns true if the attribute has been deleted.
int GetSAttrDatN(const TInt &NId, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from node with id NId.
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.
bool NodeAttrIsIntVDeleted(const int &NId, const TStrIntPrH::TIter &NodeHI) const
Returns true if NId attr deleted value for current node int vector attr iterator. ...
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...
int AddNode(const TNodeI &NodeI)
Adds a node of ID NodeI.GetId() to the graph.
int GetSAttrNameN(const TInt &AttrId, TStr &NameX, TAttrType &AttrTypeX) const
Gets name and type for attribute with id AttrId.
Node Edge Network (directed multigraph, TNEGraph with data on nodes and edges).
int GetSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, TFlt &ValX) const
Gets Flt sparse attribute with id AttrId from EdgeI.
int GetId() const
Returns edge ID.
static PUndirNet Load(TSIn &SIn)
Static constructor that loads the network from a stream SIn and returns a pointer to it...
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.
int GetNbrNId(const int &NodeN) const
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.
int DelSAttrDatN(const TNodeI &NodeI, const TStr &AttrName)
Deletes sparse attribute with name AttrName from NodeI.
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.
bool IsIntAttrDeletedE(const int &EId, const TStr &attr) const
Returns true if Int attr exists for edge EId and has default value.
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.
int GetSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, TStr &ValX) const
Gets Str sparse attribute with id AttrId from NodeI.
void Dump(FILE *OutF=stdout) const
Print the graph in a human readable form to an output stream OutF.
bool IsFltAttrDeletedN(const int &NId, const TStr &attr) const
Returns true if Flt attr exists for node NId and has default value.
void DelNode(const TNode &NodeI)
Deletes node of ID NodeI.GetId() from the network.
int AddFltAttrDatN(const TNodeI &NodeI, const TFlt &value, const TStr &attr)
Attribute based add function for attr to Flt value.
int GetInEId(const int &EdgeN) const
Returns ID of EdgeN-th in-edge.
bool NodeAttrIsFltDeleted(const int &NId, const TStrIntPrH::TIter &NodeHI) const
Returns true if NId attr deleted value for current node flt attr iterator.
int DelSAttrDatN(const TNodeI &NodeI, const TInt &AttrId)
Deletes sparse attribute with id AttrId from NodeI.
void IntVAttrValueNI(const TInt &NId, TVec< TIntV > &Values) const
Returns a vector of attr values for node NId.
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.
int AddSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, const TStr &Val)
Adds Str sparse attribute with id AttrId to NodeI.
THash< TInt, TEdge > EdgeH
static PNet New()
Static constructor that returns a pointer to the network. Call: TPt > Net = TNodeEDatNet::New().
int GetSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, TStr &ValX) const
Gets Str sparse attribute with name AttrName from EdgeI.
TNodeI(const THashIter &NodeHIter)
TAIntI GetEAIntI(const TStr &attr, const int &EId) const
Returns an iterator referring to the edge of ID EId in the graph.
void GetAttrNNames(TStrV &IntAttrNames, TStrV &FltAttrNames, TStrV &StrAttrNames) const
Fills each of the vectors with the names of node attributes of the given type.
int DelFromIntVAttrDatN(const TNodeI &NodeI, const TInt &value, const TStr &attr)
Deletes value from the TIntV attribute for the given node.
int AddIntVAttrDatN(const TNodeI &NodeI, const TIntV &value, const TStr &attr)
Attribute based add function for attr to IntV value.
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)
int GetSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, TFlt &ValX) const
Gets Flt sparse attribute with id AttrId from EdgeI.
int AddSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, const TFlt &Val)
Adds Flt sparse attribute with name AttrName to EdgeI.
int GetAttrIndN(const TStr &attr)
Gets the index of the node attr value vector specified by attr.
const TEdgeData & GetOutEDat(const int &EdgeN) const
TNodeI BegNI() const
Returns an iterator referring to the first node in the network.
TStr GetStrAttrIndDatE(const TEdgeI &EdgeI, const int &index)
Gets the value of a string edge attr specified by edge iterator EdgeI and the attr index...
bool operator==(const TNodeI &NodeI) const
bool operator==(const TEdgeI &EdgeI) const
int AddSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, const TFlt &Val)
Adds Flt sparse attribute with name AttrName to NodeI.
int GetMxNId() const
Returns an ID that is larger than any node ID in the network.
TEdgeI(const TEdgeI &EdgeI)
TAStrI BegEAStrI(const TStr &attr) const
Returns an iterator referring to the first edge's str attribute.
virtual 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)
const TNode & GetNode(const int &NId) const
TAStrI EndNAStrI(const TStr &attr) const
Returns an iterator referring to the past-the-end node's attribute.
void Save(TSOut &SOut) const
TAIntVI(const TAIntVI &I)
bool IsStrAttrDeletedE(const int &EId, const TStr &attr) const
Returns true if Str attr exists for edge NId and has default value.
TEdgeI(const TNodeI &NodeI, const TNodeI &EndNodeI, const int &EdgeN=0)
TNodeData & GetInNDat(const int &NodeN)
THash< TInt, TNode > NodeH
void Clr()
Deletes all nodes and edges from the network.
int AddEdge(const TEdgeI &EdgeI)
Adds an edge between EdgeI.GetSrcNId() and EdgeI.GetDstNId() to the network.
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.
bool IsOutEId(const int &EId) const
Tests whether the edge with ID EId is an out-edge of current node.
int GetSAttrVN(const TNodeI &NodeI, const TAttrType AttrType, TAttrPrV &AttrV) const
Gets a list of all sparse attributes of type AttrType for NodeI.
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.
int GetRndNId(TRnd &Rnd=TInt::Rnd)
Returns an ID of a random node in the network.
int GetSAttrVN(const TInt &NId, const TAttrType AttrType, TAttrPrV &AttrV) const
Gets a list of all sparse attributes of type AttrType for node with id NId.
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.
int GetOutNId(const int &NodeN) const
const TNodeData & GetDat() const
int GetSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, TStr &ValX) const
Gets Str sparse attribute with id AttrId from EdgeI.
int AddSAttrE(const TStr &Name, const TAttrType &AttrType, TInt &AttrId)
Adds mapping for sparse attribute with name Name and type AttrType.
TNEANet(const TNEANet &Graph, bool modeSubGraph)
int DelSAttrDatN(const TInt &NId, const TStr &AttrName)
Deletes sparse attribute with name AttrName from node with id NId.
int GetSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, TInt &ValX) const
Gets Int sparse attribute with id AttrId from EdgeI.
void Clr(const bool &DoDel=true, const TSizeTy &NoDelLim=-1)
Clears the contents of the vector.
Node Edge Network (directed graph, TNGraph with data on nodes and edges).
TVec< TFltV > VecOfFltVecsE
int GetInNId(const int &NodeN) const
Returns ID of NodeN-th in-node (the node pointing to the current node).
int DelSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId)
Deletes sparse attribute with id AttrId from EdgeI.
TNode & GetNode(const int &NId)
int GetFltKeyIdE(const int &EId)
Gets keyid for edge with id EId.
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.
TInt GetIntAttrDatE(const TEdgeI &EdgeI, const TStr &attr)
Gets the value of int attr from the edge attr value vector.
virtual void Save(TSOut &SOut) const
Saves the network to a (binary) stream SOut.
bool IsInNId(const int &NId) const
Tests whether node with ID NId points to the current node.
void Save(TSOut &SOut) const
Saves the attributes to a (binary) stream SOut.
int AddStrAttrDatN(const TNodeI &NodeI, const TStr &value, const TStr &attr)
Attribute based add function for attr to Str value.
TNodeI GetNI(const int &NId) const
Returns an iterator referring to the node of ID NId in the network.
int DelSAttrDatN(const TNodeI &NodeI, const TInt &AttrId)
Deletes sparse attribute with id AttrId from NodeI.
int AddSAttrDatN(const TInt &NId, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to the given node with id NId.
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 GetIntVAttrVal(TVec< TIntV > &Val) const
Gets vector of int attribute values.
void FltAttrValueEI(const TInt &EId, TFltV &Values) const
Returns a vector of attr values for node NId.
TNodeI GetRndNI(TRnd &Rnd=TInt::Rnd)
Returns an interator referring to a random node in the network.
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...
TNodeI(const TNodeI &NodeI)
int GetSAttrDatE(const TInt &EId, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from edge with id EId.
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.
int GetSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, TFlt &ValX) const
Gets Flt sparse attribute with name AttrName from NodeI.
bool IsOutNId(const int &NId) const
bool Empty() const
Tests whether the network is empty (has zero nodes).
int GetNbrNId(const int &NodeN) const
Returns ID of NodeN-th neighboring node.
int GetSAttrIdE(const TStr &Name, TInt &AttrIdX, TAttrType &AttrTypeX) const
Gets id and type for attribute with name Name.
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
void Reserve(const int &Nodes, const int &Edges)
Reserves memory for a graph of Nodes nodes and Edges edges.
int GetSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from EdgeI.
static PUndirNet Load_V1(TSIn &SIn)
Static constructor that loads the network from a stream SIn and returns a pointer to it...
void ReserveNIdDeg(const int &NId, const int &Deg)
Reserves memory for node ID NId having Deg edges.
TEdgeI & operator=(const TEdgeI &EdgeI)
TEdgeI & operator++(int)
Increment iterator.
TNode & GetNode(const int &NId)
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 GetSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, TStr &ValX) const
Gets Str sparse attribute with name AttrName from EdgeI.
int GetDstNId() const
Gets the destination node of an edge.
int AddNode(const TNodeI &NodeId)
Adds a node of ID NodeI.GetId() to the network.
bool operator<(const TNode &Node) const
int AddSAttrDatE(const int &SrcNId, const int &DstNId, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to the given edge with ids SrcId and DstId...
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 GetSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, TFlt &ValX) const
Gets Flt sparse attribute with name AttrName from EdgeI.
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
Gets 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 DelSAttrDatN(const TNodeI &NodeI, const TInt &AttrId)
Deletes sparse attribute with id AttrId from NodeI.
int AddSAttrDatN(const TInt &NId, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to the given node with id NId.
int GetMxNId() const
Returns an ID that is larger than any node ID in the network.
bool FNextKeyId(int &KeyId) const
int GetSAttrDatE(const int &SrcNId, const int &DstNId, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from edge with ids SrcId and DstId.
TNodeI(const THashIter &NodeHIter)
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
TAIntVI EndEAIntVI(const TStr &attr) const
Returns an iterator referring to the past-the-end edge's attribute.
THash< TInt, TNode > NodeH
void DelNode(const TNode &NodeI)
Deletes node of ID NodeI.GetId() from the graph.
int GetIdVSAttrE(const TStr &AttrName, TIntPrV &IdV) const
Gets a list of all edges that have a sparse attribute with name AttrName.
TNodeNet(TSIn &SIn)
Constructor that loads the network from a (binary) stream SIn.
bool Empty() const
Tests whether the network is empty (has zero nodes).
int AddStrAttrE(const TStr &attr, TStr defaultValue=TStr::GetNullStr())
Adds a new Str edge attribute to the hashmap.
TFlt GetFltAttrDatN(const TNodeI &NodeI, const TStr &attr)
Gets the value of flt attr from the node attr value vector.
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.
int AddSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, const TStr &Val)
Adds Str sparse attribute with name AttrName to NodeI.
void SortNIdByDat(const bool &Asc=true)
Sorts nodes by node data.
const TNodeData & operator()() const
bool IsNbrNId(const int &NId) const
Tests whether node with ID NId is a neighbor of the current node.
bool IsOk(const bool &ThrowExcept=true) const
Checks the network data structure for internal consistency.
TNodeEDatNet< TNodeData, TEdgeData > TNet
TNodeI(const TNodeI &NodeI)
TInt GetIntAttrIndDatN(const TNodeI &NodeI, const int &index)
Gets the value of an int node attr specified by node iterator NodeI and the attr index.
void IntVAttrNameEI(const TInt &EId, TStrV &Names) const
Returns a vector of int attr names for edge EId.
bool IsInNId(const int &NId) const
bool IsInNId(const int &NId) const
Tests whether node with ID NId points to the current node.
TAIntVI GetNAIntVI(const TStr &attr, const int &NId) const
Returns an iterator referring to the node of ID NId in the graph.
int AddKey(const TKey &Key)
int AddSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, const TFlt &Val)
Adds Flt sparse attribute with id AttrId to EdgeI.
void Save(TSOut &SOut) const
int GetId() const
Returns edge ID. Always returns -1 since only edges in multigraphs have explicit IDs.
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.
TPt< TUndirNet > PUndirNet
Pointer to an undirected network (TUndirNet)
int GetSAttrNameN(const TInt &AttrId, TStr &NameX, TAttrType &AttrTypeX) const
Gets name and type for attribute with id AttrId.
int AddSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to NodeI.
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)
THash< TInt, TNode >::TIter THashIter
TVec< TPair< TInt, TEdgeData > > TNIdDatPrV
int AddSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, const TStr &Val)
Adds Str sparse attribute with name AttrName to NodeI.
TStr GetStrAttrDefaultN(const TStr &attribute) const
Gets 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
Returns node attribute value, converted to Str type.
int GetInNId(const int &NodeN) const
Returns ID of NodeN-th in-node (the node pointing to the current node).
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.
TVec< TVec< TIntV > > VecOfIntVecVecsE
TNodeEdgeNet & operator=(const TNodeEdgeNet &Net)
void GetAttrVal(TStrV &Val) const
Gets vector of attribute values.
int GetSAttrDatE(const int &SrcNId, const int &DstNId, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from edge with ids SrcId and DstId.
int AddSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, const TStr &Val)
Adds Str sparse attribute with name AttrName to EdgeI.
int GetOutNId(const int &NodeN) const
Returns ID of NodeN-th out-node (the node the current node points to).
int GetDstNId() const
Returns the destination of the edge. Since the network is undirected, this is the node with a greater...
TNodeI EndNI() const
Returns an iterator referring to the past-the-end node in the network.
int AddSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, const TFlt &Val)
Adds Flt sparse attribute with name AttrName to EdgeI.
TEdgeI(const TEdgeI &EdgeI)
int GetRndNId(TRnd &Rnd=TInt::Rnd)
Returns an ID of a random node in the network.
bool IsInNId(const int &NId) const
int AddSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, const TStr &Val)
Adds Str sparse attribute with id AttrId to EdgeI.
THash< TInt, TEdge > EdgeH
TEdgeI BegEI() const
Returns an iterator referring to the first edge in the network.
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.
int GetSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, TStr &ValX) const
Gets Str sparse attribute with name AttrName from NodeI.
Directed multigraph with node edge attributes.
bool operator==(const TEdgeI &EdgeI) const
TEdgeData & GetOutEDat(const int &EdgeN)
static PDirNet New(const int &Nodes, const int &Edges)
Static constructor that returns a pointer to the network and reserves enough memory for Nodes nodes a...
void GetAttrNames(TStrV &Names) const
Gets vector of attribute names.
int AddSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, const TStr &Val)
Adds Str sparse attribute with id AttrId to NodeI.
void GetFltAttrVal(TFltV &Val) const
Gets vector of flt attribute values.
bool Empty() const
Tests whether the graph is empty (has zero nodes).
TSizeTy SearchBin(const TVal &Val) const
Returns the position of an element with value Val.
int DelSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName)
Deletes sparse attribute with name AttrName from EdgeI.
TAStrI BegNAStrI(const TStr &attr) const
Returns an iterator referring to the first node's str attribute.
int AddSAttrDatE(const int &SrcNId, const int &DstNId, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to the given edge with ids SrcId and DstId...
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 AddNode(const TNodeI &NodeI)
Adds a node NodeI and its node data to the network.
int GetSrcNId() const
Gets the source of an edge.
bool IsIntAttrE(const TStr &attr)
Checks if there is an edge attribute with name attr.
int GetMxNId() const
Returns an ID that is larger than any node ID in the network.
int GetSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, TFlt &ValX) const
Gets Flt sparse attribute with id AttrId from NodeI.
bool IsInEId(const int &EId) const
int AddSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to EdgeI.
static PNEANet GetSmallGraph()
Returns a small multigraph on 5 nodes and 6 edges.
bool IsIntVAttrDeletedE(const int &EId, const TStr &attr) const
Returns true if IntV attr exists for edge EId and is an empty vector.
int AddSAttrN(const TStr &Name, const TAttrType &AttrType, TInt &AttrId)
Adds mapping for sparse attribute with name Name and type AttrType.
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.
int AddSAttrE(const TStr &Name, const TAttrType &AttrType, TInt &AttrId)
Adds mapping for sparse attribute with name Name and type AttrType.
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.
const TNode & GetNode(const int &NId) const
TAIntVI BegEAIntVI(const TStr &attr) const
Returns an iterator referring to the first edge's int attribute.
void Dump(FILE *OutF=stdout) const
Print the network in a human readable form to an output stream OutF.
int GetNbrNId(const int &EdgeN) const
bool IsFltAttrE(const TStr &attr)
Checks if there is an edge attribute with name attr.
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
Edge iterator. Only forward iteration (operator++) is supported.
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 GetSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, TStr &ValX) const
Gets Str sparse attribute with id AttrId from NodeI.
int GetRndNId(TRnd &Rnd=TInt::Rnd)
Returns an ID of a random node in the network.
TAIntVI GetEAIntVI(const TStr &attr, const int &EId) const
Returns an iterator referring to the edge of ID EId in the graph.
bool IsNbrNId(const int &NId) const
bool EdgeAttrIsIntVDeleted(const int &EId, const TStrIntPrH::TIter &EdgeHI) const
Returns true if EId attr deleted for current edge int vector attr iterator.
TUndirNet(const TUndirNet &Graph)
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
TUndirNet(const int &Nodes, const int &Edges)
Constructor that reserves enough memory for a network of Nodes nodes and Edges edges.
TNodeNet< TInt > TIntNNet
TNodeNet< TFlt > TFltNNet
int GetSAttrVN(const TNodeI &NodeI, const TAttrType AttrType, TAttrPrV &AttrV) const
Gets a list of all sparse attributes of type AttrType for NodeI.
int AddNode(int NId=-1)
Adds a node of ID NId to the network.
bool IsIntAttrDeletedN(const int &NId, const TStr &attr) const
Returns true if Int attr exists for node NId and has default value.
Edge iterator. Only forward iteration (operator++) is supported.
int DelAttrDatE(const TEdgeI &EdgeI, const TStr &attr)
Deletes the edge attribute for NodeI.
void Reserve(const int &Nodes, const int &Edges)
Reserves memory for a network of Nodes nodes and Edges edges.
int GetNodes() const
Returns the number of nodes in the network.
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.
int AddNode(const TNodeI &NodeI)
Adds a node of ID NodeI.GetId() to the network.
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.
int DelSAttrDatE(const int &SrcNId, const int &DstNId, const TStr &AttrName)
Deletes sparse attribute with name AttrName from edge with ids SrcId and DstId.
void Clr()
Deletes all nodes and edges from 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 Clr()
Clears the contents of the attribute map.
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
Gets 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
TNodeI GetRndNI(TRnd &Rnd=TInt::Rnd)
Returns an interator referring to a random node in the network.
TNodeNet< TNodeData > TNet
static PDirNet Load_V1(TSIn &SIn)
Static constructor that loads the network from a stream SIn and returns a pointer to it...
int GetSAttrIdN(const TStr &Name, TInt &AttrIdX, TAttrType &AttrTypeX) const
Gets id and type for attribute with name Name.
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
Returns true if EId attr deleted for current edge str attr iterator.
void Save(TSOut &SOut) const
Saves the graph to a (binary) stream SOut. Expects data structures for sparse attributes.
TAIntVI(const TIntVVecIter &HIter, TStr attribute, bool isEdgeIter, const TNEANet *GraphPt)
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)
int GetDstNId() const
Returns the destination node of the edge.
TAIntVI BegNAIntVI(const TStr &attr) const
Returns an iterator referring to the first node's int attribute.
int AddStrAttrDatE(const TEdgeI &EdgeI, const TStr &value, const TStr &attr)
Attribute based add function for attr to Str value.
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)
static PNEANet Load_V1(TSIn &SIn)
Static constructor that loads the graph from a stream SIn and returns a pointer to it...
TEdgeI(const TEdgeI &EdgeI)
TIter BegI() const
Returns an iterator pointing to the first element in the vector.
static TStr Fmt(const char *FmtStr,...)
void Save(TSOut &SOut) const
Saves the attributes to a (binary) stream SOut.
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()
Reduces vector 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 DelSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName)
Deletes sparse attribute with name AttrName from EdgeI.
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
int GetOutDeg() const
Returns out-degree of the current node.
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 GetSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, TStr &ValX) const
Gets Str sparse attribute with id AttrId from NodeI.
void GetWeightOutEdgesV(TFltV &OutWeights, const TFltV &AttrVal)
Fills OutWeights with the outgoing weight from each node.
int GetMxEId() const
Returns an ID that is larger than any edge ID in the network.
int GetSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, TStr &ValX) const
Gets Str sparse attribute with name AttrName from NodeI.
int GetEdges() const
Returns the number of edges in the network.
int GetIdVSAttrN(const TStr &AttrName, TIntV &IdV) const
Gets a list of all nodes that have a sparse attribute with name AttrName.
int GetNbrEId(const int &EdgeN) const
Returns ID of EdgeN-th in or out-edge.
int DelSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId)
Deletes sparse attribute with id AttrId from EdgeI.
bool IsAttrDeletedN(const int &NId, const TStr &attr) const
Returns true if attr exists for node NId and has default value.
const TEdgeData & GetDat() const
int AddSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, const TFlt &Val)
Adds Flt sparse attribute with id AttrId to NodeI.
int AddSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, const TFlt &Val)
Adds Flt sparse attribute with id AttrId to EdgeI.
TVec< TFltV > VecOfFltVecsN
int GetSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from NodeI.
TAFltI EndEAFltI(const TStr &attr) const
Returns an iterator referring to the past-the-end edge's attribute.
int GetSAttrVE(const int &SrcNId, const int &DstNId, const TAttrType AttrType, TAttrPrV &AttrV) const
Gets a list of all sparse attributes of type AttrType for edge with ids SrcId and DstId...
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)
int AddSAttrE(const TStr &Name, const TAttrType &AttrType, TInt &AttrId)
Adds mapping for sparse attribute with name Name and type AttrType.
int AddSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, const TFlt &Val)
Adds Flt sparse attribute with name AttrName to EdgeI.
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)
int GetSAttrDatN(const TInt &NId, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from node with id NId.
void Save(TSOut &SOut) const
const TNodeData & GetNbrNDat(const int &EdgeN) const
int AddSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, const TStr &Val)
Adds Str sparse attribute with name AttrName to EdgeI.
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.
TNodeI GetNI(const int &NId) const
Returns an iterator referring to the node of ID NId in the network.
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.
int AddSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, const TStr &Val)
Adds Str sparse attribute with name AttrName to NodeI.
void GetIntVAttrNames(TStrV &Names) const
Gets vector of int attribute names.
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.
int GetSAttrNameE(const TInt &AttrId, TStr &NameX, TAttrType &AttrTypeX) const
Gets name and type for attribute with id AttrId.
void Clr(const bool &DoDel=true, const int &NoDelLim=-1, const bool &ResetDat=true)
TIntPr OrderEdgeNodes(const int &SrcNId, const int &DstNId) const
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
TVec< TFlt > & GetFltAttrVecE(const TStr &attr)
Gets Vector for the Flt Attribute attr.
int GetSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, TFlt &ValX) const
Gets Flt sparse attribute with id AttrId from EdgeI.
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.
int GetNodes() const
Returns the number of nodes in the network.
int GetRndNId(TRnd &Rnd=TInt::Rnd)
Returns an ID of a random node in the network.
bool IsInNId(const int &NId) const
Tests whether node with ID NId points to the current node.
int GetOutNId(const int &NodeN) const
Returns ID of NodeN-th out-node (the node the current node points to).
void Defrag(const bool &OnlyNodeLinks=false)
Defragments the network.
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
Returns true if NId attr deleted value for current node int attr iterator.
int GetOutDeg() const
Returns out-degree of the current node.
bool IsIntVAttrDeletedN(const int &NId, const TStr &attr) const
Returns true if IntV attr exists for node NId and is an empty vector.
THash< TInt, TNode > NodeH
int AppendIntVAttrDatE(const TEdgeI &EdgeI, const TInt &value, const TStr &attr)
Appends value onto the TIntV attribute for the given node.
int GetSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, TInt &ValX) const
Gets Int sparse attribute with id AttrId from NodeI.
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.
static PDirNet New()
Static constructor that returns a pointer to the network. Call: PDirNet Graph = TDirNet::New().
TEdge & GetEdge(const int &EId)
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
int GetSAttrVN(const TNodeI &NodeI, const TAttrType AttrType, TAttrPrV &AttrV) const
Gets a list of all sparse attributes of type AttrType for NodeI.
int GetSrcNId() const
Returns the source of the edge. Since the network is undirected, this is the node with a smaller ID o...
TEdgeI & operator=(const TEdgeI &EdgeI)
TFlt GetFltAttrIndDatN(const TNodeI &NodeI, const int &index)
Gets the value of a float node attr specified by node iterator NodeI and the attr index...
int GetDstNId() const
Gets the destination node of an edge.
TDirNet(TSIn &SIn)
Constructor that loads the network from a (binary) stream SIn.
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.
TVec< TVec< TIntV > > VecOfIntVecVecsN
int AddIntAttrE(const TStr &attr, TInt defaultValue=TInt::Mn)
Adds a new Int edge attribute to the hashmap.
TEdgeI BegEI() const
Returns an iterator referring to the first edge in the network.
int AddSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, const TInt &Val)
Adds Int sparse attribute with id AttrId to NodeI.
int AddSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, const TStr &Val)
Adds Str sparse attribute with name AttrName to EdgeI.
void Reserve(const TSizeTy &_MxVals)
Reserves enough memory for the vector to store _MxVals elements.
int GetSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from EdgeI.
TEdge(const int &EId, const int &SourceNId, const int &DestNId)
void Dump(FILE *OutF=stdout) const
Print the network in a human readable form to an output stream OutF.
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
Gets 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
TEdgeI EndEI() const
Returns an iterator referring to the past-the-end edge in the network.
int GetIdVSAttrE(const TStr &AttrName, TIntPrV &IdV) const
Gets a list of all edges that have a sparse attribute with name AttrName.
int AddSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, const TFlt &Val)
Adds Flt sparse attribute with id AttrId to NodeI.
void IntAttrNameEI(const TInt &EId, TStrV &Names) const
Returns a vector of int attr names for edge EId.
int GetSAttrDatE(const TEdgeI &EdgeI, const TStr &AttrName, TFlt &ValX) const
Gets Flt sparse attribute with name AttrName from EdgeI.
int GetIdVSAttrE(const TStr &AttrName, TIntV &IdV) const
Gets a list of all edges that have a sparse attribute with name AttrName.
TNodeI BegNI() const
Returns an iterator referring to the first node in the network.
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
Gets 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.
int AddIntVAttrE(const TStr &attr)
Adds a new IntV edge attribute to the hashmap.
int GetInNId(const int &NodeN) const
void DelNode(const TNode &NodeI)
Deletes node of ID NodeI.GetId() from the network.
bool IsOutNId(const int &NId) const
TDirNet(const int &Nodes, const int &Edges)
Constructor that reserves enough memory for a network of Nodes nodes and Edges edges.
TNodeData & GetNbrNDat(const int &NodeN)
int GetInDeg() const
Returns in-degree of the current node (returns same as value GetDeg() since the network is undirected...
Node iterator. Only forward iteration (operator++) is supported.
int GetSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, TStr &ValX) const
Gets Str sparse attribute with name AttrName from NodeI.
int DelSAttrDatN(const TNodeI &NodeI, const TStr &AttrName)
Deletes sparse attribute with name AttrName from NodeI.
int AddSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, const TFlt &Val)
Adds Flt sparse attribute with name AttrName to NodeI.
TPt< TNEANet > PNEANet
Pointer to a directed attribute multigraph (TNEANet)
bool IsKey(const TKey &Key) const
TIntV GetDat() const
Returns an attribute of the node.
static PDirNet Load(TSIn &SIn)
Static constructor that loads the network from a stream SIn and returns a pointer to it...
const TEdge & GetEdge(const int &EId) const
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
int GetSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, TInt &ValX) const
Gets Int sparse attribute with id AttrId from EdgeI.
int GetSAttrVN(const TInt &NId, const TAttrType AttrType, TAttrPrV &AttrV) const
Gets a list of all sparse attributes of type AttrType for node with id NId.
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 DelSAttrDatE(const TInt &EId, const TStr &AttrName)
Deletes sparse attribute with name AttrName from edge with id EId.
int GetSAttrVE(const int &SrcNId, const int &DstNId, const TAttrType AttrType, TAttrPrV &AttrV) const
Gets a list of all sparse attributes of type AttrType for edge with ids SrcId and DstId...
bool IsOk(const bool &ThrowExcept=true) const
Checks the network data structure for internal consistency.
int GetIdVSAttrN(const TStr &AttrName, TIntV &IdV) const
Gets a list of all nodes that have a sparse attribute with name AttrName.
int DelSAttrDatE(const int &SrcNId, const int &DstNId, const TStr &AttrName)
Deletes sparse attribute with name AttrName from edge with ids SrcId and DstId.
bool IsStrAttrE(const TStr &attr)
Checks if there is an edge attribute with name attr.
TAIntVI & operator++(int)
TNodeI(const TNodeI &NodeI)
int GetSrcNId() const
Returns the source node of the edge.
TNodeData & GetOutNDat(const int &NodeN)
int DelAttrDatN(const TNodeI &NodeI, const TStr &attr)
Deletes the node attribute for NodeI.
int GetDeg() const
Returns degree of the current node, the sum of in-degree and out-degree.
int DelSAttrDatN(const TInt &NId, const TStr &AttrName)
Deletes sparse attribute with name AttrName from node with id NId.
TIter GetI(const TSizeTy &ValN) const
Returns an iterator an element at position ValN.
void GetStrAttrNames(TStrV &Names) const
Gets vector of str attribute names.
TNEANet(bool copyAll, const TNEANet &Graph)
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
static PDirNet GetSmallGraph()
Returns a small network on 5 nodes and 6 edges.
TEdgeDat & GetInEDat(const int &EdgeN)
int GetSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from NodeI.
void Save(TSOut &SOut) const
int GetSAttrVE(const TEdgeI &EdgeI, const TAttrType AttrType, TAttrPrV &AttrV) const
Gets a list of all sparse attributes of type AttrType for EdgeI.
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.
int AddIntAttrDatN(const TNodeI &NodeI, const TInt &value, const TStr &attr)
Attribute based add function for attr to Int value.
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 attr (same as GetAttrIndE for compatibility...
int AddSAttrDatN(const TNodeI &NodeI, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to NodeI.
int AddSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, const TStr &Val)
Adds Str sparse attribute with id AttrId to EdgeI.
void GetIntVAttrVal(TVec< TIntV > &Val) const
Gets vector of int attribute values.
TAFltI(const TFltVecIter &HIter, TStr attribute, bool isEdgeIter, const TNEANet *GraphPt)
void Save(TSOut &SOut) const
TStr GetStrAttrIndDatN(const TNodeI &NodeI, const int &index)
Gets the value of a string node attr specified by node iterator NodeI and the attr index...
int DelSAttrDatN(const TInt &NId, const TStr &AttrName)
Deletes sparse attribute with name AttrName from node with id NId.
THash< TInt, TNode >::TIter THashIter
TEdgeI(const TNodeI &NodeI, const TNodeI &EndNodeI, const int &EdgeN=0)
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.
TNodeI EndNI() const
Returns an iterator referring to the past-the-end node in the network.
Node iterator. Only forward iteration (operator++) is supported.
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.
void Clr()
Clears the contents of the attribute map.
const TKey & GetKey(const int &KeyId) const
int AddSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, const TStr &Val)
Adds Str sparse attribute with id AttrId to NodeI.
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 AddSAttrDatE(const TEdgeI &EdgeI, const TInt &AttrId, const TInt &Val)
Adds Int sparse attribute with id AttrId to EdgeI.
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
int GetId() const
Returns ID of the current node.
TEdgeI BegEI() const
Returns an iterator referring to the first edge in the network.
TUndirNet(TSIn &SIn)
Constructor that loads the network from a (binary) stream SIn.
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 AddSAttrDatN(const TNodeI &NodeI, const TInt &AttrId, const TFlt &Val)
Adds Flt sparse attribute with id AttrId to NodeI.
int GetNbrNId(const int &NodeN) const
void GetIntVAttrNames(TStrV &Names) const
Gets vector of int attribute names.
bool operator==(const TNodeI &NodeI) const
TPt< TDirNet > PDirNet
Pointer to a directed network (TDirNet)
int AddSAttrN(const TStr &Name, const TAttrType &AttrType, TInt &AttrId)
Adds mapping for sparse attribute with name Name and type AttrType.
static PNet Load(TSIn &SIn)
Static constructor that loads the network from a stream SIn and returns a pointer to it...
TFlt GetFltAttrIndDatE(const TEdgeI &EdgeI, const int &index)
Gets the value of a float edge attr specified by edge iterator EdgeI and the attr index...
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.
TInt GetIntAttrIndDatE(const TEdgeI &EdgeI, const int &index)
Gets the value of an int edge attr specified by edge iterator EdgeI and the attr index.
TNodeI GetRndNI(TRnd &Rnd=TInt::Rnd)
Returns an interator referring to a random node in the network.
int AddSAttrN(const TStr &Name, const TAttrType &AttrType, TInt &AttrId)
Adds mapping for sparse attribute with name Name and type AttrType.
TIter GetI(const TKey &Key) const
void SortByDat(const bool &Asc=true)
TPt< TFltNENet > PFltNENet
Implements a single CrossNet consisting of edges between two TModeNets (could be the same TModeNet) ...
int GetMxNId() const
Returns an ID that is larger than any node ID in the network.
void Save_V1(TSOut &SOut) const
Saves the network to a (binary) stream SOut. Available for backwards compatibility.
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.