SNAP Library 4.1, Developer Reference  2018-07-26 16:30:42
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 174 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 175 of file subgraph.h.

References THashSet< TKey, THashFunc >::AddKey(), CAssert, THashSet< TKey, THashFunc >::Defrag(), edge, gfEdgeDat, gfMultiGraph, gfNodeDat, HasGraphFlag, TVec< TVal, TSizeTy >::Len(), and THashSet< TKey, THashFunc >::Len().

175  {
176  CAssert(! HasGraphFlag(typename PGraph::TObj, gfMultiGraph));
177  PGraph NewGraphPt = PGraph::TObj::New();
178  typename PGraph::TObj& NewGraph = *NewGraphPt;
179  NewGraph.Reserve(NIdV.Len(), -1);
180  TIntSet NodeSet;
181  for (int n = 0; n < NIdV.Len(); n++) {
182  if (! HasGraphFlag(typename PGraph::TObj, gfNodeDat)) {
183  if (Graph->IsNode(NIdV[n])) { NewGraph.AddNode(NIdV[n]); NodeSet.AddKey(NIdV[n]); } }
184  else {
185  if (Graph->IsNode(NIdV[n])) { NewGraph.AddNode(Graph->GetNI(NIdV[n])); NodeSet.AddKey(NIdV[n]); } }
186  }
187  for (int n = 0; n < NodeSet.Len(); n++) {
188  const int SrcNId = NodeSet[n];
189  const typename PGraph::TObj::TNodeI NI = Graph->GetNI(SrcNId);
190  for (int edge = 0; edge < NI.GetOutDeg(); edge++) {
191  const int OutNId = NI.GetOutNId(edge);
192  if (NewGraph.IsNode(OutNId)) {
193  if (! HasGraphFlag(typename PGraph::TObj, gfEdgeDat)) {
194  NewGraph.AddEdge(SrcNId, OutNId); }
195  else {
196  NewGraph.AddEdge(Graph->GetEI(SrcNId, OutNId)); } // also copy data
197  }
198  }
199  }
200  NewGraph.Defrag();
201  return NewGraphPt;
202  }
void Defrag()
Definition: shash.h:1366
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
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

Here is the call graph for this function:


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