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 PGraph | Do (const PGraph &Graph, const TIntV &NIdV) |
Definition at line 161 of file subgraph.h.
static PGraph TSnap::TSnapDetail::TGetSubGraph< PGraph, false >::Do | ( | const PGraph & | Graph, |
const TIntV & | NIdV | ||
) | [inline, static] |
Definition at line 162 of file subgraph.h.
References THashSet< TKey, THashFunc >::AddKey(), CAssert, THashSet< TKey, THashFunc >::Defrag(), gfEdgeDat, gfMultiGraph, gfNodeDat, HasGraphFlag, TVec< TVal >::Len(), and THashSet< TKey, THashFunc >::Len().
{ CAssert(! HasGraphFlag(typename PGraph::TObj, gfMultiGraph)); PGraph NewGraphPt = PGraph::TObj::New(); typename PGraph::TObj& NewGraph = *NewGraphPt; NewGraph.Reserve(NIdV.Len(), -1); TIntSet NodeSet; for (int n = 0; n < NIdV.Len(); n++) { if (! HasGraphFlag(typename PGraph::TObj, gfNodeDat)) { if (Graph->IsNode(NIdV[n])) { NewGraph.AddNode(NIdV[n]); NodeSet.AddKey(NIdV[n]); } } else { if (Graph->IsNode(NIdV[n])) { NewGraph.AddNode(Graph->GetNI(NIdV[n])); NodeSet.AddKey(NIdV[n]); } } } for (int n = 0; n < NodeSet.Len(); n++) { const int SrcNId = NodeSet[n]; const typename PGraph::TObj::TNodeI NI = Graph->GetNI(SrcNId); for (int edge = 0; edge < NI.GetOutDeg(); edge++) { const int OutNId = NI.GetOutNId(edge); if (NewGraph.IsNode(OutNId)) { if (! HasGraphFlag(typename PGraph::TObj, gfEdgeDat)) { NewGraph.AddEdge(SrcNId, OutNId); } else { NewGraph.AddEdge(Graph->GetEI(SrcNId, OutNId)); } // also copy data } } } NewGraph.Defrag(); return NewGraphPt; }