Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- val seenVertices = mutable.HashMap[Int, Int]()
- var bitMasks = for (i <- 0 to 24; j <- 0 to 24) yield (1 << i | 1 << j)
- bitMasks = 0 +: bitMasks
- val bufferedSource = Source.fromFile("/home/asznajder/Coursera/clustering_big.txt")
- val lines = bufferedSource.getLines()
- val uf = UnionFind(lines.next().split(" ")(0).toInt)
- for ((line, id) <- lines.zipWithIndex) {
- val code = Integer.parseInt(line.replaceAll(" ", ""), 2)
- for (mask <- bitMasks) {
- val modifiedCode = code ^ mask
- seenVertices.get(modifiedCode) match {
- case Some(seen_id) => uf.union(id, seen_id)
- case None => {
- seenVertices(code) = id
- }
- }
- }
- }
- bufferedSource.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement