Created
March 14, 2015 19:15
-
-
Save 4lex1v/ce5557b9e73c41a7143a to your computer and use it in GitHub Desktop.
Compute bloom filter bits for Coursera C3 hm question
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def compute(nums: Int*) = { | |
def h(idx: Int)(num: Int): Int = (((math.pow(num, 2) + math.pow(num, 3)) * idx) % 32).toInt | |
val fs: List[Int => Int] = List(h(1), h(2), h(3)) | |
val result = nums.map { n => | |
val bits = fs.map(_(n)).sorted | |
println(s"$n -> ${bits.mkString(",")}") | |
(n -> bits) | |
} | |
println(s"Result: ${result.map(_._2).flatten.sorted.distinct.mkString(",")}") | |
result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment