58 TEdge(
const int& EId,
const int& SourceNId,
const int& DestNId) :
Id(EId),
SrcNId(SourceNId),
DstNId(DestNId) { }
103 bool IsInNId(
const int& NId)
const;
105 bool IsOutNId(
const int& NId)
const;
508 int AddEdge(
const int& SrcNId,
const int& DstNId,
int EId = -1);
524 bool IsEdge(
const int& SrcNId,
const int& DstNId,
const bool& IsDir =
true)
const {
int EId;
return IsEdge(SrcNId, DstNId, EId, IsDir); }
526 bool IsEdge(
const int& SrcNId,
const int& DstNId,
int& EId,
const bool& IsDir =
true)
const;
528 int GetEId(
const int& SrcNId,
const int& DstNId)
const {
int EId;
return IsEdge(SrcNId, DstNId, EId)?EId:-1; }
560 void Reserve(
const int& Nodes,
const int& Edges) {
563 void ReserveAttr(
const int& NIntAttr,
const int& NFltAttr,
const int& NStrAttr,
const int& EIntAttr,
564 const int& EFltAttr,
const int& EStrAttr) {
578 void Defrag(
const bool& OnlyNodeLinks=
false);
583 bool IsOk(
const bool& ThrowExcept=
true)
const;
585 void Dump(FILE *OutF=stdout)
const;
733 #endif // NETWORKMP_H
void SetNodes(const int &Length)
Sets the number of nodes in the graph.
TIter GetI(const TKey &Key) const
void GetStrAttrNames(TStrV &Names) const
Gets vector of str attribute names.
TStr GetDat() const
Returns an attribute of the node.
TIter EndI() const
Returns an iterator referring to the past-the-end element in the vector.
TFlt GetFltAttrDatE(const TEdgeI &EdgeId, const TStr &attr)
Gets the value of flt attr from the edge attr value vector.
bool IsInNId(const int &NId) const
Tests whether node with ID NId points to the current node.
bool operator==(const TAFltI &I) const
void GetStrAttrVal(TStrV &Val) const
Gets vector of str attribute values.
int GetId() const
Returns ID of the current node.
void Save(TSOut &SOut) const
bool operator<(const TAStrI &I) const
TEdge(const int &EId, const int &SourceNId, const int &DestNId)
void FltAttrNameNI(const TInt &NId, TStrV &Names) const
Returns a vector of int attr names for node NId.
void Save(TSOut &SOut) const
void GetFltAttrVal(TFltV &Val) const
Gets vector of flt attribute values.
int GetOutDeg() const
Returns out-degree of the current node.
int GetNodes() const
Returns the number of nodes in the graph.
Directed multigraph with node edge attributes.
void StrAttrValueEI(const TInt &EId, TStrV &Values) const
Returns a vector of attr values for node NId.
bool IsDeleted() const
Returns true if the attribute has been deleted.
TEdgeI & operator=(const TEdgeI &EdgeI)
int GetInNId(const int &EdgeN) const
Returns ID of EdgeN-th in-node (the node pointing to the current node).
TStrIntPrH KeyToIndexTypeE
int GetMxEId() const
Returns an ID that is larger than any edge ID in the network.
void Clr()
Deletes all nodes and edges from the graph.
bool IsOutNId(const int &NId) const
Tests whether the current node points to node with ID NId.
bool operator<(const TAIntI &I) const
TPt< TNEANetMP > PNEANetMP
Pointer to a directed attribute multigraph (TNEANetMP)
TInt GetIntAttrDefaultE(const TStr &attribute) const
Get Int edge attribute val. If not a proper attr, return default.
int GetEdges() const
Returns the number of edges in the graph.
TVec< TIntV > VecOfIntVecsN
void Save(TSOut &SOut) const
TAIntI BegEAIntI(const TStr &attr) const
Returns an iterator referring to the first edge's int attribute.
TStr GetStrAttrDefaultN(const TStr &attribute) const
Get Str node attribute val. If not a proper attr, return default.
bool Empty() const
Tests whether the graph is empty (has zero nodes).
bool EdgeAttrIsStrDeleted(const int &EId, const TStrIntPrH::TIter &EdgeHI) const
bool IsOk(const bool &ThrowExcept=true) const
Checks the graph data structure for internal consistency.
void ReserveAttr(const int &NIntAttr, const int &NFltAttr, const int &NStrAttr, const int &EIntAttr, const int &EFltAttr, const int &EStrAttr)
Reserves memory for dense attributes.
static PNEANetMP New()
Static cons returns pointer to graph. Ex: PNEANetMP Graph=TNEANetMP::New().
Tests (at compile time) if the graph is directed.
TStrIntPrH KeyToIndexTypeN
KeyToIndexType[N|E]: Key->(Type,Index).
TSizeTy Len() const
Returns the number of elements in the vector.
void SetEdges(const int &Length)
Sets the number of edges in the graph.
bool operator<(const TNodeI &NodeI) const
int AddIntAttrDatE(const TEdgeI &EdgeId, const TInt &value, const TStr &attr)
Attribute based add function for attr to Int value.
int GetInEId(const int &EdgeN) const
Returns ID of EdgeN-th in-edge.
TAIntI(const TIntVecIter &HIter, TStr attribute, bool isEdgeIter, const TNEANetMP *GraphPt)
TNodeI & operator=(const TNodeI &NodeI)
void Reserve(const int &Nodes, const int &Edges)
Reserves memory for a graph of Nodes nodes and Edges edges.
TEdgeI GetEI(const int &EId) const
Returns an iterator referring to edge with edge ID EId.
int GetDeg() const
Returns degree of the current node, the sum of in-degree and out-degree.
void Save(TSOut &SOut) const
TVec< TFltV > VecOfFltVecsN
void GetAttrNames(TStrV &Names) const
Gets vector of attribute names.
TEdgeI BegEI() const
Returns an iterator referring to the first edge in the graph.
static PNEANetMP Load(TSIn &SIn)
Static constructor that loads the graph from a stream SIn and returns a pointer to it...
void SetLen(const int &Length)
void FltAttrNameEI(const TInt &EId, TStrV &Names) const
Returns a vector of int attr names for node NId.
THashMP< TStr, TStr > StrDefaultsN
int DelAttrDatN(const TNodeI &NodeId, const TStr &attr)
Deletes the node attribute for NodeId.
void IntAttrNameNI(const TInt &NId, TStrV &Names) const
Returns a vector of int attr names for node NId.
int AddIntAttrE(const TStr &attr, TInt defaultValue=TInt::Mn)
Adds a new Int edge attribute to the hashmap.
bool operator==(const TNodeI &NodeI) const
TStr GetStrAttrDatE(const TEdgeI &EdgeId, const TStr &attr)
Gets the value of str attr from the edge attr value vector.
void GetFltAttrVal(TFltV &Val) const
Gets vector of flt attribute values.
int AddFltAttrDatN(const TNodeI &NodeId, const TFlt &value, const TStr &attr)
Attribute based add function for attr to Flt value.
void Save(TSOut &SOut) const
Saves the graph to a (binary) stream SOut.
TAFltI BegNAFltI(const TStr &attr) const
Returns an iterator referring to the first node's flt attribute.
void Dump(FILE *OutF=stdout) const
Print the graph in a human readable form to an output stream OutF.
TAFltI & operator=(const TAFltI &I)
TAStrI & operator=(const TAStrI &I)
void GetAttrVal(TStrV &Val) const
Gets vector of attribute values.
TAIntI GetNAIntI(const TStr &attr, const int &NId) const
Returns an iterator referring to the node of ID NId in the graph.
void GetIntAttrVal(TIntV &Val) const
Gets vector of int attribute values.
int Reserved() const
Returns the number of nodes reserved in the network.
static PNEANetMP New(const int &Nodes, const int &Edges)
Static constructor that returns a pointer to the graph and reserves enough memory for Nodes nodes and...
TAIntI EndEAIntI(const TStr &attr) const
Returns an iterator referring to the past-the-end edge's attribute.
const TDat & GetDat(const TKey &Key) const
int GetEId(const int &SrcNId, const int &DstNId) const
Returns an edge ID between node IDs SrcNId and DstNId, if such an edge exists. Otherwise, return -1.
int GetNbrEId(const int &EdgeN) const
Returns ID of EdgeN-th in or out-edge.
int GetNbrEId(const int &EdgeN) const
TInt GetIntAttrIndDatN(const TNodeI &NodeId, const int &index)
Gets the value of node int attr specified by the attr index.
void GetStrAttrVal(TStrV &Val) const
Gets vector of str attribute values.
void GetIntAttrVal(TIntV &Val) const
Gets vector of int attribute values.
TEdge & GetEdge(const int &EId)
void StrAttrValueNI(const TInt &NId, TStrV &Values) const
Returns a vector of attr values for node NId.
TStr GetNodeAttrValue(const int &NId, const TStrIntPrH::TIter &NodeHI) const
TNEANetMP(TSIn &SIn)
Constructor for loading the graph from a (binary) stream SIn.
bool IsIntAttrE(const TStr &attr)
THashMP< TStr, TInt > IntDefaultsN
void Save(TSOut &SOut) const
TNodeI GetRndNI(TRnd &Rnd=TInt::Rnd)
Returns an interator referring to a random node in the graph.
void AttrNameEI(const TInt &EId, TStrV &Names) const
Returns a vector of attr names for edge EId.
TAFltI GetNAFltI(const TStr &attr, const int &NId) const
Returns an iterator referring to the node of ID NId in the graph.
THashMP< TInt, TEdge > EdgeH
TInt GetDat() const
Returns an attribute of the node.
TInt GetIntAttrDefaultN(const TStr &attribute) const
Get Int node attribute val. If not a proper attr, return default.
void GetAttrVal(TStrV &Val) const
Gets vector of attribute values.
TStr GetEdgeAttrValue(const int &EId, const TStrIntPrH::TIter &EdgeHI) const
bool IsStrAttrE(const TStr &attr)
void GetFltAttrNames(TStrV &Names) const
Gets vector of flt attribute names.
THashMP< TStr, TStr > StrDefaultsE
const TEdge & GetEdge(const int &EId) const
int GetSrcNId() const
Returns the source of the edge.
TNodeI EndNI() const
Returns an iterator referring to the past-the-end node in the graph.
TAStrI GetNAStrI(const TStr &attr, const int &NId) const
Returns an iterator referring to the node of ID NId in the graph.
void Save(TSOut &SOut) const
Node/edge string attribute iterator. Iterates through all nodes/edges for one string attribute...
void Clr(const bool &DoDel=true, const TSizeTy &NoDelLim=-1)
Clears the contents of the vector.
TVec< TStrV > VecOfStrVecsE
int GetIntAttrIndE(const TStr &attr)
Gets the index of the edge attr value vector specified by str attr.
void StrAttrNameEI(const TInt &EId, TStrV &Names) const
Returns a vector of str attr names for node NId.
TAFltI GetEAFltI(const TStr &attr, const int &EId) const
Returns an iterator referring to the edge of ID EId in the graph.
bool operator<(const TEdgeI &EdgeI) const
TAStrI(const TStrVecIter &HIter, TStr attribute, bool isEdgeIter, const TNEANetMP *GraphPt)
void GetNIdV(TIntV &NIdV) const
Gets a vector IDs of all nodes in the graph.
void IntAttrNameEI(const TInt &EId, TStrV &Names) const
Returns a vector of int attr names for edge EId.
int GetRndNId(TRnd &Rnd=TInt::Rnd)
Returns an ID of a random node in the graph.
TEdgeI GetEI(const int &SrcNId, const int &DstNId) const
Returns an iterator referring to edge (SrcNId, DstNId) in the graph.
TEdgeI(const THashIter &EdgeHIter, const TNEANetMP *GraphPt)
TNode & GetNode(const int &NId)
TNodeI(const THashIter &NodeHIter, const TNEANetMP *GraphPt)
TVec< TFlt > & GetFltAttrVecE(const TStr &attr)
bool IsFltAttrE(const TStr &attr)
bool NodeAttrIsFltDeleted(const int &NId, const TStrIntPrH::TIter &NodeHI) const
TVec< TIntV > VecOfIntVecsE
void GetStrAttrNames(TStrV &Names) const
Gets vector of str attribute names.
Tests (at compile time) if the graph is a multigraph with multiple edges between the same nodes...
bool NodeAttrIsStrDeleted(const int &NId, const TStrIntPrH::TIter &NodeHI) const
TAFltI(const TFltVecIter &HIter, TStr attribute, bool isEdgeIter, const TNEANetMP *GraphPt)
int AddStrAttrN(const TStr &attr, TStr defaultValue=TStr::GetNullStr())
Adds a new Str node attribute to the hashmap.
int GetIntAttrIndN(const TStr &attr)
Gets the index of the node attr value vector specified by str attr.
int GetMxNId() const
Returns an ID that is larger than any node ID in the network.
TFlt GetWeightOutEdges(const TNodeI &NI, const TStr &attr)
TAIntI GetEAIntI(const TStr &attr, const int &EId) const
Returns an iterator referring to the edge of ID EId in the graph.
TFlt GetFltAttrDefaultE(const TStr &attribute) const
Get Flt edge attribute val. If not a proper attr, return default.
bool IsNode(const int &NId) const
If the node of ID NId does not exist the function aborts.
bool operator==(const TEdgeI &EdgeI) const
TStr GetStrAttrDefaultE(const TStr &attribute) const
Get Str edge attribute val. If not a proper attr, return default.
void GetEIdV(TIntV &EIdV) const
Gets a vector IDs of all edges in the graph.
void FltAttrValueNI(const TInt &NId, TFltV &Values) const
Returns a vector of attr values for node NId.
int AddStrAttrDatE(const TEdgeI &EdgeId, const TStr &value, const TStr &attr)
Attribute based add function for attr to Str value.
bool IsKey(const TKey &Key) const
TInt GetIntAttrIndDatE(const TEdgeI &EdgeId, const int &index)
Gets the value of edge int attr specified by the attr index.
void GetIntAttrNames(TStrV &Names) const
Gets vector of int attribute names.
bool NodeAttrIsIntDeleted(const int &NId, const TStrIntPrH::TIter &NodeHI) const
TFlt GetFltAttrDefaultN(const TStr &attribute) const
Get Flt node attribute val. If not a proper attr, return default.
TNodeI & operator++(int)
Increment iterator.
void GetFltAttrNames(TStrV &Names) const
Gets vector of flt attribute names.
TAFltI BegEAFltI(const TStr &attr) const
Returns an iterator referring to the first edge's flt attribute.
THashMP< TStr, TInt > IntDefaultsE
TSizeTy SearchBin(const TVal &Val) const
Returns the position of an element with value Val.
TNEANetMP(const int &Nodes, const int &Edges)
Constructor that reserves enough memory for a graph of nodes and edges.
TNodeI(const TNodeI &NodeI)
Node iterator. Only forward iteration (operator++) is supported.
int GetInEId(const int &EdgeN) const
TNEANetMP(const TNEANetMP &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.
TVal * TIter
Random access iterator to TVal.
TEdgeI & operator++(int)
Increment iterator.
bool IsNbrEId(const int &EId) const
Tests whether the edge with ID EId is an in or out-edge of current node.
int GetReservedKeyIds() const
TAStrI GetEAStrI(const TStr &attr, const int &EId) const
Returns an iterator referring to the edge of ID EId in the graph.
int GetInDeg() const
Returns in-degree of the current node.
int AddStrAttrDatN(const TNodeI &NodeId, const TStr &value, const TStr &attr)
Attribute based add function for attr to Str value.
Node/edge float attribute iterator. Iterates through all nodes/edges for one float attribute...
THashMP< TInt, TNode >::TIter THashIter
TAFltI EndEAFltI(const TStr &attr) const
Returns an iterator referring to the past-the-end edge's attribute.
void AddNodeWithEdges(const TInt &NId, TIntV &InEIdV, TIntV &OutEIdV)
Adds a node along with its neighbor edges.
TNodeI GetNI(const int &NId) const
Returns an iterator referring to the node of ID NId 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...
void Gen(const int &ExpectVals)
int GetOutNId(const int &EdgeN) const
Returns ID of EdgeN-th out-node (the node the current node points to).
Edge iterator. Only forward iteration (operator++) is supported.
TStr GetStrAttrDatN(const TNodeI &NodeId, const TStr &attr)
Gets the value of str attr from the node attr value vector.
TAIntI EndNAIntI(const TStr &attr) const
Returns an iterator referring to the past-the-end node's attribute.
TNEANetMP & operator=(const TNEANetMP &Graph)
void AttrNameNI(const TInt &NId, TStrV &Names) const
Returns a vector of attr names for node NId.
int DelAttrDatE(const TEdgeI &EdgeId, const TStr &attr)
Deletes the edge attribute for NodeId.
bool IsOutEId(const int &EId) const
TAStrI EndNAStrI(const TStr &attr) const
Returns an iterator referring to the past-the-end node's attribute.
TInt GetIntAttrDatN(const TNodeI &NodeId, const TStr &attr)
Gets the value of int attr from the node attr value vector.
int GetNbrNId(const int &EdgeN) const
Returns ID of EdgeN-th neighboring node.
bool operator==(const TAStrI &I) const
THashMP< TInt, TNode > NodeH
TFlt GetFltAttrDatN(const TNodeI &NodeId, const TStr &attr)
Gets the value of flt attr from the node attr value vector.
const TNode & GetNode(const int &NId) const
TVec< TFltV > VecOfFltVecsE
TNodeI BegNI() const
Returns an iterator referring to the first node in the graph.
TFlt GetDat() const
Returns an attribute of the node.
void GetAttrNames(TStrV &Names) const
Gets vector of attribute names.
bool IsDeleted() const
Returns true if the attribute has been deleted.
TIter BegI() const
Returns an iterator pointing to the first element in the vector.
Node/edge integer attribute iterator. Iterates through all nodes/edges for one integer attribute...
bool IsInEId(const int &EId) const
enum TGraphFlag_ TGraphFlag
Graph Flags, used for quick testing of graph types.
TEdgeI GetRndEI(TRnd &Rnd=TInt::Rnd)
Returns an interator referring to a random edge in the graph.
bool HasFlag(const TGraphFlag &Flag) const
Allows for run-time checking the type of the graph (see the TGraphFlag for flags).
int AddNode(int NId=-1)
Adds a node of ID NId to the graph.
TAStrI BegNAStrI(const TStr &attr) const
Returns an iterator referring to the first node's str attribute.
TAFltI EndNAFltI(const TStr &attr) const
Returns an iterator referring to the past-the-end node's attribute.
int ReservedE() const
Returns the number of edges reserved in the network.
int AddIntAttrN(const TStr &attr, TInt defaultValue=TInt::Mn)
Adds a new Int node attribute to the hashmap.
bool operator<(const TAFltI &I) const
TEdgeI EndEI() const
Returns an iterator referring to the past-the-end edge in the graph.
int AddFltAttrE(const TStr &attr, TFlt defaultValue=TFlt::Mn)
Adds a new Flt edge attribute to the hashmap.
void StrAttrNameNI(const TInt &NId, TStrV &Names) const
Returns a vector of str attr names for node NId.
Hash-Table with multiprocessing support.
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.
int AddIntAttrDatN(const TNodeI &NodeId, const TInt &value, const TStr &attr)
Attribute based add function for attr to Int value.
void Clr(const bool &DoDel=true, const int &NoDelLim=-1, const bool &ResetDat=true)
TEdgeI(const TEdgeI &EdgeI)
int AddEdge(const TEdgeI &EdgeI)
Adds an edge between EdgeI.GetSrcNId() and EdgeI.GetDstNId() to the graph.
int GetDstNId() const
Returns the destination of the edge.
bool IsOutEId(const int &EId) const
Tests whether the edge with ID EId is an out-edge of current node.
bool IsDeleted() const
Returns true if the attribute has been deleted.
void Clr(const bool &DoDel=true)
void IntAttrValueEI(const TInt &EId, TIntV &Values) const
Returns a vector of attr values for edge EId.
void FltAttrValueEI(const TInt &EId, TFltV &Values) const
Returns a vector of attr values for node NId.
TInt GetIntAttrDatE(const TEdgeI &EdgeId, const TStr &attr)
Gets the value of int attr from the edge attr value vector.
bool IsInEId(const int &EId) const
Tests whether the edge with ID EId is an in-edge of current node.
THashMP< TStr, TFlt > FltDefaultsE
TAStrI BegEAStrI(const TStr &attr) const
Returns an iterator referring to the first edge's str attribute.
void AttrValueNI(const TInt &NId, TStrV &Values) const
Returns a vector of attr values for node NId.
int GetRndEId(TRnd &Rnd=TInt::Rnd)
Returns an ID of a random edge in the graph.
void AttrValueEI(const TInt &EId, TStrV &Values) const
Returns a vector of attr values for edge EId.
TAStrI EndEAStrI(const TStr &attr) const
Returns an iterator referring to the past-the-end edge's attribute.
TAIntI BegNAIntI(const TStr &attr) const
Returns an iterator referring to the first node's int attribute.
int GetOutEId(const int &EdgeN) const
Returns ID of EdgeN-th out-edge.
int GetOutEId(const int &EdgeN) const
bool IsEdge(const int &EId) const
Tests whether an edge with edge ID EId exists in the graph.
void GetIntAttrNames(TStrV &Names) const
Gets vector of int attribute names.
bool NodeAttrIsDeleted(const int &NId, const TStrIntPrH::TIter &NodeHI) const
bool EdgeAttrIsDeleted(const int &EId, const TStrIntPrH::TIter &EdgeHI) const
int AddStrAttrE(const TStr &attr, TStr defaultValue=TStr::GetNullStr())
Adds a new Str edge attribute to the hashmap.
THashMP< TInt, TEdge >::TIter THashIter
THashMP< TStr, TFlt > FltDefaultsN
bool operator==(const TAIntI &I) const
void Defrag(const bool &OnlyNodeLinks=false)
int GetKeyId(const TKey &Key) const
int AddNode(const TNodeI &NodeId)
Adds a node of ID NodeI.GetId() to the graph.
bool IsNbrNId(const int &NId) const
Tests whether node with ID NId is a neighbor of the current node.
TIter GetI(const TSizeTy &ValN) const
Returns an iterator an element at position ValN.
void IntAttrValueNI(const TInt &NId, TIntV &Values) const
Returns a vector of attr values for node NId.
bool EdgeAttrIsIntDeleted(const int &EId, const TStrIntPrH::TIter &EdgeHI) const
int AddFltAttrDatE(const TEdgeI &EdgeId, const TFlt &value, const TStr &attr)
Attribute based add function for attr to Flt value.
int GetFltKeyIdE(const int &EId)
const TDat & GetDat(const TKey &Key) const
TVec< TStrV > VecOfStrVecsN
void GetWeightOutEdgesV(TFltV &OutWeights, const TFltV &AttrVal)
void SetMxEId(const TInt &Id)
Sets the MaxEId. Used since AddEdgeUnchecked doesn't affect EId for efficiency.
int AddFltAttrN(const TStr &attr, TFlt defaultValue=TFlt::Mn)
Adds a new Flt node attribute to the hashmap.
int GetId() const
Returns edge ID.
TAIntI & operator=(const TAIntI &I)
bool EdgeAttrIsFltDeleted(const int &EId, const TStrIntPrH::TIter &EdgeHI) const
const TKey & GetKey(const int &KeyId) const
void AddEdgeUnchecked(const TInt &EId, const int SrcNId, const int DstNId)
Adds an edge without checking its adjacent nodes' neighborhood.