グラフの保存にneo4jを使用してSCCアルゴリズムを実装しようとしています。
これが私のDFSの実装です:
void dfs(GraphDatabaseService g, Node node, long counter) {
Transaction tx = g.beginTx();
node.setProperty("explored", true);
tx.success();
tx.finish();
System.out.println("Exporing node " + node.getProperty("name") + "with depth " + counter);
Iterator<Relationship> it = node.getRelationships(Direction.OUTGOING, RelTypes.KNOWS).iterator();
while (it.hasNext()) {
Node end = it.next().getEndNode();
if (!(boolean) end.getProperty("explored"))
dfs(g, end, ++counter);
}
}
StackOverflowError をスローします。明らかな理由は、再帰の深さが大きくなりすぎていることです。しかし、私のコードに何か問題があるのでしょうか?