Skip to content

Instantly share code, notes, and snippets.

@markwatson
Created March 2, 2011 04:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markwatson/850483 to your computer and use it in GitHub Desktop.
Save markwatson/850483 to your computer and use it in GitHub Desktop.
Not finished just saving it here...
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