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::TGetSubGraph< PGraph, false > Struct Template Reference

#include <subgraph.h>

Static Public Member Functions

static PGraph Do (const PGraph &Graph, const TIntV &NIdV)
 

Detailed Description

template<class PGraph>
struct TSnap::TSnapDetail::TGetSubGraph< PGraph, false >

Definition at line 167 of file subgraph.h.

Member Function Documentation

template<class PGraph >
static PGraph TSnap::TSnapDetail::TGetSubGraph< PGraph, false >::Do ( const PGraph &  Graph,
const TIntV NIdV 
)
inlinestatic

Definition at line 168 of file subgraph.h.

168  {
169  CAssert(! HasGraphFlag(typename PGraph::TObj, gfMultiGraph));
170  PGraph NewGraphPt = PGraph::TObj::New();
171  typename PGraph::TObj& NewGraph = *NewGraphPt;
172  NewGraph.Reserve(NIdV.Len(), -1);
173  TIntSet NodeSet;
174  for (int n = 0; n < NIdV.Len(); n++) {
175  if (! HasGraphFlag(typename PGraph::TObj, gfNodeDat)) {
176  if (Graph->IsNode(NIdV[n])) { NewGraph.AddNode(NIdV[n]); NodeSet.AddKey(NIdV[n]); } }
177  else {
178  if (Graph->IsNode(NIdV[n])) { NewGraph.AddNode(Graph->GetNI(NIdV[n])); NodeSet.AddKey(NIdV[n]); } }
179  }
180  for (int n = 0; n < NodeSet.Len(); n++) {
181  const int SrcNId = NodeSet[n];
182  const typename PGraph::TObj::TNodeI NI = Graph->GetNI(SrcNId);
183  for (int edge = 0; edge < NI.GetOutDeg(); edge++) {
184  const int OutNId = NI.GetOutNId(edge);
185  if (NewGraph.IsNode(OutNId)) {
186  if (! HasGraphFlag(typename PGraph::TObj, gfEdgeDat)) {
187  NewGraph.AddEdge(SrcNId, OutNId); }
188  else {
189  NewGraph.AddEdge(Graph->GetEI(SrcNId, OutNId)); } // also copy data
190  }
191  }
192  }
193  NewGraph.Defrag();
194  return NewGraphPt;
195  }
void Defrag()
Definition: shash.h:1366
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
have explicit edges (multigraph): TNEGraph, TNodeEdgeNet
Definition: gbase.h:14
#define HasGraphFlag(TGraph, Flag)
For quick testing of the properties of the graph/network object (see TGraphFlag). ...
Definition: gbase.h:41
network with data on edges
Definition: gbase.h:16
int AddKey(const TKey &Key)
Definition: shash.h:1254
#define CAssert(Cond)
Definition: bd.h:302
int Len() const
Definition: shash.h:1121
network with data on nodes
Definition: gbase.h:15

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