template<class POutGraph, class PInGraph, bool IsMultiGraph>
struct TSnap::TSnapDetail::TConvertSubGraph< POutGraph, PInGraph, IsMultiGraph >
Definition at line 335 of file subgraph.h.
template<class POutGraph, class PInGraph, bool IsMultiGraph>
Definition at line 336 of file subgraph.h.
References THashSet< TKey, THashFunc >::AddKey(), gfDirected, HasGraphFlag, and TVec< TVal, TSizeTy >::Len().
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]);
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());
347 OutGraph.AddEdge(EI.GetDstNId(), EI.GetSrcNId());
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);
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);
362 OutGraph.AddEdge(DstNId, SrcNId);
TSizeTy Len() const
Returns the number of elements in the vector.
#define HasGraphFlag(TGraph, Flag)
For quick testing of the properties of the graph/network object (see TGraphFlag). ...
int AddKey(const TKey &Key)
directed graph (TNGraph, TNEGraph), else graph is undirected TUNGraph