SNAP Library 4.0, Developer Reference
2017-07-27 13:18:06
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
|
Node Network (directed graph, TNGraph with data on nodes only). More...
#include <network.h>
Classes | |
class | TEdgeI |
Edge iterator. Only forward iteration (operator++) is supported. More... | |
class | TNode |
class | TNodeFunctor |
class | TNodeI |
Node iterator. Only forward iteration (operator++) is supported. More... | |
Public Types | |
typedef TNodeData | TNodeDat |
typedef TNodeNet< TNodeData > | TNet |
typedef TPt< TNet > | PNet |
Public Member Functions | |
TNodeNet () | |
TNodeNet (const int &Nodes, const int &Edges) | |
Constructor that reserves enough memory for a network of Nodes nodes and Edges edges. More... | |
TNodeNet (const TNodeNet &NodeNet) | |
TNodeNet (TSIn &SIn) | |
Constructor that loads the network from a (binary) stream SIn. More... | |
virtual | ~TNodeNet () |
virtual void | Save (TSOut &SOut) const |
Saves the network to a (binary) stream SOut. More... | |
bool | HasFlag (const TGraphFlag &Flag) const |
Allows for run-time checking the type of the network (see the TGraphFlag for flags). More... | |
TNodeNet & | operator= (const TNodeNet &NodeNet) |
int | GetNodes () const |
Returns the number of nodes in the network. More... | |
int | AddNode (int NId=-1) |
Adds a node of ID NId to the network. More... | |
int | AddNodeUnchecked (int NId=-1) |
Adds a node of ID NId to the network, noop if the node already exists. More... | |
int | AddNode (int NId, const TNodeData &NodeDat) |
Adds a node of ID NId and node data NodeDat to the network. More... | |
int | AddNode (const TNodeI &NodeI) |
Adds a node NodeI and its node data to the network. More... | |
virtual void | DelNode (const int &NId) |
Deletes node of ID NId from the network. More... | |
void | DelNode (const TNode &NodeI) |
Deletes node of ID NodeI.GetId() from the network. More... | |
bool | IsNode (const int &NId) const |
Tests whether ID NId is a node. More... | |
TNodeI | BegNI () const |
Returns an iterator referring to the first node in the network. More... | |
TNodeI | EndNI () const |
Returns an iterator referring to the past-the-end node in the network. More... | |
TNodeI | GetNI (const int &NId) const |
Returns an iterator referring to the node of ID NId in the network. More... | |
const TNode & | GetNode (const int &NId) const |
Returns node element for the node of ID NId in the network. More... | |
void | SetNDat (const int &NId, const TNodeData &NodeDat) |
Sets node data for the node of ID NId in the network. More... | |
TNodeData & | GetNDat (const int &NId) |
Returns node data for the node of ID NId in the network. More... | |
const TNodeData & | GetNDat (const int &NId) const |
Returns node data for the node of ID NId in the network. More... | |
int | GetMxNId () const |
Returns an ID that is larger than any node ID in the network. More... | |
int | GetEdges () const |
Returns the number of edges in the network. More... | |
int | AddEdge (const int &SrcNId, const int &DstNId) |
Adds an edge from node SrcNId to node DstNId to the network. More... | |
int | AddEdge (const TEdgeI &EdgeI) |
Adds an edge from EdgeI.GetSrcNId() to EdgeI.GetDstNId() to the network. More... | |
void | DelEdge (const int &SrcNId, const int &DstNId, const bool &IsDir=true) |
Deletes an edge from node IDs SrcNId to DstNId from the network. More... | |
bool | IsEdge (const int &SrcNId, const int &DstNId, const bool &IsDir=true) const |
Tests whether an edge from node IDs SrcNId to DstNId exists in the network. More... | |
TEdgeI | BegEI () const |
Returns an iterator referring to the first edge in the network. More... | |
TEdgeI | EndEI () const |
Returns an iterator referring to the past-the-end edge in the network. More... | |
TEdgeI | GetEI (const int &EId) const |
Not supported/implemented! More... | |
TEdgeI | GetEI (const int &SrcNId, const int &DstNId) const |
Returns an iterator referring to edge (SrcNId, DstNId) in the network. More... | |
int | GetRndNId (TRnd &Rnd=TInt::Rnd) |
Returns an ID of a random node in the network. More... | |
TNodeI | GetRndNI (TRnd &Rnd=TInt::Rnd) |
Returns an interator referring to a random node in the network. More... | |
void | GetNIdV (TIntV &NIdV) const |
Gets a vector IDs of all nodes in the network. More... | |
bool | Empty () const |
Tests whether the network is empty (has zero nodes). More... | |
void | Clr (const bool &DoDel=true, const bool &ResetDat=true) |
Deletes all nodes and edges from the network. More... | |
void | Reserve (const int &Nodes, const int &Edges) |
Reserves memory for a network of Nodes nodes and Edges edges. More... | |
void | SortNIdById (const bool &Asc=true) |
Sorts nodes by node IDs. More... | |
void | SortNIdByDat (const bool &Asc=true) |
Sorts nodes by node data. More... | |
void | Defrag (const bool &OnlyNodeLinks=false) |
Defragments the network. More... | |
bool | IsOk (const bool &ThrowExcept=true) const |
Checks the network data structure for internal consistency. More... | |
Static Public Member Functions | |
static PNet | New () |
Static constructor that returns a pointer to the network. Call: TPt <TNodeNet<TNodeData> > Net = TNodeNet<TNodeData>::New(). More... | |
static PNet | Load (TSIn &SIn) |
Static constructor that loads the network from a stream SIn and returns a pointer to it. More... | |
static PNet | LoadShM (TShMIn &ShMIn) |
Static constructor that loads the network from shared memory. More... | |
Protected Member Functions | |
TNode & | GetNode (const int &NId) |
Protected Attributes | |
TCRef | CRef |
TInt | MxNId |
THash< TInt, TNode > | NodeH |
Private Member Functions | |
void | LoadNetworkShM (TShMIn &ShMIn) |
Friends | |
class | TPt< TNodeNet< TNodeData > > |
Node Network (directed graph, TNGraph with data on nodes only).
Definition at line 160 of file network.h.
Referenced by TNodeNet< TSecTm >::Load(), TNodeNet< TSecTm >::LoadShM(), and TNodeNet< TSecTm >::New().
|
inlineexplicit |
Constructor that reserves enough memory for a network of Nodes nodes and Edges edges.
Definition at line 162 of file network.h.
|
inline |
int TNodeNet< TNodeData >::AddEdge | ( | const int & | SrcNId, |
const int & | DstNId | ||
) |
Adds an edge from node SrcNId to node DstNId to the network.
If the edge already exists return -2. If the edge was successfully added return -1. Normally the function should return an ID of the edge added but since edges in TNodeNet have no IDs we return -1. Function aborts if SrcNId or DstNId are not nodes in the network.
Definition at line 381 of file network.h.
References TStr::Fmt(), and IAssertR.
Referenced by TTimeNet::GetSubGraph(), TTimeNet::LoadAmazon(), TTimeNet::LoadArxiv(), TTimeNet::LoadBipartite(), and TTimeNet::LoadPatents().
Adds an edge from EdgeI.GetSrcNId() to EdgeI.GetDstNId() to the network.
Definition at line 247 of file network.h.
Referenced by TNodeNet< TSecTm >::AddEdge().
int TNodeNet< TNodeData >::AddNode | ( | int | NId = -1 | ) |
Adds a node of ID NId to the network.
Returns the ID of the node being added. If NId is -1, node ID is automatically assigned. Aborts, if a node with ID NId already exists.
Definition at line 311 of file network.h.
References TStr::Fmt(), IAssertR, and TMath::Mx().
Referenced by TTimeNet::GetSubGraph(), TTimeNet::LoadAmazon(), TTimeNet::LoadArxiv(), TTimeNet::LoadBipartite(), and TTimeNet::LoadPatents().
int TNodeNet< TNodeData >::AddNode | ( | int | NId, |
const TNodeData & | NodeDat | ||
) |
Adds a node of ID NId and node data NodeDat to the network.
Returns the ID of the node being added. If NId is -1, node ID is automatically assigned. Aborts, if a node with ID NId already exists.
Definition at line 335 of file network.h.
References TStr::Fmt(), IAssertR, and TMath::Mx().
Adds a node NodeI and its node data to the network.
Definition at line 209 of file network.h.
Referenced by TNodeNet< TSecTm >::AddNode().
int TNodeNet< TNodeData >::AddNodeUnchecked | ( | int | NId = -1 | ) |
Adds a node of ID NId to the network, noop if the node already exists.
Returns -1, if the node NId already exists. Otherwise, it returns the ID of the node being added. If NId is -1, node ID is automatically assigned.
Definition at line 323 of file network.h.
References TMath::Mx().
Returns an iterator referring to the first edge in the network.
Definition at line 257 of file network.h.
Returns an iterator referring to the first node in the network.
Definition at line 219 of file network.h.
Referenced by TNodeNet< TSecTm >::BegEI(), TTimeNet::LoadArxiv(), and TTimeNet::LoadPatents().
|
inline |
Deletes all nodes and edges from the network.
Definition at line 275 of file network.h.
void TNodeNet< TNodeData >::Defrag | ( | const bool & | OnlyNodeLinks = false | ) |
Defragments the network.
After performing many node and edge insertions and deletions to a network, the network data structure will be fragmented in memory. This function compacts down the network data structure and frees unneeded memory.
Definition at line 423 of file network.h.
References TNodeNet< TNodeData >::TNode::InNIdV, TNodeNet< TNodeData >::TNode::OutNIdV, and TVec< TVal, TSizeTy >::Pack().
Referenced by TTimeNet::GetSubGraph(), TTimeNet::LoadAmazon(), TTimeNet::LoadArxiv(), TTimeNet::LoadBipartite(), and TTimeNet::LoadPatents().
void TNodeNet< TNodeData >::DelEdge | ( | const int & | SrcNId, |
const int & | DstNId, | ||
const bool & | IsDir = true |
||
) |
Deletes an edge from node IDs SrcNId to DstNId from the network.
If the edge (SrcNId, DstNId) does not exist in the network function still completes. But the function aborts if SrcNId or DstNId are not nodes in the network.
Definition at line 390 of file network.h.
References TStr::Fmt(), and IAssertR.
|
virtual |
Deletes node of ID NId from the network.
If the node of ID NId does not exist the function aborts.
Definition at line 347 of file network.h.
References TVec< TVal, TSizeTy >::Del(), TNodeNet< TNodeData >::TNode::GetInDeg(), TNodeNet< TNodeData >::TNode::GetInNId(), TNodeNet< TNodeData >::TNode::GetOutDeg(), TNodeNet< TNodeData >::TNode::GetOutNId(), TNodeNet< TNodeData >::TNode::InNIdV, TNodeNet< TNodeData >::TNode::OutNIdV, and TVec< TVal, TSizeTy >::SearchBin().
Referenced by TTimeNet::LoadArxiv(), and TTimeNet::LoadPatents().
Deletes node of ID NodeI.GetId() from the network.
Definition at line 215 of file network.h.
Referenced by TNodeNet< TSecTm >::DelNode().
|
inline |
Tests whether the network is empty (has zero nodes).
Definition at line 273 of file network.h.
Returns an iterator referring to the past-the-end edge in the network.
Definition at line 259 of file network.h.
Returns an iterator referring to the past-the-end node in the network.
Definition at line 221 of file network.h.
Referenced by TNodeNet< TSecTm >::BegEI(), TNodeNet< TSecTm >::EndEI(), TTimeNet::LoadArxiv(), and TTimeNet::LoadPatents().
int TNodeNet< TNodeData >::GetEdges | ( | ) | const |
Returns the number of edges in the network.
Definition at line 373 of file network.h.
Referenced by TTimeNet::LoadAmazon(), TTimeNet::LoadArxiv(), TTimeNet::LoadBipartite(), and TTimeNet::LoadPatents().
Not supported/implemented!
TNodeNet< TNodeData >::TEdgeI TNodeNet< TNodeData >::GetEI | ( | const int & | SrcNId, |
const int & | DstNId | ||
) | const |
Returns an iterator referring to edge (SrcNId, DstNId) in the network.
Definition at line 415 of file network.h.
References TNodeNet< TNodeData >::TNodeI::NodeHI.
|
inline |
|
inline |
Returns node data for the node of ID NId in the network.
Definition at line 229 of file network.h.
Referenced by TNodeNet< TNodeData >::TNodeI::GetInNDat(), TNodeNet< TNodeData >::TNodeI::GetNbrNDat(), TNodeNet< TNodeData >::TNodeI::GetOutNDat(), TTimeNet::LoadArxiv(), TTimeNet::LoadBipartite(), and TTimeNet::LoadPatents().
|
inline |
Returns an iterator referring to the node of ID NId in the network.
Definition at line 223 of file network.h.
Referenced by TNodeNet< TSecTm >::GetRndNI().
Gets a vector IDs of all nodes in the network.
Definition at line 408 of file network.h.
References TVec< TVal, TSizeTy >::Add(), and TVec< TVal, TSizeTy >::Reserve().
|
inline |
|
inline |
Returns the number of nodes in the network.
Definition at line 189 of file network.h.
Referenced by TNodeNet< TSecTm >::Empty(), TTimeNet::LoadAmazon(), TTimeNet::LoadArxiv(), TTimeNet::LoadBipartite(), and TTimeNet::LoadPatents().
Returns an interator referring to a random node in the network.
Definition at line 268 of file network.h.
Returns an ID of a random node in the network.
Definition at line 266 of file network.h.
Referenced by TNodeNet< TSecTm >::GetRndNI().
bool TNodeNet< TNodeData >::HasFlag | ( | const TGraphFlag & | Flag | ) | const |
Allows for run-time checking the type of the network (see the TGraphFlag for flags).
Definition at line 306 of file network.h.
References HasGraphFlag.
bool TNodeNet< TNodeData >::IsEdge | ( | const int & | SrcNId, |
const int & | DstNId, | ||
const bool & | IsDir = true |
||
) | const |
Tests whether an edge from node IDs SrcNId to DstNId exists in the network.
Definition at line 401 of file network.h.
Referenced by TTimeNet::LoadAmazon(), TTimeNet::LoadArxiv(), TTimeNet::LoadBipartite(), and TTimeNet::LoadPatents().
|
inline |
Tests whether ID NId is a node.
Definition at line 217 of file network.h.
Referenced by TTimeNet::GetSubGraph(), TTimeNet::LoadAmazon(), TTimeNet::LoadArxiv(), TTimeNet::LoadBipartite(), and TTimeNet::LoadPatents().
bool TNodeNet< TNodeData >::IsOk | ( | const bool & | ThrowExcept = true | ) | const |
Checks the network data structure for internal consistency.
For each node in the network check that its neighbors are also nodes in the network.
Definition at line 433 of file network.h.
References TStr::CStr(), EAssertR, ErrNotify(), TStr::Fmt(), TNodeNet< TNodeData >::TNode::GetId(), TNodeNet< TNodeData >::TNode::GetInDeg(), TNodeNet< TNodeData >::TNode::GetInNId(), TNodeNet< TNodeData >::TNode::GetOutDeg(), TNodeNet< TNodeData >::TNode::GetOutNId(), TNodeNet< TNodeData >::TNode::InNIdV, TVec< TVal, TSizeTy >::IsSorted(), and TNodeNet< TNodeData >::TNode::OutNIdV.
|
inlineprivate |
Definition at line 153 of file network.h.
Referenced by TNodeNet< TSecTm >::LoadShM().
Static constructor that returns a pointer to the network. Call: TPt <TNodeNet<TNodeData> > Net = TNodeNet<TNodeData>::New().
Definition at line 170 of file network.h.
|
inline |
|
inline |
Reserves memory for a network of Nodes nodes and Edges edges.
Definition at line 278 of file network.h.
Referenced by TTimeNet::GetSubGraph(), TTimeNet::LoadAmazon(), TTimeNet::LoadPatents(), and TNodeNet< TSecTm >::TNodeNet().
|
inlinevirtual |
void TNodeNet< TNodeData >::SetNDat | ( | const int & | NId, |
const TNodeData & | NodeDat | ||
) |
Sets node data for the node of ID NId in the network.
Definition at line 367 of file network.h.
References TStr::Fmt(), and IAssertR.
|
inline |
|
inline |
Definition at line 143 of file network.h.
Referenced by TNodeNet< TSecTm >::Clr(), TNodeNet< TSecTm >::GetMxNId(), TNodeNet< TSecTm >::LoadNetworkShM(), TNodeNet< TSecTm >::operator=(), and TNodeNet< TSecTm >::Save().
Definition at line 144 of file network.h.
Referenced by TNodeNet< TSecTm >::BegNI(), TNodeNet< TSecTm >::Clr(), TNodeNet< TSecTm >::EndNI(), TNodeNet< TSecTm >::GetNDat(), TNodeNet< TSecTm >::GetNI(), TNodeNet< TSecTm >::GetNode(), TNodeNet< TSecTm >::GetNodes(), TNodeNet< TSecTm >::GetRndNId(), TNodeNet< TSecTm >::IsNode(), TNodeNet< TSecTm >::LoadNetworkShM(), TNodeNet< TSecTm >::operator=(), TNodeNet< TSecTm >::Reserve(), TNodeNet< TSecTm >::Save(), TNodeNet< TSecTm >::SortNIdByDat(), and TNodeNet< TSecTm >::SortNIdById().