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::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 199 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 200 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().

200  {
201  CAssert(! HasGraphFlag(typename PGraph::TObj, gfMultiGraph));
202  PGraph NewGraphPt = PGraph::TObj::New();
203  typename PGraph::TObj& NewGraph = *NewGraphPt;
204  NewGraph.Reserve(NIdV.Len(), -1);
205  TIntSet NodeSet;
206  for (int n = 0; n < NIdV.Len(); n++) {
207  if (! HasGraphFlag(typename PGraph::TObj, gfNodeDat)) {
208  if (Graph->IsNode(NIdV[n])) { NewGraph.AddNode(NIdV[n]); NodeSet.AddKey(NIdV[n]); } }
209  else {
210  if (Graph->IsNode(NIdV[n])) { NewGraph.AddNode(Graph->GetNI(NIdV[n])); NodeSet.AddKey(NIdV[n]); } }
211  }
212  for (int n = 0; n < NodeSet.Len(); n++) {
213  const int SrcNId = NodeSet[n];
214  const typename PGraph::TObj::TNodeI NI = Graph->GetNI(SrcNId);
215  for (int edge = 0; edge < NI.GetOutDeg(); edge++) {
216  const int OutNId = NI.GetOutNId(edge);
217  if (NewGraph.IsNode(OutNId)) {
218  if (! HasGraphFlag(typename PGraph::TObj, gfEdgeDat)) {
219  NewGraph.AddEdge(SrcNId, OutNId); }
220  else {
221  NewGraph.AddEdge(Graph->GetEI(SrcNId, OutNId)); } // also copy data
222  }
223  }
224  }
225  NewGraph.Defrag();
226  return NewGraphPt;
227  }
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: