Created
March 2, 2011 04:32
-
-
Save markwatson/850483 to your computer and use it in GitHub Desktop.
Not finished just saving it here...
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
class AdjacencyMatrix[T: Manifest](size: Int) { | |
// initialize it | |
// (It's in column vector format) | |
val matrix = Array.ofDim[T](size, size) | |
// helper functions | |
// takes a list of 3-tuples in the form: (from, to, weight) | |
def setConnections(connections: List[(Int, Int, T)]) = { | |
for (x <- connections) { | |
// make matrix[to][from] = weight | |
matrix(x._2)(x._1) = x._3 | |
} | |
} | |
// This function returns a list of (index, weight) of items connected to the current node | |
def getConnected(node: Int) = { | |
matrix(node) // column vector format makes things easy | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment