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, IsMultiGraph > 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, bool IsMultiGraph>
struct TSnap::TSnapDetail::TConvertSubGraph< POutGraph, PInGraph, IsMultiGraph >

Definition at line 360 of file subgraph.h.

Member Function Documentation

template<class POutGraph, class PInGraph, bool IsMultiGraph>
static POutGraph TSnap::TSnapDetail::TConvertSubGraph< POutGraph, PInGraph, IsMultiGraph >::Do ( const PInGraph &  InGraph,
const TIntV NIdV,
const bool &  RenumberNodes 
)
inlinestatic

Definition at line 361 of file subgraph.h.

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

361  {
362  POutGraph OutGraphPt = POutGraph::TObj::New();
363  typename POutGraph::TObj& OutGraph = *OutGraphPt;
364  if (! RenumberNodes) {
365  for (int n = 0; n < NIdV.Len(); n++) {
366  OutGraph.AddNode(NIdV[n]);
367  }
368  for (typename PInGraph::TObj::TEdgeI EI = InGraph->BegEI(); EI < InGraph->EndEI(); EI++) {
369  if (! OutGraph.IsNode(EI.GetSrcNId()) || ! OutGraph.IsNode(EI.GetDstNId())) { continue; }
370  OutGraph.AddEdge(EI.GetSrcNId(), EI.GetDstNId());
371  if (! HasGraphFlag(typename PInGraph::TObj, gfDirected) && HasGraphFlag(typename POutGraph::TObj, gfDirected)) {
372  OutGraph.AddEdge(EI.GetDstNId(), EI.GetSrcNId());
373  }
374  }
375  } else { // renumber nodes so that node ids are 0...N-1
376  TIntSet NIdSet(InGraph->GetNodes());
377  for (int n = 0; n < NIdV.Len(); n++) {
378  const int NId = NIdSet.AddKey(NIdV[n]);
379  OutGraph.AddNode(NId);
380  }
381  for (typename PInGraph::TObj::TEdgeI EI = InGraph->BegEI(); EI < InGraph->EndEI(); EI++) {
382  const int SrcNId = NIdSet.GetKeyId(EI.GetSrcNId());
383  const int DstNId = NIdSet.GetKeyId(EI.GetDstNId());
384  if (! OutGraph.IsNode(SrcNId) || ! OutGraph.IsNode(DstNId)) { continue; }
385  OutGraph.AddEdge(SrcNId, DstNId);
386  if (! HasGraphFlag(typename PInGraph::TObj, gfDirected) && HasGraphFlag(typename POutGraph::TObj, gfDirected)) {
387  OutGraph.AddEdge(DstNId, SrcNId);
388  }
389  }
390  }
391  OutGraph.Defrag();
392  return OutGraphPt;
393  }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
#define HasGraphFlag(TGraph, Flag)
For quick testing of the properties of the graph/network object (see TGraphFlag). ...
Definition: gbase.h:41
int AddKey(const TKey &Key)
Definition: shash.h:1254
directed graph (TNGraph, TNEGraph), else graph is undirected TUNGraph
Definition: gbase.h:13

Here is the call graph for this function:


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