snap-stanford / snap

Stanford Network Analysis Platform (SNAP) is a general purpose network analysis and graph mining library.
Other
2.16k stars 795 forks source link

SNAP should support finding the NId(s) with the minimum degree #248

Open smemery opened 7 months ago

smemery commented 7 months ago

SNAP should support finding the NId(s) with the minimum degree. The following is the delta to add support:

--- snap-core/alg.h.old 2023-12-09 22:16:39.458539066 -0700 +++ snap-core/alg.h 2023-12-09 22:32:35.778365319 -0700 @@ -19,10 +19,17 @@ /// Returns a randomly chosen node from all the nodes with the maximum in-degree. template int GetMxInDegNId(const PGraph& Graph); /// Returns a randomly chosen node from all the nodes with the maximum out-degree. template int GetMxOutDegNId(const PGraph& Graph);

+/// Returns a randomly chosen node from all the nodes with the minimum degree. +template int GetMnDegNId(const PGraph& Graph); +/// Returns a randomly chosen node from all the nodes with the minimum in-degree. +template int GetMnInDegNId(const PGraph& Graph); +/// Returns a randomly chosen node from all the nodes with the minimum out-degree. +template int GetMnOutDegNId(const PGraph& Graph); + // degree histograms /// Returns an in-degree histogram: a set of pairs (in-degree, number of nodes of such in-degree) template void GetInDegCnt(const PGraph& Graph, TIntPrV& DegToCntV); /// Returns an in-degree histogram: a set of pairs (in-degree, number of nodes of such in-degree) template void GetInDegCnt(const PGraph& Graph, TFltPrV& DegToCntV); @@ -174,10 +181,46 @@ EAssertR(! MxDegV.Empty(), "Input graph is empty!"); return MxDegV[TInt::Rnd.GetUniDevInt(MxDegV.Len())]; }

template +int GetMnDegNId(const PGraph& Graph) {