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

Graph reduce #93

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Graph reduce #93

wants to merge 3 commits into from

Conversation

dionyziz
Copy link

This patch introduces the reduce algorithm which performs a dfs but processes the graph using an arbitrary function accumulator. pre-order and post-order are still supported. DFS has been rewritten using the new reduce function.

Fix #62

@lutzroeder
Copy link
Contributor

@arieljake can you help reviewing and testing this change?

@pkakelas
Copy link

LGTM

@dionyziz dionyziz mentioned this pull request Aug 28, 2018
@mstou
Copy link

mstou commented Aug 28, 2018

I did a stress test as we discussed in #94 . It turns out that in both the old and new imlpementations of dfs ( with both 'post' & 'pre' ), a stack overflow is caused at a chain length of around ~2000 nodes(!)

I ran the tests on node v9.2.0.
If you want to replicate the results, the c++ code that generetated the test files is the following:

#include <cstdio>

using namespace std;

const int chainLength = 2000;

int main(){
  printf("var Graph = require('./graphlib').Graph;\n");
  printf("var dfs = require('./graphlib/lib/alg/dfs');\n");
  printf("var g = new Graph();\n");

  for(int i=1; i<=chainLength; i++){
    printf("g.setEdge(%d, %d);\n", i, i+1);
  }

  printf("console.log(%d);\n",chainLength);
  printf("console.log(dfs(g,1,\'post\'))");
}

@dionyziz
Copy link
Author

Nice catch, thanks for running this. This indicates a bug in the old implementation as well, so it's a good chance to fix it. I'll work on this.

@lutzroeder lutzroeder force-pushed the master branch 3 times, most recently from 64a1b87 to cf48a25 Compare February 16, 2019 02:57
@dskdas
Copy link

dskdas commented May 19, 2020

I had a similar need and came across this PR while searching around. This is still being reviewed?

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

Successfully merging this pull request may close these issues.

dfs - pass in node iterator function
5 participants