SNAP Library , Developer Reference
2013-01-07 14:03:36
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
|
#include <subgraph.h>
Static Public Member Functions | |
static POutGraph | Do (const PInGraph &InGraph, const TIntV &NIdV, const bool &RenumberNodes) |
Definition at line 353 of file subgraph.h.
static POutGraph TSnap::TSnapDetail::TConvertSubGraph< POutGraph, PInGraph, false >::Do | ( | const PInGraph & | InGraph, |
const TIntV & | NIdV, | ||
const bool & | RenumberNodes | ||
) | [inline, static] |
Definition at line 354 of file subgraph.h.
References THashSet< TKey, THashFunc >::AddKey(), and TVec< TVal >::Len().
{ POutGraph OutGraphPt = POutGraph::TObj::New(); typename POutGraph::TObj& OutGraph = *OutGraphPt; if (! RenumberNodes) { for (int n = 0; n < NIdV.Len(); n++) { OutGraph.AddNode(NIdV[n]); } for (int n = 0; n < NIdV.Len(); n++) { typename PInGraph::TObj::TNodeI NI = InGraph->GetNI(NIdV[n]); for (int e = 0; e < NI.GetOutDeg(); e++) { const int dst = NI.GetOutNId(e); if (! OutGraph.IsNode(dst)) { continue; } OutGraph.AddEdge(NIdV[n], dst); } } } else { // renumber nodes so that node ids are 0...N-1 TIntSet NIdSet(InGraph->GetNodes()); for (int n = 0; n < NIdV.Len(); n++) { const int NId = NIdSet.AddKey(NIdV[n]); OutGraph.AddNode(NId); } for (int n = 0; n < NIdV.Len(); n++) { typename PInGraph::TObj::TNodeI NI = InGraph->GetNI(NIdV[n]); const int src = NIdSet.GetKey(NIdV[n]); for (int e = 0; e < NI.GetOutDeg(); e++) { const int dst = NIdSet.GetKey(NI.GetOutNId(e)); if (! OutGraph.IsNode(dst)) { continue; } OutGraph.AddEdge(src, dst); } } } OutGraph.Defrag(); return OutGraphPt; }