SNAP Library 3.0, User Reference  2016-07-20 17:56:49
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TSnap::TSnapDetail::TConvertSubGraph< POutGraph, PInGraph, false > Struct Template Reference

#include <subgraph.h>

Static Public Member Functions

static POutGraph Do (const PInGraph &InGraph, const TIntV &NIdV, const bool &RenumberNodes)
 

Detailed Description

template<class POutGraph, class PInGraph>
struct TSnap::TSnapDetail::TConvertSubGraph< POutGraph, PInGraph, false >

Definition at line 359 of file subgraph.h.

Member Function Documentation

template<class POutGraph , class PInGraph >
static POutGraph TSnap::TSnapDetail::TConvertSubGraph< POutGraph, PInGraph, false >::Do ( const PInGraph &  InGraph,
const TIntV NIdV,
const bool &  RenumberNodes 
)
inlinestatic

Definition at line 360 of file subgraph.h.

360  {
361  POutGraph OutGraphPt = POutGraph::TObj::New();
362  typename POutGraph::TObj& OutGraph = *OutGraphPt;
363  if (! RenumberNodes) {
364  for (int n = 0; n < NIdV.Len(); n++) {
365  OutGraph.AddNode(NIdV[n]); }
366  for (int n = 0; n < NIdV.Len(); n++) {
367  typename PInGraph::TObj::TNodeI NI = InGraph->GetNI(NIdV[n]);
368  for (int e = 0; e < NI.GetOutDeg(); e++) {
369  const int dst = NI.GetOutNId(e);
370  if (! OutGraph.IsNode(dst)) { continue; }
371  OutGraph.AddEdge(NIdV[n], dst);
372  }
373  }
374  } else { // renumber nodes so that node ids are 0...N-1
375  TIntSet NIdSet(InGraph->GetNodes());
376  for (int n = 0; n < NIdV.Len(); n++) {
377  const int NId = NIdSet.AddKey(NIdV[n]);
378  OutGraph.AddNode(NId);
379  }
380  for (int n = 0; n < NIdV.Len(); n++) {
381  typename PInGraph::TObj::TNodeI NI = InGraph->GetNI(NIdV[n]);
382  const int src = NIdSet.GetKey(NIdV[n]);
383  for (int e = 0; e < NI.GetOutDeg(); e++) {
384  const int dst = NIdSet.GetKey(NI.GetOutNId(e));
385  if (! OutGraph.IsNode(dst)) { continue; }
386  OutGraph.AddEdge(src, dst);
387  }
388  }
389  }
390  OutGraph.Defrag();
391  return OutGraphPt;
392  }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
int AddKey(const TKey &Key)
Definition: shash.h:1254

The documentation for this struct was generated from the following file: