Created
October 23, 2014 20:15
-
-
Save treadstone90/5ee73a21a23a99b7a523 to your computer and use it in GitHub Desktop.
Blog BFS bottom up
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait DirectedSerialAncestorManager extends SerialAncestorManager{ | |
var _graph: SerialDirectedGraph = _ | |
def getAncestor(id: Int): IndexedSeq[Int] = { | |
_graph.getParents(id) | |
} | |
def getVertices: IndexedSeq[Int] = (0 to _graph.numberVertices - 1) | |
} | |
trait SBottomUpUpdater extends FrontierUpdater with SerialAncestorManager { | |
def update(frontier: BitSet, parents: Array[Int]): Seq[Int] = { | |
val next = mutable.BitSet() | |
val vertices = getVertices | |
val frontierSet = frontier.toSet | |
(vertices.filter(parents(_) == -1)).foreach { node => | |
val neighbors = (getAncestor(node)) | |
neighbors.find(frontierSet) match { | |
case Some(ancestor) => { | |
parents(node) = ancestor | |
next(node) = true | |
} | |
case None => None | |
} | |
} | |
next.toBuffer | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment