Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
smemery opened this issue Dec 10, 2023 · 0 comments
Open

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

smemery opened this issue Dec 10, 2023 · 0 comments

Comments

@smemery
Copy link

smemery commented Dec 10, 2023

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) {

  • TIntV MnDegV;
  • int MnDeg=INT_MAX;
  • for (typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
  • if (MnDeg > NI.GetDeg()) { MnDegV.Clr(); MnDeg = NI.GetDeg(); }
  • if (MnDeg == NI.GetDeg()) { MnDegV.Add(NI.GetId()); }
  • }
  • EAssertR(! MnDegV.Empty(), "Input graph is empty!");
  • return MnDegV[TInt::Rnd.GetUniDevInt(MnDegV.Len())];
    +}

+template
+int GetMnInDegNId(const PGraph& Graph) {

  • TIntV MnDegV;
  • int MnDeg=INT_MAX;
  • for (typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
  • if (MnDeg > NI.GetInDeg()) { MnDegV.Clr(); MnDeg = NI.GetInDeg(); }
  • if (MnDeg == NI.GetInDeg()) { MnDegV.Add(NI.GetId()); }
  • }
  • EAssertR(! MnDegV.Empty(), "Input graph is empty!");
  • return MnDegV[TInt::Rnd.GetUniDevInt(MnDegV.Len())];
    +}

+template
+int GetMnOutDegNId(const PGraph& Graph) {

  • TIntV MnDegV;
  • int MnDeg=INT_MAX;
  • for (typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
  • if (MnDeg > NI.GetOutDeg()) { MnDegV.Clr(); MnDeg = NI.GetOutDeg(); }
  • if (MnDeg == NI.GetOutDeg()) { MnDegV.Add(NI.GetId()); }
  • }
  • EAssertR(! MnDegV.Empty(), "Input graph is empty!");
  • return MnDegV[TInt::Rnd.GetUniDevInt(MnDegV.Len())];
    +}

+template
void GetInDegCnt(const PGraph& Graph, TIntPrV& DegToCntV) {
TIntH DegToCntH;
for (typename PGraph::TObj::TNodeI NI = Graph->BegNI(); NI < Graph->EndNI(); NI++) {
DegToCntH.AddDat(NI.GetInDeg())++; }
DegToCntV.Gen(DegToCntH.Len(), 0);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant