43 TNode(
const int& NId) : Id(NId), NIdV() { }
44 TNode(
const TNode& Node) : Id(Node.Id), NIdV(Node.NIdV) { }
57 int GetNbrNId(
const int& NodeN)
const {
return NIdV[NodeN]; }
74 TNodeI(
const THashIter& NodeHIter) : NodeHI(NodeHIter) { }
88 int GetId()
const {
return NodeHI.GetDat().GetId(); }
90 int GetDeg()
const {
return NodeHI.GetDat().GetDeg(); }
92 int GetInDeg()
const {
return NodeHI.GetDat().GetInDeg(); }
94 int GetOutDeg()
const {
return NodeHI.GetDat().GetOutDeg(); }
96 void SortNIdV() { NodeHI.GetDat().SortNIdV(); }
101 int GetInNId(
const int& NodeN)
const {
return NodeHI.GetDat().GetInNId(NodeN); }
106 int GetOutNId(
const int& NodeN)
const {
return NodeHI.GetDat().GetOutNId(NodeN); }
111 int GetNbrNId(
const int& NodeN)
const {
return NodeHI.GetDat().GetNbrNId(NodeN); }
113 bool IsInNId(
const int& NId)
const {
return NodeHI.GetDat().IsInNId(NId); }
115 bool IsOutNId(
const int& NId)
const {
return NodeHI.GetDat().IsOutNId(NId); }
117 bool IsNbrNId(
const int& NId)
const {
return NodeHI.GetDat().IsNbrNId(NId); }
126 TEdgeI() : CurNode(), EndNode(), CurEdge(0) { }
127 TEdgeI(
const TNodeI& NodeI,
const TNodeI& EndNodeI,
const int& EdgeN=0) : CurNode(NodeI), EndNode(EndNodeI), CurEdge(EdgeN) { }
128 TEdgeI(
const TEdgeI& EdgeI) : CurNode(EdgeI.CurNode), EndNode(EdgeI.EndNode), CurEdge(EdgeI.CurEdge) { }
157 NEdges =
TInt(ShMIn);
162 TUNGraph() : CRef(), MxNId(0), NEdges(0), NodeH() { }
164 explicit TUNGraph(
const int& Nodes,
const int& Edges) : MxNId(0), NEdges(0) {
Reserve(Nodes, Edges); }
165 TUNGraph(
const TUNGraph& Graph) : MxNId(Graph.MxNId), NEdges(Graph.NEdges), NodeH(Graph.NodeH) { }
189 if (
this!=&Graph) { MxNId=Graph.
MxNId; NEdges=Graph.
NEdges; NodeH=Graph.
NodeH; }
return *
this; }
252 int AddEdge(
const int& SrcNId,
const int& DstNId);
254 int AddEdge(
const int& SrcNId,
const int& DstNId,
const int& EId) {
return AddEdge(SrcNId, DstNId); }
265 int AddEdge2(
const int& SrcNId,
const int& DstNId);
272 void DelEdge(
const int& SrcNId,
const int& DstNId);
274 bool IsEdge(
const int& SrcNId,
const int& DstNId)
const;
276 bool IsEdge(
const int& EId)
const {
return false; }
282 TEdgeI
GetEI(
const int& EId)
const;
286 TEdgeI
GetEI(
const int& SrcNId,
const int& DstNId)
const;
298 void Clr() { MxNId=0; NEdges=0; NodeH.
Clr(); }
302 void Reserve(
const int& Nodes,
const int& Edges) {
if (Nodes>0) NodeH.
Gen(Nodes/2); }
310 void Defrag(
const bool& OnlyNodeLinks=
false);
314 bool IsOk(
const bool& ThrowExcept=
true)
const;
316 void Dump(FILE *OutF=stdout)
const;
356 TNode() : Id(-1), InNIdV(), OutNIdV() { }
357 TNode(
const int& NId) : Id(NId), InNIdV(), OutNIdV() { }
358 TNode(
const TNode& Node) : Id(Node.Id), InNIdV(Node.InNIdV), OutNIdV(Node.OutNIdV) { }
359 TNode(
TSIn& SIn) : Id(SIn), InNIdV(SIn), OutNIdV(SIn) { }
365 int GetInNId(
const int& NodeN)
const {
return InNIdV[NodeN]; }
366 int GetOutNId(
const int& NodeN)
const {
return OutNIdV[NodeN]; }
389 TNodeI(
const THashIter& NodeHIter) : NodeHI(NodeHIter) { }
400 int GetId()
const {
return NodeHI.GetDat().GetId(); }
402 int GetDeg()
const {
return NodeHI.GetDat().GetDeg(); }
404 int GetInDeg()
const {
return NodeHI.GetDat().GetInDeg(); }
406 int GetOutDeg()
const {
return NodeHI.GetDat().GetOutDeg(); }
412 int GetInNId(
const int& NodeN)
const {
return NodeHI.GetDat().GetInNId(NodeN); }
416 int GetOutNId(
const int& NodeN)
const {
return NodeHI.GetDat().GetOutNId(NodeN); }
420 int GetNbrNId(
const int& NodeN)
const {
return NodeHI.GetDat().GetNbrNId(NodeN); }
422 bool IsInNId(
const int& NId)
const {
return NodeHI.GetDat().IsInNId(NId); }
424 bool IsOutNId(
const int& NId)
const {
return NodeHI.GetDat().IsOutNId(NId); }
435 TEdgeI() : CurNode(), EndNode(), CurEdge(0) { }
436 TEdgeI(
const TNodeI& NodeI,
const TNodeI& EndNodeI,
const int& EdgeN=0) : CurNode(NodeI), EndNode(EndNodeI), CurEdge(EdgeN) { }
437 TEdgeI(
const TEdgeI& EdgeI) : CurNode(EdgeI.CurNode), EndNode(EdgeI.EndNode), CurEdge(EdgeI.CurEdge) { }
441 while (CurNode < EndNode && CurNode.
GetOutDeg()==0) { CurNode++; } }
return *
this; }
474 explicit TNGraph(
const int& Nodes,
const int& Edges) : MxNId(0) {
Reserve(Nodes, Edges); }
500 if (
this!=&Graph) { MxNId=Graph.
MxNId; NodeH=Graph.
NodeH; }
return *
this; }
567 int AddEdge(
const int& SrcNId,
const int& DstNId);
569 int AddEdge(
const int& SrcNId,
const int& DstNId,
const int& EId) {
return AddEdge(SrcNId, DstNId); }
580 int AddEdge2(
const int& SrcNId,
const int& DstNId);
588 void DelEdge(
const int& SrcNId,
const int& DstNId,
const bool& IsDir =
true);
590 bool IsEdge(
const int& SrcNId,
const int& DstNId,
const bool& IsDir =
true)
const;
592 bool IsEdge(
const int& EId)
const {
return false; }
598 TEdgeI
GetEI(
const int& EId)
const;
600 TEdgeI
GetEI(
const int& SrcNId,
const int& DstNId)
const;
614 void Reserve(
const int& Nodes,
const int& Edges) {
if (Nodes>0) { NodeH.
Gen(Nodes/2); } }
627 void Defrag(
const bool& OnlyNodeLinks=
false);
632 bool IsOk(
const bool& ThrowExcept=
true)
const;
634 void Dump(FILE *OutF=stdout)
const;
675 TNode() : Id(-1), InEIdV(), OutEIdV() { }
676 TNode(
const int& NId) : Id(NId), InEIdV(), OutEIdV() { }
677 TNode(
const TNode& Node) : Id(Node.Id), InEIdV(Node.InEIdV), OutEIdV(Node.OutEIdV) { }
678 TNode(
TSIn& SIn) : Id(SIn), InEIdV(SIn), OutEIdV(SIn) { }
684 int GetInEId(
const int& EdgeN)
const {
return InEIdV[EdgeN]; }
685 int GetOutEId(
const int& EdgeN)
const {
return OutEIdV[EdgeN]; }
695 TEdge() : Id(-1), SrcNId(-1), DstNId(-1) { }
696 TEdge(
const int& EId,
const int& SourceNId,
const int& DestNId) : Id(EId), SrcNId(SourceNId), DstNId(DestNId) { }
697 TEdge(
const TEdge& Edge) : Id(Edge.Id), SrcNId(Edge.SrcNId), DstNId(Edge.DstNId) { }
698 TEdge(
TSIn& SIn) : Id(SIn), SrcNId(SIn), DstNId(SIn) { }
713 TNodeI(
const THashIter& NodeHIter,
const TNEGraph* GraphPt) : NodeHI(NodeHIter), Graph(GraphPt) { }
714 TNodeI(
const TNodeI& NodeI) : NodeHI(NodeI.NodeHI), Graph(NodeI.Graph) { }
724 int GetId()
const {
return NodeHI.GetDat().GetId(); }
726 int GetDeg()
const {
return NodeHI.GetDat().GetDeg(); }
728 int GetInDeg()
const {
return NodeHI.GetDat().GetInDeg(); }
730 int GetOutDeg()
const {
return NodeHI.GetDat().GetOutDeg(); }
734 int GetInNId(
const int& EdgeN)
const {
return Graph->
GetEdge(NodeHI.GetDat().GetInEId(EdgeN)).GetSrcNId(); }
738 int GetOutNId(
const int& EdgeN)
const {
return Graph->
GetEdge(NodeHI.GetDat().GetOutEId(EdgeN)).GetDstNId(); }
745 bool IsInNId(
const int& NId)
const;
747 bool IsOutNId(
const int& NId)
const;
752 int GetInEId(
const int& EdgeN)
const {
return NodeHI.GetDat().GetInEId(EdgeN); }
754 int GetOutEId(
const int& EdgeN)
const {
return NodeHI.GetDat().GetOutEId(EdgeN); }
756 int GetNbrEId(
const int& EdgeN)
const {
return NodeHI.GetDat().GetNbrEId(EdgeN); }
758 bool IsInEId(
const int& EId)
const {
return NodeHI.GetDat().IsInEId(EId); }
760 bool IsOutEId(
const int& EId)
const {
return NodeHI.GetDat().IsOutEId(EId); }
773 TEdgeI(
const THashIter& EdgeHIter,
const TNEGraph *GraphPt) : EdgeHI(EdgeHIter), Graph(GraphPt) { }
774 TEdgeI(
const TEdgeI& EdgeI) : EdgeHI(EdgeI.EdgeHI), Graph(EdgeI.Graph) { }
781 int GetId()
const {
return EdgeHI.GetDat().GetId(); }
783 int GetSrcNId()
const {
return EdgeHI.GetDat().GetSrcNId(); }
785 int GetDstNId()
const {
return EdgeHI.GetDat().GetDstNId(); }
802 explicit TNEGraph(
const int& Nodes,
const int& Edges) : CRef(), MxNId(0), MxEId(0) {
Reserve(Nodes, Edges); }
803 TNEGraph(
const TNEGraph& Graph) : MxNId(Graph.MxNId), MxEId(Graph.MxEId), NodeH(Graph.NodeH), EdgeH(Graph.EdgeH) { }
805 TNEGraph(
TSIn& SIn) : MxNId(SIn), MxEId(SIn), NodeH(SIn), EdgeH(SIn) { }
856 int AddEdge(
const int& SrcNId,
const int& DstNId,
int EId = -1);
866 void DelEdge(
const int& SrcNId,
const int& DstNId,
const bool& IsDir =
true);
870 bool IsEdge(
const int& SrcNId,
const int& DstNId,
const bool& IsDir =
true)
const {
int EId;
return IsEdge(SrcNId, DstNId, EId, IsDir); }
872 bool IsEdge(
const int& SrcNId,
const int& DstNId,
int& EId,
const bool& IsDir =
true)
const;
874 int GetEId(
const int& SrcNId,
const int& DstNId)
const {
int EId;
return IsEdge(SrcNId, DstNId, EId)?EId:-1; }
900 void Clr() { MxNId=0; MxEId=0; NodeH.
Clr(); EdgeH.
Clr(); }
902 void Reserve(
const int& Nodes,
const int& Edges) {
903 if (Nodes>0) { NodeH.
Gen(Nodes/2); }
if (Edges>0) { EdgeH.
Gen(Edges/2); } }
910 void Defrag(
const bool& OnlyNodeLinks=
false);
915 bool IsOk(
const bool& ThrowExcept=
true)
const;
917 void Dump(FILE *OutF=stdout)
const;
950 TNode(
const TNode& Node) : Id(Node.Id), NIdV(Node.NIdV), NodeTy(Node.NodeTy) { }
959 int GetNbrNId(
const int& NodeN)
const {
return NIdV[NodeN]; }
973 inline THashIter
HI()
const {
return ! LeftHI.IsEnd()?LeftHI:
RightHI; }
976 TNodeI(
const THashIter& LeftHIter,
const THashIter& RightHIter) : LeftHI(LeftHIter), RightHI(RightHIter) { }
977 TNodeI(
const TNodeI& NodeI) : LeftHI(NodeI.LeftHI), RightHI(NodeI.RightHI) { }
981 if (! LeftHI.IsEnd()) {
983 else if (! RightHI.IsEnd()) {
989 int GetId()
const {
return HI().GetDat().GetId(); }
991 bool IsLeft()
const {
return ! LeftHI.IsEnd(); }
995 int GetDeg()
const {
return HI().GetDat().GetDeg(); }
1002 int GetInNId(
const int& NodeN)
const {
return HI().GetDat().GetInNId(NodeN); }
1005 int GetOutNId(
const int& NodeN)
const {
return HI().GetDat().GetOutNId(NodeN); }
1008 int GetNbrNId(
const int& NodeN)
const {
return HI().GetDat().GetNbrNId(NodeN); }
1010 bool IsInNId(
const int& NId)
const {
return HI().GetDat().IsInNId(NId); }
1012 bool IsOutNId(
const int& NId)
const {
return HI().GetDat().IsOutNId(NId); }
1014 bool IsNbrNId(
const int& NId)
const {
return HI().GetDat().IsNbrNId(NId); }
1023 TEdgeI() : CurNode(), EndNode(), CurEdge(0) { }
1024 TEdgeI(
const TNodeI& NodeI,
const TNodeI& EndNodeI,
const int& EdgeN=0) : CurNode(NodeI), EndNode(EndNodeI), CurEdge(EdgeN) { }
1025 TEdgeI(
const TEdgeI& EdgeI) : CurNode(EdgeI.CurNode), EndNode(EdgeI.EndNode), CurEdge(EdgeI.CurEdge) { }
1029 while (CurNode < EndNode && CurNode.
GetOutDeg()==0) { CurNode++; } }
return *
this; }
1055 explicit TBPGraph(
const int& Nodes,
const int& Edges) : MxNId(0) { }
1056 TBPGraph(
const TBPGraph& BPGraph) : MxNId(BPGraph.MxNId), LeftH(BPGraph.LeftH), RightH(BPGraph.RightH) { }
1071 if (
this!=&BPGraph) { MxNId=BPGraph.
MxNId; LeftH=BPGraph.
LeftH; RightH=BPGraph.
RightH; }
return *
this; }
1081 int AddNode(
int NId = -1,
const bool& LeftNode=
true);
1117 int AddEdge(
const int& LeftNId,
const int& RightNId);
1122 void DelEdge(
const int& LeftNId,
const int& RightNId);
1124 bool IsEdge(
const int& LeftNId,
const int& RightNId)
const;
1130 TEdgeI
GetEI(
const int& EId)
const;
1133 TEdgeI
GetEI(
const int& LeftNId,
const int& RightNId)
const;
1155 void Reserve(
const int& Nodes,
const int& Edges);
1158 void Defrag(
const bool& OnlyNodeLinks=
false);
1161 bool IsOk(
const bool& ThrowExcept=
true)
const;
1163 void Dump(FILE *OutF=stdout)
const;
bool HasFlag(const TGraphFlag &Flag) const
Allows for run-time checking the type of the graph (see the TGraphFlag for flags).
static PBPGraph GetSmallGraph()
Returns a small graph on 2 'left', 3 'right' nodes and 4 edges.
int AddEdge(const TEdgeI &EdgeI)
Adds an edge between EdgeI.GetLNId() and EdgeI.GetRNId() to the graph.
Edge iterator. Only forward iteration (operator++) is supported.
void LoadGraphShM(TShMIn &ShMIn)
int GetNbrNId(const int &NodeN) const
Returns ID of NodeN-th neighboring node.
bool operator<(const TNodeI &NodeI) const
Main namespace for all the Snap global entities.
TBPGraph(const TBPGraph &BPGraph)
!! Reserve(Nodes, Edges); }
static PNGraph LoadShM(TShMIn &ShMIn)
Static constructor that loads the graph from a shared memory stream and returns pointer to it...
int GetId() const
Gets edge ID. Always returns -1 since only edges in multigraphs have explicit IDs.
TUNGraph(const TUNGraph &Graph)
int AddNode(const TNodeI &NodeId)
Adds a node of ID NodeI.GetId() to the graph.
void Reserve(const int &Nodes, const int &Edges)
Reserves memory for a biparite graph of Nodes nodes and Edges edges.
void GetNIdV(TIntV &NIdV) const
Gets a vector IDs of all nodes in the graph.
static PUNGraph New(const int &Nodes, const int &Edges)
Static constructor that returns a pointer to the graph and reserves enough memory for Nodes nodes and...
bool IsInNId(const int &NId) const
Tests whether node with ID NId points to the current node.
void DelNode(const int &NId)
Deletes node of ID NId from the graph.
int AddEdge(const int &SrcNId, const int &DstNId, int EId=-1)
Adds an edge with ID EId between node IDs SrcNId and DstNId to the graph.
TNodeI BegNI() const
Returns an iterator referring to the first node in the graph.
bool IsOk(const bool &ThrowExcept=true) const
Checks the graph data structure for internal consistency.
TEdgeI EndEI() const
Returns an iterator referring to the past-the-end edge in the graph.
void GetRNIdV(TIntV &NIdV) const
Gets a vector IDs of all 'right' nodes in the bipartite graph.
bool IsOutNId(const int &NId) const
bool operator==(const TEdgeI &EdgeI) const
TNodeI & operator--(int)
Decrement iterator.
TEdgeI & operator++(int)
Increment iterator.
TNodeI & operator=(const TNodeI &NodeI)
static PBPGraph New(const int &Nodes, const int &Edges)
Static constructor that returns a pointer to the graph and reserves enough memory for Nodes nodes and...
bool Empty() const
Tests whether the graph is empty (has zero nodes).
bool operator==(const TNodeI &NodeI) const
TNodeI GetNI(const int &NId) const
Returns an iterator referring to the node of ID NId in the graph.
int GetInDeg() const
Returns in-degree of the current node (returns same as value GetDeg() since the graph is undirected)...
static PUNGraph GetSmallGraph()
Returns a small graph on 5 nodes and 5 edges.
TNEGraph & operator=(const TNEGraph &Graph)
THash< TInt, TNode >::TIter THashIter
TNode & GetNode(const int &NId)
bool operator==(const TEdgeI &EdgeI) const
bool IsNbrNId(const int &NId) const
Tests whether node with ID NId is a neighbor of the current node.
int GetNbrEId(const int &EdgeN) const
void LoadShM(TShMIn &ShMIn)
TEdge(const int &EId, const int &SourceNId, const int &DestNId)
int GetRndNId(TRnd &Rnd=TInt::Rnd)
Returns an ID of a random node in the graph.
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
void Dump(FILE *OutF=stdout) const
Print the graph in a human readable form to an output stream OutF.
static PNGraph New()
Static constructor that returns a pointer to the graph. Call: PNGraph Graph = TNGraph::New().
TNodeI GetNI(const int &NId) const
Returns an iterator referring to the node of ID NId in the graph.
void Save(TSOut &SOut) const
int AddEdge(const int &SrcNId, const int &DstNId, const int &EId)
Adds an edge between node IDs SrcNId and DstNId to the graph, ignores EId (for compatibility with TNE...
void ReserveNIdInDeg(const int &NId, const int &InDeg)
Reserves memory for node ID NId having InDeg in-edges.
TEdgeI BegEI() const
Returns an iterator referring to the first edge in the graph.
TNEGraph(const int &Nodes, const int &Edges)
Constructor that reserves enough memory for a graph of Nodes nodes and Edges edges.
int AddNode(const TNodeI &NodeI)
Adds a node of ID NodeI.GetId() to the graph.
void GetNIdV(TIntV &NIdV) const
Gets a vector IDs of all nodes in the graph.
TEdgeI EndEI() const
Returns an iterator referring to the past-the-end edge in the graph.
int GetOutDeg() const
Returns out-degree of the current node.
int GetDstNId() const
Returns the destination of the edge. Since the graph is undirected, this is the node with a greater I...
int GetMxNId() const
Returns an ID that is larger than any node ID in the graph.
bool IsInNId(const int &NId) const
Tests whether node with ID NId points to the current node.
bool IsLNode(const int &NId) const
Tests whether ID NId is a 'left' side node.
TNEGraph(TSIn &SIn)
Constructor for loading the graph from a (binary) stream SIn.
TUNGraph(TSIn &SIn)
Constructor that loads the graph from a (binary) stream SIn.
TEdgeI & operator=(const TEdgeI &EdgeI)
Tests (at compile time) if the graph is directed.
void LoadShM(TShMIn &ShMIn)
int GetMxNId() const
Returns an ID that is larger than any node ID in the graph.
int GetNbrNId(const int &NodeN) const
int GetEdges() const
Returns the number of edges in the graph.
Node iterator. Only forward iteration (operator++) is supported.
int AddNode(int NId=-1)
Adds a node of ID NId to the graph.
int GetDstNId() const
Gets destination ('right' side) of an edge. Since the graph is undirected this is the node with great...
THash< TInt, TNode > NodeH
int GetEdges() const
Returns the number of edges in the graph.
int AddEdge(const TEdgeI &EdgeI)
Adds an edge from EdgeI.GetSrcNId() to EdgeI.GetDstNId() to the graph.
TSizeTy Len() const
Returns the number of elements in the vector.
bool IsInEId(const int &EId) const
TNodeI & operator=(const TNodeI &NodeI)
bool operator<(const TEdgeI &EdgeI) const
Node iterator. Only forward iteration (operator++) is supported.
int GetId() const
Gets edge ID.
TNodeI EndNI() const
Returns an iterator referring to the past-the-end node in the graph.
bool operator==(const TEdgeI &EdgeI) const
int AddEdgeUnchecked(const int &SrcNId, const int &DstNId)
Adds an edge from node SrcNId to node DstNId to the graph.
void Save(TSOut &SOut) const
TNodeI BegNI() const
Returns an iterator referring to the first node in the graph.
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.
TNodeI & operator--(int)
Decrement iterator.
TEdgeI BegEI() const
Returns an iterator referring to the first edge in the graph.
TEdgeI & operator++(int)
Increment iterator.
void Save(TSOut &SOut) const
bool IsOk(const bool &ThrowExcept=true) const
Checks the graph data structure for internal consistency.
int GetOutEId(const int &EdgeN) const
int AddNode(int NId=-1, const bool &LeftNode=true)
Adds a node of ID NId to the graph.
void LoadGraphShM(TShMIn &ShMIn)
TEdgeI EndEI() const
Returns an iterator referring to the past-the-end edge in the graph.
int GetNodes() const
Returns the number of nodes in the graph.
TEdgeI EndEI() const
Returns an iterator referring to the past-the-end edge in the graph.
int AddNode(int NId=-1)
Adds a node of ID NId to the graph.
void Dump(FILE *OutF=stdout) const
Print the graph in a human readable form to an output stream OutF.
static PNEGraph Load(TSIn &SIn)
Static constructor that loads the graph from a stream SIn and returns a pointer to it...
Edge iterator. Only forward iteration (operator++) is supported.
const TDat & GetDat(const TKey &Key) const
void Save(TSOut &SOut) const
Saves the graph to a (binary) stream SOut.
int GetSrcNId() const
Returns the source of the edge. Since the graph is undirected, this is the node with a smaller ID of ...
bool IsEdge(const int &EId) const
Tests whether an edge EId exists in the graph (for compatibility with TNEANet), always returns false...
TNodeI & operator--(int)
Decrement iterator.
void Save(TSOut &SOut) const
Saves the graph to a (binary) stream SOut.
bool IsNbrNId(const int &NId) const
Tests whether node with ID NId is a neighbor of the current node.
const TNode & GetNode(const int &NId) const
void SortNodeAdjV()
Sorts the adjacency lists of each node.
bool IsInNId(const int &NId) const
int GetRndLNId(TRnd &Rnd=TInt::Rnd)
Returns an ID of a random 'left' node in the graph.
TNodeI & operator++(int)
Increment iterator.
TBPGraph(const int &Nodes, const int &Edges)
Constructor that reserves enough memory for a graph of Nodes (LeftNodes+RightNodes) nodes and Edges e...
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.
int GetId() const
Returns edge ID. Always returns -1 since only edges in multigraphs have explicit IDs.
void DelNode(const TNode &NodeI)
Deletes node of ID NodeI.GetId() from the graph.
void LoadShM(TShMIn &ShMIn)
Load THash from shared memory file. Copying/Deleting Keys is illegal.
int GetNodes() const
Returns the number of nodes in the graph.
bool IsInNId(const int &NId) const
Tests whether node with ID NId points to the current node.
TNodeI(const THashIter &NodeHIter, const TNEGraph *GraphPt)
THash< TInt, TNode > NodeH
int GetInNId(const int &EdgeN) const
Returns ID of EdgeN-th in-node (the node pointing to the current node).
TNGraph(TSIn &SIn)
Constructor that loads the graph from a (binary) stream SIn.
int GetInNId(const int &NodeN) const
TNode & GetNode(const int &NId)
int AddEdge(const TEdgeI &EdgeI)
Adds an edge between EdgeI.GetSrcNId() and EdgeI.GetDstNId() to the graph.
void Save(TSOut &SOut) const
int GetRndNId(TRnd &Rnd=TInt::Rnd)
Returns an ID of a random node in the graph.
TEdgeI & operator++(int)
Increment iterator.
int GetId() const
Returns ID of the current node.
int GetOutNId(const int &NodeN) const
int GetDstNId() const
Gets destination of an edge.
THash< TInt, TEdge > EdgeH
int GetLNodes() const
Returns the number of nodes on the 'left' side of the biparite graph.
TEdgeI(const TEdgeI &EdgeI)
bool operator<(const TEdgeI &EdgeI) const
TEdgeI(const TNodeI &NodeI, const TNodeI &EndNodeI, const int &EdgeN=0)
static PBPGraph Load(TSIn &SIn)
Static constructor that loads the graph from a stream SIn and returns a pointer to it...
void DelNode(const int &NId)
Deletes node of ID NId from the graph.
int GetOutEId(const int &EdgeN) const
Returns ID of EdgeN-th out-edge.
void SortNodeAdjV()
Sorts the adjacency lists of each node.
int GetNbrNId(const int &NodeN) const
Returns ID of NodeN-th neighboring node.
int GetDeg() const
Returns degree of the current node.
void Clr()
Deletes all nodes and edges from the bipartite graph.
TNodeI EndNI() const
Returns an iterator referring to the past-the-end node in the graph.
TEdgeI GetEI(const int &EId) const
Not supported/implemented!
int GetInEId(const int &EdgeN) const
TNodeI GetNI(const int &NId) const
Returns an iterator referring to the node of ID NId in the graph.
int GetOutDeg() const
Returns out-degree of the current node (returns same as value GetDeg() since the graph is undirected)...
int GetNbrNId(const int &EdgeN) const
Returns ID of EdgeN-th neighboring node.
void GetNIdV(TIntV &NIdV) const
Gets a vector IDs of all nodes in the graph.
TEdgeI GetEI(const int &SrcNId, const int &DstNId) const
Returns an iterator referring to edge (SrcNId, DstNId) in the graph.
int GetNodes() const
Returns the number of nodes in the graph.
static PUNGraph LoadShM(TShMIn &ShMIn)
Static constructor that loads the graph from shared memory.
TNodeI & operator++(int)
Increment iterator.
void SortNIdV()
Sorts the adjacency lists of the current node.
int GetOutDeg() const
Returns out-degree of the current node (returns same as value GetDeg() since the graph is undirected)...
bool Empty() const
Tests whether the bipartite graph is empty (has zero nodes).
TPt< TNEGraph > PNEGraph
Pointer to a directed multigraph (TNEGraph)
TEdge & GetEdge(const int &EId)
int GetLNId() const
Gets the ID of the node on the 'left' side of the edge.
THash< TInt, TNode >::TIter THashIter
bool IsOutNId(const int &NId) const
Tests whether the current node points to node with ID NId.
TNodeI EndRNI() const
Returns an iterator referring to the past-the-end 'right' node in the graph.
TNodeI & operator++(int)
Increment iterator.
void Sort(const bool &Asc=true)
Sorts the elements of the vector.
bool IsOutNId(const int &NId) const
void Gen(const int &ExpectVals)
Edge iterator. Only forward iteration (operator++) is supported.
int GetEdges() const
Returns the number of edges in the graph.
TNodeI(const THashIter &LeftHIter, const THashIter &RightHIter)
int AddEdge(const int &SrcNId, const int &DstNId)
Adds an edge from node SrcNId to node DstNId to the graph.
static PNEGraph GetSmallGraph()
Returns a small multigraph on 5 nodes and 6 edges.
int GetNodes() const
Returns the total number of nodes in the graph.
bool IsInNId(const int &NId) const
static PNGraph Load(TSIn &SIn)
Static constructor that loads the graph from a stream SIn and returns a pointer to it...
TEdgeI(const THashIter &EdgeHIter, const TNEGraph *GraphPt)
void DelNode(const TNode &NodeI)
Deletes node of ID NodeI.GetId() from the graph.
void DelEdge(const int &SrcNId, const int &DstNId, const bool &IsDir=true)
Deletes an edge from node IDs SrcNId to DstNId from the 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 graph.
void Reserve(const int &Nodes, const int &Edges)
Reserves memory for a graph of Nodes nodes and Edges edges.
TNGraph(const int &Nodes, const int &Edges)
Constructor that reserves enough memory for a graph of Nodes nodes and Edges edges.
bool Empty() const
Tests whether the graph is empty (has zero nodes).
int GetRndNId(TRnd &Rnd=TInt::Rnd)
Returns an ID of a random node in the graph.
TNodeI BegLNI() const
Returns an iterator referring to the first 'left' node in the graph.
int GetInEId(const int &EdgeN) const
Returns ID of EdgeN-th in-edge.
bool IsOutNId(const int &NId) const
Tests whether the current node points to node with ID NId.
int GetRNodes() const
Returns the number of nodes on the 'right' side of the biparite graph.
TNodeI GetNI(const int &NId) const
Returns an iterator referring to the node of ID NId in the graph.
bool HasFlag(const TGraphFlag &Flag) const
Allows for run-time checking the type of the graph (see the TGraphFlag for flags).
THash< TInt, TNode >::TIter THashIter
Tests (at compile time) if the graph is a multigraph with multiple edges between the same nodes...
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
TNodeI(const TNodeI &NodeI)
int GetOutNId(const int &EdgeN) const
Returns ID of EdgeN-th out-node (the node the current node points to).
void operator()(TNode *Node, TShMIn &ShMIn)
bool IsEdge(const int &LeftNId, const int &RightNId) const
Tests whether an edge between node IDs LeftNId and RightNId exists in the graph.
bool operator<(const TEdgeI &EdgeI) const
int AddEdge(const TEdgeI &EdgeI)
Adds an edge between EdgeI.GetSrcNId() and EdgeI.GetDstNId() to the graph.
TEdgeI BegEI() const
Returns an iterator referring to the first edge in the graph.
void GetLNIdV(TIntV &NIdV) const
Gets a vector IDs of all 'left' nodes in the bipartite graph.
static PUNGraph New()
Static constructor that returns a pointer to the graph. Call: PUNGraph Graph = TUNGraph::New().
TEdgeI(const TNodeI &NodeI, const TNodeI &EndNodeI, const int &EdgeN=0)
int AddEdge(const int &SrcNId, const int &DstNId, const int &EId)
Adds an edge between node IDs SrcNId and DstNId to the graph, ignores EId (for compatibility with TNE...
TPt< TNGraph > PNGraph
Pointer to a directed graph (TNGraph)
bool operator<(const TNodeI &NodeI) const
int GetOutNId(const int &NodeN) const
TBPGraph & operator=(const TBPGraph &BPGraph)
int AddNode(int NId=-1)
Adds a node of ID NId to the graph.
int AddNode(const TNodeI &NodeId)
Adds a node of ID NodeI.GetId() to the graph.
void DelEdge(const int &SrcNId, const int &DstNId)
Deletes an edge between node IDs SrcNId and DstNId from the graph.
TNodeI BegRNI() const
Returns an iterator referring to the first 'right' node in the graph.
int GetOutNId(const int &NodeN) const
int AddNodeUnchecked(int NId=-1)
Adds a node of ID NId to the network, noop if the node already exists.
void Dump(FILE *OutF=stdout) const
Print the graph in a human readable form to an output stream OutF.
TNodeI GetRndNI(TRnd &Rnd=TInt::Rnd)
Returns an interator referring to a random node in the graph.
void Save(TSOut &SOut) const
void Save(TSOut &SOut) const
TNodeI EndLNI() const
Returns an iterator referring to the past-the-end 'left' node in the graph.
int GetRNId() const
Gets the ID of the node on the 'right' side of the edge.
TNodeI GetRndNI(TRnd &Rnd=TInt::Rnd)
Returns an interator referring to a random node in the graph.
TNodeI & operator=(const TNodeI &NodeI)
bool operator==(const TNodeI &NodeI) const
int GetDeg() const
Returns degree of the current node, the sum of in-degree and out-degree.
bool operator==(const TNodeI &NodeI) const
TNGraph(const TNGraph &Graph)
THash< TInt, TNode >::TIter THashIter
bool IsNbrNId(const int &NId) const
Tests whether node with ID NId is a neighbor of the current node.
void operator()(TNode *Node, TShMIn &ShMIn)
TSizeTy SearchBin(const TVal &Val) const
Returns the position of an element with value Val.
void Defrag(const bool &OnlyNodeLinks=false)
Defragments the graph.
int AddEdge(const int &SrcNId, const int &DstNId)
Adds an edge between node IDs SrcNId and DstNId to the graph.
bool operator<(const TNodeI &NodeI) const
int GetDeg() const
Returns degree of the current node.
void Clr()
Deletes all nodes and edges from the graph.
int GetMxNId() const
Returns an ID that is larger than any node ID in the graph.
bool IsNbrNId(const int &NId) const
TNEGraph(const TNEGraph &Graph)
TNode & GetNode(const int &NId)
static PUNGraph Load(TSIn &SIn)
Static constructor that loads the graph from a stream SIn and returns a pointer to it...
static PNEGraph New()
Static constructor that returns a pointer to the graph. Call: PNEGraph Graph = TNEGraph::New().
void Save(TSOut &SOut) const
Saves the graph to a (binary) stream SOut.
void Save(TSOut &SOut) const
int AddEdge(const int &LeftNId, const int &RightNId)
Adds an edge between a node LeftNId on the left and a node RightNId on the right side of the bipartit...
bool IsEdge(const int &EId) const
Tests whether an edge EId exists in the graph (for compatibility with TNEANet), always returns false...
void DelEdge(const int &LeftNId, const int &RightNId)
Deletes an edge between a node LeftNId on the left and a node RightNId on the right side of the bipar...
int GetSrcNId() const
Gets the source ('left' side) of an edge. Since the graph is undirected this is the node with smaller...
bool IsNbrNId(const int &NId) const
void LoadShM(TShMIn &ShMIn)
Constructs the vector from a shared memory input.
int GetNbrNId(const int &NodeN) const
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 graph.
TEdgeI & operator=(const TEdgeI &EdgeI)
bool IsEdge(const int &EId) const
Tests whether an edge with edge ID EId exists in the graph.
TNodeI EndNI() const
Returns an iterator referring to the past-the-end node in the graph.
int GetId() const
Returns ID of the current node.
static PNGraph GetSmallGraph()
Returns a small graph on 5 nodes and 6 edges.
int GetOutNId(const int &NodeN) const
Returns ID of NodeN-th out-node (the node the current node points to).
int GetRndRNId(TRnd &Rnd=TInt::Rnd)
Returns an ID of a random 'right' node in the graph.
const TNode & GetNode(const int &NId) const
int GetId() const
Returns edge ID. Always returns -1 since only edges in multigraphs have explicit IDs.
void Reserve(const int &Nodes, const int &Edges)
Reserves memory for a graph of Nodes nodes and Edges edges.
int GetOutDeg() const
Returns out-degree of the current node.
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.
int GetSrcNId() const
Gets the source of an edge.
int AddEdge2(const int &SrcNId, const int &DstNId)
Adds an edge between node IDs SrcNId and DstNId to the graph. If nodes do not exists, create them.
TNodeI & operator=(const TNodeI &NodeI)
THash< TInt, TNode > NodeH
bool IsOutEId(const int &EId) const
static PNGraph New(const int &Nodes, const int &Edges)
Static constructor that returns a pointer to the graph and reserves enough memory for Nodes nodes and...
void GetEIdV(TIntV &EIdV) const
Gets a vector IDs of all edges in the graph.
void Pack()
Reduces vector capacity (frees memory) to match its size.
int GetRndEId(TRnd &Rnd=TInt::Rnd)
Returns an ID of a random edge in the graph.
enum TGraphFlag_ TGraphFlag
Graph Flags, used for quick testing of graph types.
bool IsRNode(const int &NId) const
Tests whether ID NId is a 'right' side node.
bool IsRight() const
Tests whether the node is right hand side node.
THash< TInt, TNode > RightH
TNodeI(const THashIter &NodeHIter)
static PNEGraph 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 GetNbrEId(const int &EdgeN) const
Returns ID of EdgeN-th in or out-edge.
int GetEdges() const
Returns the number of edges in the graph.
int GetInDeg() const
Returns in-degree of the current node (returns same as value GetDeg() since the graph is undirected)...
Node iterator. Only forward iteration (operator++) is supported.
void Defrag(const bool &OnlyNodeLinks=false)
Defragments the graph.
const TEdge & GetEdge(const int &EId) const
TNodeI EndNI() const
Returns an iterator referring to the past-the-end node in the graph.
bool IsOutNId(const int &NId) const
Tests whether the current node points to node with ID NId.
int GetRndNId(TRnd &Rnd=TInt::Rnd)
Returns an ID of a random node in the graph.
void Reserve(const int &Nodes, const int &Edges)
Reserves memory for a graph of Nodes nodes and Edges edges.
static PBPGraph New()
Static constructor that returns a pointer to the graph. Call: PBPGraph BPGraph = TBPGraph::New();.
int GetNbrNId(const int &NodeN) const
Returns ID of NodeN-th neighboring node.
void Clr(const bool &DoDel=true, const int &NoDelLim=-1, const bool &ResetDat=true)
THash< TInt, TNode > LeftH
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
int GetOutNId(const int &NodeN) const
Returns ID of NodeN-th out-node (the node the current node points to).
TPt< TBPGraph > PBPGraph
Pointer to a bipartitegraph graph (TBPGraph)
bool HasFlag(const TGraphFlag &Flag) const
Allows for run-time checking the type of the graph (see the TGraphFlag for flags).
TNodeI GetRndNI(TRnd &Rnd=TInt::Rnd)
Returns an interator referring to a random node in the graph.
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 operator==(const TNodeI &NodeI) const
void Clr()
Deletes all nodes and edges from the graph.
void GetNIdV(TIntV &NIdV) const
Gets a vector IDs of all nodes in the bipartite graph.
void Clr()
Deletes all nodes and edges from the graph.
TNodeI & operator++(int)
Increment iterator.
bool IsOk(const bool &ThrowExcept=true) const
Checks the graph data structure for internal consistency.
void Reserve(const TSizeTy &_MxVals)
Reserves enough memory for the vector to store _MxVals elements.
TEdgeI GetRndEI(TRnd &Rnd=TInt::Rnd)
Returns an interator referring to a random edge in the graph.
const TNode & GetNode(const int &NId) const
int AddNodeUnchecked(int NId=-1)
Adds a node of ID NId to the network, noop if the node already exists.
bool HasFlag(const TGraphFlag &Flag) const
Allows for run-time checking the type of the graph (see the TGraphFlag for flags).
void SortNIdV()
Sorts the adjacency lists of the current node.
void Defrag(const bool &OnlyNodeLinks=false)
Defragments the graph.
TEdgeI BegEI() const
Returns an iterator referring to the first edge in the graph.
int GetInDeg() const
Returns in-degree of the current node.
void DelNode(const TNode &NodeI)
Deletes node of ID NodeI.GetId() from the graph.
void Dump(FILE *OutF=stdout) const
Print the biparite graph in a human readable form to an output stream OutF.
void DelNode(const TNode &NodeI)
Deletes node of ID NodeI.GetId() from the graph.
int GetSrcNId() const
Returns the source node of the edge.
int GetId() const
Returns ID of the current node.
void Defrag(const bool &OnlyNodeLinks=false)
Defragments the biparite graph.
int GetId() const
Returns ID of the current node.
bool IsEdge(const int &SrcNId, const int &DstNId) const
Tests whether an edge between node IDs SrcNId and DstNId exists in the graph.
TEdgeI(const TEdgeI &EdgeI)
bool IsKey(const TKey &Key) const
int GetInNId(const int &NodeN) const
Returns ID of NodeN-th in-node (the node pointing to the current node).
bool IsOutNId(const int &NId) const
Tests whether the current node points to node with ID NId.
void DelEdge(const int &EId)
Deletes an edge with edge ID EId from the graph.
TEdgeI GetEI(const int &EId) const
Not supported/implemented!
int GetInNId(const int &NodeN) const
bool IsOutEId(const int &EId) const
Tests whether the edge with ID EId is an out-edge of current node.
TNodeI BegNI() const
Returns an iterator referring to the first node in the graph.
int GetInNId(const int &NodeN) const
bool operator<(const TEdgeI &EdgeI) const
void ReserveNIdDeg(const int &NId, const int &Deg)
Reserves memory for node ID NId having Deg edges.
bool IsOutNId(const int &NId) const
int GetNbrNId(const int &NodeN) const
TNodeI(const TNodeI &NodeI)
int AddNode(const TNodeI &NodeI)
Adds a node of ID NodeI.GetId() to the graph.
TNodeI(const THashIter &NodeHIter)
TNodeI(const TNodeI &NodeI)
bool IsInEId(const int &EId) const
Tests whether the edge with ID EId is an in-edge of current node.
bool IsNbrNId(const int &NId) const
bool operator==(const TEdgeI &EdgeI) const
TNodeI GetRndNI(TRnd &Rnd=TInt::Rnd)
Returns an interator referring to a random node in the graph.
bool IsOk(const bool &ThrowExcept=true) const
Checks the bipartite graph data structure for internal consistency.
void DelNode(const int &NId)
Deletes node of ID NId from the graph.
Tests (at compile time) if the graph is a bipartite graph type.
TEdgeI & operator=(const TEdgeI &EdgeI)
TEdgeI(const TEdgeI &EdgeI)
Edge iterator. Only forward iteration (operator++) is supported.
void Save(TSOut &SOut) const
TNGraph & operator=(const TNGraph &Graph)
Node iterator. Only forward iteration (operator++) is supported.
int AddEdge2(const int &SrcNId, const int &DstNId)
Adds an edge from node IDs SrcNId to node DstNId to the graph. If nodes do not exist, create them.
int GetDstNId() const
Returns the destination node of the edge.
bool IsInNId(const int &NId) const
bool operator<(const TNodeI &NodeI) const
TUNGraph & operator=(const TUNGraph &Graph)
int GetOutNId(const int &NodeN) const
Returns ID of NodeN-th out-node (the node the current node points to).
int GetDeg() const
Returns degree of the current node, the sum of in-degree and out-degree.
bool Empty() const
Tests whether the graph is empty (has zero nodes).
TEdgeI & operator++(int)
Increment iterator.
THash< TInt, TEdge >::TIter THashIter
const TKey & GetKey(const int &KeyId) const
int GetInDeg() const
Returns in-degree of the current node.
TEdgeI GetEI(const int &EId) const
Not supported/implemented!
TEdgeI(const TNodeI &NodeI, const TNodeI &EndNodeI, const int &EdgeN=0)
bool IsLeft() const
Tests whether the node is left hand side node.
TUNGraph(const int &Nodes, const int &Edges)
Constructor that reserves enough memory for a graph of Nodes nodes and Edges edges.
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
TEdgeI(const TEdgeI &EdgeI)
TEdgeI & operator=(const TEdgeI &EdgeI)
int GetInNId(const int &NodeN) const
Returns ID of NodeN-th in-node (the node pointing to the current node).
void Save(TSOut &SOut) const
Saves the graph to a (binary) stream SOut.
TBPGraph(TSIn &SIn)
Constructor for loading the graph from a (binary) stream SIn.
TNodeI(const TNodeI &NodeI)
void ReserveNIdOutDeg(const int &NId, const int &OutDeg)
Reserves memory for node ID NId having OutDeg out-edges.
int AddEdgeUnchecked(const int &SrcNId, const int &DstNId)
Adds an edge between node IDs SrcNId and DstNId to the graph.
bool IsNbrNId(const int &NId) const
Tests whether node with ID NId is a neighbor of the current node.
TPt< TUNGraph > PUNGraph
Pointer to an undirected graph (TUNGraph)
int GetMxNId() const
Returns an ID that is larger than any node ID in the graph.
TIter GetI(const TKey &Key) const
int GetInNId(const int &NodeN) const
Returns ID of NodeN-th in-node (the node pointing to the current node).
bool IsInNId(const int &NId) const
Tests whether node with ID NId points to the current node.