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