SNAP Library 2.1, Developer Reference
2013-09-25 10:47:25
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 316 of file subgraph.h.
static POutGraph TSnap::TSnapDetail::TConvertSubGraph< POutGraph, PInGraph, IsMultiGraph >::Do | ( | const PInGraph & | InGraph, |
const TIntV & | NIdV, | ||
const bool & | RenumberNodes | ||
) | [inline, static] |
Definition at line 317 of file subgraph.h.
References THashSet< TKey, THashFunc >::AddKey(), gfDirected, HasGraphFlag, and TVec< TVal, TSizeTy >::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 (typename PInGraph::TObj::TEdgeI EI = InGraph->BegEI(); EI < InGraph->EndEI(); EI++) { if (! OutGraph.IsNode(EI.GetSrcNId()) || ! OutGraph.IsNode(EI.GetDstNId())) { continue; } OutGraph.AddEdge(EI.GetSrcNId(), EI.GetDstNId()); if (! HasGraphFlag(typename PInGraph::TObj, gfDirected) && HasGraphFlag(typename POutGraph::TObj, gfDirected)) { OutGraph.AddEdge(EI.GetDstNId(), EI.GetSrcNId()); } } } 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 (typename PInGraph::TObj::TEdgeI EI = InGraph->BegEI(); EI < InGraph->EndEI(); EI++) { const int SrcNId = NIdSet.GetKeyId(EI.GetSrcNId()); const int DstNId = NIdSet.GetKeyId(EI.GetDstNId()); if (! OutGraph.IsNode(SrcNId) || ! OutGraph.IsNode(DstNId)) { continue; } OutGraph.AddEdge(SrcNId, DstNId); if (! HasGraphFlag(typename PInGraph::TObj, gfDirected) && HasGraphFlag(typename POutGraph::TObj, gfDirected)) { OutGraph.AddEdge(DstNId, SrcNId); } } } OutGraph.Defrag(); return OutGraphPt; }