SNAP Library 4.0, Developer Reference  2017-07-27 13:18:06
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 322 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 323 of file subgraph.h.

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

323  {
324  POutGraph OutGraphPt = POutGraph::TObj::New();
325  typename POutGraph::TObj& OutGraph = *OutGraphPt;
326  if (! RenumberNodes) {
327  for (int n = 0; n < NIdV.Len(); n++) {
328  OutGraph.AddNode(NIdV[n]);
329  }
330  for (typename PInGraph::TObj::TEdgeI EI = InGraph->BegEI(); EI < InGraph->EndEI(); EI++) {
331  if (! OutGraph.IsNode(EI.GetSrcNId()) || ! OutGraph.IsNode(EI.GetDstNId())) { continue; }
332  OutGraph.AddEdge(EI.GetSrcNId(), EI.GetDstNId());
333  if (! HasGraphFlag(typename PInGraph::TObj, gfDirected) && HasGraphFlag(typename POutGraph::TObj, gfDirected)) {
334  OutGraph.AddEdge(EI.GetDstNId(), EI.GetSrcNId());
335  }
336  }
337  } else { // renumber nodes so that node ids are 0...N-1
338  TIntSet NIdSet(InGraph->GetNodes());
339  for (int n = 0; n < NIdV.Len(); n++) {
340  const int NId = NIdSet.AddKey(NIdV[n]);
341  OutGraph.AddNode(NId);
342  }
343  for (typename PInGraph::TObj::TEdgeI EI = InGraph->BegEI(); EI < InGraph->EndEI(); EI++) {
344  const int SrcNId = NIdSet.GetKeyId(EI.GetSrcNId());
345  const int DstNId = NIdSet.GetKeyId(EI.GetDstNId());
346  if (! OutGraph.IsNode(SrcNId) || ! OutGraph.IsNode(DstNId)) { continue; }
347  OutGraph.AddEdge(SrcNId, DstNId);
348  if (! HasGraphFlag(typename PInGraph::TObj, gfDirected) && HasGraphFlag(typename POutGraph::TObj, gfDirected)) {
349  OutGraph.AddEdge(DstNId, SrcNId);
350  }
351  }
352  }
353  OutGraph.Defrag();
354  return OutGraphPt;
355  }
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: