Skip to content

Instantly share code, notes, and snippets.

View treadstone90's full-sized avatar

Karthik Anantha Padmanabhan treadstone90

  • Pinterest Inc
  • San Francisco, CA
View GitHub Profile
@treadstone90
treadstone90 / top-down-par.scala
Last active August 29, 2015 14:08
Par Top Down_
trait PTopDownUpdater extends FrontierUpdater {
def update(frontier: Seq[Int], parents: Array[Int]): Seq[Int] = {
val next = ArrayBuffer[Int]()
frontier.par.foreach { node =>
graph.getNeighbors(node).filter(parents(_) == -1).foreach { neighbor =>
next += neighbor
parents(neighbor) = node
}
@treadstone90
treadstone90 / bottom-up-par.scala
Last active August 29, 2015 14:08
Par Bottom up
trait ParallelAncestorManager {
def getAncestor(id: Int): ParSeq[Int]
def getParVertices: ParSeq[Int]
}
trait PBottomUpUpdater extends FrontierUpdater with ParallelAncestorManager {
def update(frontier: Seq[Int], parents: Array[Int]):Seq[Int] = {
val next = BitSet()
val frontierSet = frontier.toSet
@treadstone90
treadstone90 / bottom-up.scala
Created October 23, 2014 20:15
Blog BFS bottom up
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 {
@treadstone90
treadstone90 / top-down.scala
Created October 23, 2014 20:14
Blog BFS top down
class BFS(g: Graph) {
val parent = ArrayBuffer.fill(g.numberVertices)(-1).toArray
def bfs(source: Int, updater: (Seq[Int], Array[Int]) => Seq[Int]) = {
var frontier = Seq(source)
parent(source) = -2
while (!frontier.isEmpty) {
frontier = updater(frontier, parent)