Skip to content

Instantly share code, notes, and snippets.

@4lex1v
Created March 14, 2015 19:15
Show Gist options
  • Save 4lex1v/ce5557b9e73c41a7143a to your computer and use it in GitHub Desktop.
Save 4lex1v/ce5557b9e73c41a7143a to your computer and use it in GitHub Desktop.
Compute bloom filter bits for Coursera C3 hm question
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