SNAP Library 6.0, Developer Reference  2020-12-09 16:24:20
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
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 397 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 398 of file subgraph.h.

References THashSet< TKey, THashFunc >::AddKey(), and TVec< TVal, TSizeTy >::Len().

398  {
399  POutGraph OutGraphPt = POutGraph::TObj::New();
400  typename POutGraph::TObj& OutGraph = *OutGraphPt;
401  if (! RenumberNodes) {
402  for (int n = 0; n < NIdV.Len(); n++) {
403  OutGraph.AddNode(NIdV[n]); }
404  for (int n = 0; n < NIdV.Len(); n++) {
405  typename PInGraph::TObj::TNodeI NI = InGraph->GetNI(NIdV[n]);
406  for (int e = 0; e < NI.GetOutDeg(); e++) {
407  const int dst = NI.GetOutNId(e);
408  if (! OutGraph.IsNode(dst)) { continue; }
409  OutGraph.AddEdge(NIdV[n], dst);
410  }
411  }
412  } else { // renumber nodes so that node ids are 0...N-1
413  TIntSet NIdSet(InGraph->GetNodes());
414  for (int n = 0; n < NIdV.Len(); n++) {
415  const int NId = NIdSet.AddKey(NIdV[n]);
416  OutGraph.AddNode(NId);
417  }
418  for (int n = 0; n < NIdV.Len(); n++) {
419  typename PInGraph::TObj::TNodeI NI = InGraph->GetNI(NIdV[n]);
420  const int src = NIdSet.GetKey(NIdV[n]);
421  for (int e = 0; e < NI.GetOutDeg(); e++) {
422  const int dst = NIdSet.GetKey(NI.GetOutNId(e));
423  if (! OutGraph.IsNode(dst)) { continue; }
424  OutGraph.AddEdge(src, dst);
425  }
426  }
427  }
428  OutGraph.Defrag();
429  return OutGraphPt;
430  }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
int AddKey(const TKey &Key)
Definition: shash.h:1254

Here is the call graph for this function:


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