94 int GetInNId(
const int& NodeN)
const {
return NodeHI.GetDat().GetInNId(NodeN); }
99 int GetOutNId(
const int& NodeN)
const {
return NodeHI.GetDat().GetOutNId(NodeN); }
219 int AddEdge(
const int& SrcNId,
const int& DstNId);
226 void DelEdge(
const int& SrcNId,
const int& DstNId);
228 bool IsEdge(
const int& SrcNId,
const int& DstNId)
const;
234 TEdgeI
GetEI(
const int& EId)
const;
238 TEdgeI
GetEI(
const int& SrcNId,
const int& DstNId)
const;
260 void Defrag(
const bool& OnlyNodeLinks=
false);
264 bool IsOk(
const bool& ThrowExcept=
true)
const;
266 void Dump(FILE *OutF=stdout)
const;
482 int AddEdge(
const int& SrcNId,
const int& DstNId);
490 void DelEdge(
const int& SrcNId,
const int& DstNId,
const bool& IsDir =
true);
492 bool IsEdge(
const int& SrcNId,
const int& DstNId,
const bool& IsDir =
true)
const;
498 TEdgeI
GetEI(
const int& EId)
const;
500 TEdgeI
GetEI(
const int& SrcNId,
const int& DstNId)
const;
514 void Reserve(
const int& Nodes,
const int& Edges) {
if (Nodes>0) {
NodeH.
Gen(Nodes/2); } }
525 void Defrag(
const bool& OnlyNodeLinks=
false);
530 bool IsOk(
const bool& ThrowExcept=
true)
const;
532 void Dump(FILE *OutF=stdout)
const;
594 TEdge(
const int& EId,
const int& SourceNId,
const int& DestNId) :
Id(EId),
SrcNId(SourceNId),
DstNId(DestNId) { }
643 bool IsInNId(
const int& NId)
const;
645 bool IsOutNId(
const int& NId)
const;
754 int AddEdge(
const int& SrcNId,
const int& DstNId,
int EId = -1);
764 void DelEdge(
const int& SrcNId,
const int& DstNId,
const bool& IsDir =
true);
768 bool IsEdge(
const int& SrcNId,
const int& DstNId,
const bool& IsDir =
true)
const {
int EId;
return IsEdge(SrcNId, DstNId, EId, IsDir); }
770 bool IsEdge(
const int& SrcNId,
const int& DstNId,
int& EId,
const bool& IsDir =
true)
const;
772 int GetEId(
const int& SrcNId,
const int& DstNId)
const {
int EId;
return IsEdge(SrcNId, DstNId, EId)?EId:-1; }
800 void Reserve(
const int& Nodes,
const int& Edges) {
808 void Defrag(
const bool& OnlyNodeLinks=
false);
813 bool IsOk(
const bool& ThrowExcept=
true)
const;
815 void Dump(FILE *OutF=stdout)
const;
887 int GetId()
const {
return HI().GetDat().GetId(); }
893 int GetDeg()
const {
return HI().GetDat().GetDeg(); }
900 int GetInNId(
const int& NodeN)
const {
return HI().GetDat().GetInNId(NodeN); }
903 int GetOutNId(
const int& NodeN)
const {
return HI().GetDat().GetOutNId(NodeN); }
906 int GetNbrNId(
const int& NodeN)
const {
return HI().GetDat().GetNbrNId(NodeN); }
908 bool IsInNId(
const int& NId)
const {
return HI().GetDat().IsInNId(NId); }
910 bool IsOutNId(
const int& NId)
const {
return HI().GetDat().IsOutNId(NId); }
912 bool IsNbrNId(
const int& NId)
const {
return HI().GetDat().IsNbrNId(NId); }
979 int AddNode(
int NId = -1,
const bool& LeftNode=
true);
1015 int AddEdge(
const int& LeftNId,
const int& RightNId);
1020 void DelEdge(
const int& LeftNId,
const int& RightNId);
1022 bool IsEdge(
const int& LeftNId,
const int& RightNId)
const;
1028 TEdgeI
GetEI(
const int& EId)
const;
1031 TEdgeI
GetEI(
const int& LeftNId,
const int& RightNId)
const;
1053 void Reserve(
const int& Nodes,
const int& Edges);
1056 void Defrag(
const bool& OnlyNodeLinks=
false);
1059 bool IsOk(
const bool& ThrowExcept=
true)
const;
1061 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.
int GetNbrNId(const int &NodeN) const
Returns ID of NodeN-th neighboring node.
bool operator<(const TNodeI &NodeI) const
TBPGraph(const TBPGraph &BPGraph)
!! Reserve(Nodes, Edges); }
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
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
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.
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
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.
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 ...
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
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.
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.
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.
TNodeI & operator++(int)
Increment iterator.
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.
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 IDs 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).
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)
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
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.
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...
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
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.
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()
The vector reduces its 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
bool HasFlag(const TGraphFlag &Flag) const
Allows for run-time checking the type of the graph (see the TGraphFlag for flags).
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 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.
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.