I was wondering how (if possible) I can make the adjacency list view of a (mutable) graph through HashMap[Int, Vector[Int]]. HashMapwill change of course.
I am currently set up as HashMap[Int, ArrayBuffer[Int]], but the fact that I can change every cell in the ArrayBuffer makes me uncomfortable, although I'm sure I don't. I would use it ListBuffer[Int], but I would like to get quick random access to my neighbors because of my need to do quick random walks on graphs. A Vector[Int]will solve this problem, but do it anyway?
As far as I know (tried this in REPL), this will not work:
scala> val x = new mutable.HashMap[Int, Vector[Int]]
x: scala.collection.mutable.HashMap[Int,Vector[Int]] = Map()
scala> x(3) = Vector(1)
scala> x(3) += 4
I need to be able to simultaneously add it at any time, as well as arbitrarily access any element inside it (subject to the index). Is it possible?
Thank! -kstruct
source
share