SNAP Library 2.0, Developer Reference  2013-05-13 16:33:57
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
TSnap::TSnapDetail::TConvertSubGraph< POutGraph, PInGraph, false > Struct Template Reference

#include <subgraph.h>

List of all members.

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 353 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 
) [inline, static]

Definition at line 354 of file subgraph.h.

References THashSet< TKey, THashFunc >::AddKey(), 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 (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;
  }

Here is the call graph for this function:


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