template<class POutGraph, class PInGraph, bool IsMultiGraph>
struct TSnap::TSnapDetail::TConvertSubGraph< POutGraph, PInGraph, IsMultiGraph >
Definition at line 360 of file subgraph.h.
template<class POutGraph, class PInGraph, bool IsMultiGraph>
Definition at line 361 of file subgraph.h.
References THashSet< TKey, THashFunc >::AddKey(), gfDirected, HasGraphFlag, and TVec< TVal, TSizeTy >::Len().
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]);
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());
372 OutGraph.AddEdge(EI.GetDstNId(), EI.GetSrcNId());
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);
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);
387 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