Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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