84 int GetInNId(
const int& NodeN)
const {
return NodeHI.GetDat().GetInNId(NodeN); }
88 int GetOutNId(
const int& NodeN)
const {
return NodeHI.GetDat().GetOutNId(NodeN); }
92 int GetNbrNId(
const int& NodeN)
const {
return NodeHI.GetDat().GetNbrNId(NodeN); }
94 bool IsInNId(
const int& NId)
const {
return NodeHI.GetDat().IsInNId(NId); }
96 bool IsOutNId(
const int& NId)
const {
return NodeHI.GetDat().IsOutNId(NId); }
217 int AddEdge(
const int& SrcNId,
const int& DstNId);
222 int AddOutEdge1(
int& SrcIdx,
const int& SrcNId,
const int& DstNId);
223 int AddInEdge1(
int& DstIdx,
const int& SrcNId,
const int& DstNId);
224 void AddOutEdge2(
const int& SrcNId,
const int& DstNId);
225 void AddInEdge2(
const int& SrcNId,
const int& DstNId);
235 void DelEdge(
const int& SrcNId,
const int& DstNId,
const bool& IsDir =
true);
237 bool IsEdge(
const int& SrcNId,
const int& DstNId,
const bool& IsDir =
true)
const;
245 TEdgeI
GetEI(
const int& SrcNId,
const int& DstNId)
const;
259 void Reserve(
const int& Nodes,
const int& Edges) {
if (Nodes>0) {
NodeH.
Gen(Nodes); } }
261 void ReserveNodeDegs(
const int& Idx,
const int& InDeg,
const int& OutDeg) {
if (InDeg > 0)
NodeH[Idx].InNIdV.Reserve(InDeg);
if (OutDeg > 0)
NodeH[Idx].OutNIdV.Reserve(OutDeg); }
267 void SortEdges(
const int& Idx,
const int& InDeg,
const int& OutDeg) {
if (InDeg > 0)
NodeH[Idx].InNIdV.Sort();
if (OutDeg > 0)
NodeH[Idx].OutNIdV.Sort(); }
276 void Defrag(
const bool& OnlyNodeLinks=
false);
281 bool IsOk(
const bool& ThrowExcept=
true)
const;
283 void Dump(FILE *OutF=stdout)
const;
TIter GetI(const TKey &Key) const
void AddOutEdge2(const int &SrcNId, const int &DstNId)
bool Empty() const
Tests whether the graph is empty (has zero nodes).
bool operator<(const TEdgeI &EdgeI) const
int GetOutNId(const int &NodeN) const
int AddOutEdge1(int &SrcIdx, const int &SrcNId, const int &DstNId)
void Save(TSOut &SOut) const
bool IsNbrNId(const int &NId) const
void ReserveNIdInDeg(const int &NId, const int &InDeg)
Reserves memory for node ID NId having InDeg in-edges.
int GetMxNId() const
Returns the maximum id of a any node in the graph.
void Save(TSOut &SOut) const
TNGraphMP(const TNGraphMP &Graph)
void SortEdges(const int &Idx, const int &InDeg, const int &OutDeg)
Sorts in-edges and out-edges.
TNodeI GetNI(const int &NId) const
Returns an iterator referring to the node of ID NId in the graph.
Tests (at compile time) if the graph is directed.
void ReserveNIdOutDeg(const int &NId, const int &OutDeg)
Reserves memory for node ID NId having OutDeg out-edges.
TSizeTy Len() const
Returns the number of elements in the vector.
TEdgeI & operator++(int)
Increment iterator.
static PNGraphMP New()
Static constructor that returns a pointer to the graph. Call: PNGraphMP Graph = TNGraphMP::New().
void DelNode(const int &NId)
Deletes node of ID NId from the graph.
TEdgeI(const TNodeI &NodeI, const TNodeI &EndNodeI, const int &EdgeN=0)
void SetLen(const int &Length)
int GetOutNId(const int &NodeN) const
Returns ID of NodeN-th out-node (the node the current node points to).
int AddEdge(const TEdgeI &EdgeI)
Adds an edge from EdgeI.GetSrcNId() to EdgeI.GetDstNId() to the graph.
bool operator<(const TNodeI &NodeI) const
const TNode & GetNode(const int &NId) const
int GetNbrNId(const int &NodeN) const
void Save(TSOut &SOut) const
void DelEdge(const int &SrcNId, const int &DstNId, const bool &IsDir=true)
Deletes an edge from node IDs SrcNId to DstNId from the graph.
TNodeI(const THashIter &NodeHIter)
void Dump(FILE *OutF=stdout) const
Print the graph in a human readable form to an output stream OutF.
int GetEdges() const
Returns the number of edges in the graph.
void ReserveNodeDegs(const int &Idx, const int &InDeg, const int &OutDeg)
Reserves memory for node Idx having InDeg in-edges and OutDeg out-edges.
void Save(TSOut &SOut) const
void SortNIdV()
Sorts the adjacency lists of the current node.
int GetInNId(const int &NodeN) const
TNodeI GetRndNI(TRnd &Rnd=TInt::Rnd)
Returns an interator referring to a random node in the graph.
static PNGraphMP 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 Reserve(const int &Nodes, const int &Edges)
Reserves memory for a graph of Nodes nodes and Edges edges.
TEdgeI BegEI() const
Returns an iterator referring to the first edge in the graph.
TNodeI BegNI() const
Returns an iterator referring to the first node in the graph.
int AddEdgeUnchecked(const int &SrcNId, const int &DstNId)
Adds an edge from node IDs SrcNId to node DstNId to the graph without performing checks.
void Defrag(const bool &OnlyNodeLinks=false)
Defragments the graph.
bool operator==(const TEdgeI &EdgeI) const
int AddNode(const TNodeI &NodeId)
Adds a node of ID NodeI.GetId() to the graph.
void Sort(const bool &Asc=true)
Sorts the elements of the vector.
void AddInEdge2(const int &SrcNId, const int &DstNId)
int GetRndNId(TRnd &Rnd=TInt::Rnd)
Returns an ID of a random node in the graph.
TNodeI EndNI() const
Returns an iterator referring to the past-the-end node in the graph.
TNGraphMP & operator=(const TNGraphMP &Graph)
int GetSrcNId() const
Gets the source node of an edge.
void DelNode(const TNode &NodeI)
Deletes node of ID NodeI.GetId() from the graph.
void Save(TSOut &SOut) const
Saves the graph to a (binary) stream SOut.
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
void SetNodes(const int &Length)
Sets the number of nodes in the graph.
Directed graph for multi-threaded operations.
int GetDeg() const
Returns degree of the current node, the sum of in-degree and out-degree.
int GetDstNId() const
Gets destination node of an edge.
TEdgeI GetEI(const int &SrcNId, const int &DstNId) const
Returns an iterator referring to edge (SrcNId, DstNId) in the graph.
bool IsKey(const TKey &Key) const
bool IsOutNId(const int &NId) const
Tests whether the current node points to node with ID NId.
int GetId() const
Returns ID of the current node.
TNGraphMP(const int &Nodes, const int &Edges)
Constructor that reserves enough memory for a graph of Nodes nodes and Edges edges.
int AddInEdge1(int &DstIdx, const int &SrcNId, const int &DstNId)
Edge iterator. Only forward iteration (operator++) is supported.
Node iterator. Only forward iteration (operator++) is supported.
bool IsInNId(const int &NId) const
void Clr()
Deletes all nodes and edges from the graph.
TSizeTy SearchBin(const TVal &Val) const
Returns the position of an element with value Val.
void AddNodeWithEdges(const TInt &NId, TIntV &InNIdV, TIntV &OutNIdV)
Adds a node of ID NId to the graph, creates edges to the node from all nodes in vector InNIdV...
friend class TNGraphMPMtx
bool HasFlag(const TGraphFlag &Flag) const
Allows for run-time checking the type of the graph (see the TGraphFlag for flags).
int GetReservedKeyIds() const
bool IsInNId(const int &NId) const
Tests whether node with ID NId points to the current node.
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...
void Gen(const int &ExpectVals)
THashMP< TInt, TNode > NodeH
TNGraphMP(TSIn &SIn)
Constructor that loads the graph from a (binary) stream SIn.
bool IsOutNId(const int &NId) const
bool IsOk(const bool &ThrowExcept=true) const
Checks the graph data structure for internal consistency.
int GetOutDeg() const
Returns out-degree of the current node.
void GetNIdV(TIntV &NIdV) const
Gets a vector IDs of all nodes in the graph.
int GetId() const
Gets edge ID. Always returns -1 since only edges in multigraphs have explicit IDs.
void SortNodeAdjV()
Sorts the adjacency lists of each node.
int GetNbrNId(const int &NodeN) const
Returns ID of NodeN-th neighboring node.
void Pack()
Reduces vector capacity (frees memory) to match its size.
enum TGraphFlag_ TGraphFlag
Graph Flags, used for quick testing of graph types.
int GetInDeg() const
Returns in-degree of the current node.
TEdgeI & operator=(const TEdgeI &EdgeI)
Hash-Table with multiprocessing support.
TEdgeI EndEI() const
Returns an iterator referring to the past-the-end edge in the graph.
bool IsNbrNId(const int &NId) const
Tests whether node with ID NId is a neighbor of the current node.
int GetNodes() const
Returns the number of nodes in the graph.
void Clr(const bool &DoDel=true)
static PNGraphMP GetSmallGraph()
Returns a small graph on 5 nodes and 6 edges.
void Reserve(const TSizeTy &_MxVals)
Reserves enough memory for the vector to store _MxVals elements.
int AddNode(int NId=-1)
Adds a node of ID NId to the graph.
bool operator==(const TNodeI &NodeI) const
TNodeI & operator++(int)
Increment iterator.
int AddNodeUnchecked(int NId=-1)
Adds a node of ID NId to the graph without performing checks.
static PNGraphMP Load(TSIn &SIn)
Static constructor that loads the graph from a stream SIn and returns a pointer to it...
TPt< TNGraphMP > PNGraphMP
TNodeI & operator=(const TNodeI &NodeI)
TEdgeI(const TEdgeI &EdgeI)
const TDat & GetDat(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 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.
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 graph.
THashMP< TInt, TNode >::TIter THashIter
TNodeI(const TNodeI &NodeI)
const TKey & GetKey(const int &KeyId) const