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::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 335 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 336 of file subgraph.h.

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

336  {
337  POutGraph OutGraphPt = POutGraph::TObj::New();
338  typename POutGraph::TObj& OutGraph = *OutGraphPt;
339  if (! RenumberNodes) {
340  for (int n = 0; n < NIdV.Len(); n++) {
341  OutGraph.AddNode(NIdV[n]);
342  }
343  for (typename PInGraph::TObj::TEdgeI EI = InGraph->BegEI(); EI < InGraph->EndEI(); EI++) {
344  if (! OutGraph.IsNode(EI.GetSrcNId()) || ! OutGraph.IsNode(EI.GetDstNId())) { continue; }
345  OutGraph.AddEdge(EI.GetSrcNId(), EI.GetDstNId());
346  if (! HasGraphFlag(typename PInGraph::TObj, gfDirected) && HasGraphFlag(typename POutGraph::TObj, gfDirected)) {
347  OutGraph.AddEdge(EI.GetDstNId(), EI.GetSrcNId());
348  }
349  }
350  } else { // renumber nodes so that node ids are 0...N-1
351  TIntSet NIdSet(InGraph->GetNodes());
352  for (int n = 0; n < NIdV.Len(); n++) {
353  const int NId = NIdSet.AddKey(NIdV[n]);
354  OutGraph.AddNode(NId);
355  }
356  for (typename PInGraph::TObj::TEdgeI EI = InGraph->BegEI(); EI < InGraph->EndEI(); EI++) {
357  const int SrcNId = NIdSet.GetKeyId(EI.GetSrcNId());
358  const int DstNId = NIdSet.GetKeyId(EI.GetDstNId());
359  if (! OutGraph.IsNode(SrcNId) || ! OutGraph.IsNode(DstNId)) { continue; }
360  OutGraph.AddEdge(SrcNId, DstNId);
361  if (! HasGraphFlag(typename PInGraph::TObj, gfDirected) && HasGraphFlag(typename POutGraph::TObj, gfDirected)) {
362  OutGraph.AddEdge(DstNId, SrcNId);
363  }
364  }
365  }
366  OutGraph.Defrag();
367  return OutGraphPt;
368  }
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: