Advertisement
Guest User

Untitled

a guest
Apr 4th, 2015
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.75 KB | None | 0 0
  1.     val seenVertices = mutable.HashMap[Int, Int]()
  2.  
  3.     var bitMasks = for (i <- 0 to 24; j <- 0 to 24) yield (1 << i | 1 << j)
  4.     bitMasks = 0 +: bitMasks
  5.  
  6.     val bufferedSource = Source.fromFile("/home/asznajder/Coursera/clustering_big.txt")
  7.     val lines = bufferedSource.getLines()
  8.  
  9.     val uf = UnionFind(lines.next().split(" ")(0).toInt)
  10.     for ((line, id) <- lines.zipWithIndex) {
  11.       val code = Integer.parseInt(line.replaceAll(" ", ""), 2)
  12.       for (mask <- bitMasks) {
  13.         val modifiedCode = code ^ mask
  14.         seenVertices.get(modifiedCode) match {
  15.           case Some(seen_id) => uf.union(id, seen_id)
  16.           case None => {
  17.             seenVertices(code) = id
  18.           }
  19.         }
  20.       }
  21.     }
  22.     bufferedSource.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement