Skip to content

Commit

Permalink
Optimize edge traversal in PeerCalculator
Browse files Browse the repository at this point in the history
We have to make sure that we just traverse edges that we have not
already seen. So we need to check for already visited edges.

Signed-off-by: David Soria Parra <dsp@php.net>
  • Loading branch information
dsp committed Mar 19, 2010
1 parent e5a4db5 commit 0211aaa
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/edu/kit/ipd/sonar/server/PeerCalculator.scala
Expand Up @@ -101,12 +101,14 @@ class PeerCalculator extends Calculator {
var list: List[Node] = List()
def recur(cur: Node, limit: Int) {
cur.getEdges
.withFilter(_.isOutgoingEdge(cur))
.foreach((e: Edge) => {
list = e.getDestinationNode :: list
if (limit > 0)
recur(e.getDestinationNode, limit - 1)
})
.withFilter(_.isOutgoingEdge(cur))
.foreach((e: Edge) => {
if (!list.contains(e.getDestinationNode)) {
list = e.getDestinationNode :: list
if (limit > 0)
recur(e.getDestinationNode, limit - 1)
}
})
}

val node = (n: Node) => graph.getNodeById(n.getId)
Expand Down

0 comments on commit 0211aaa

Please sign in to comment.