Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saturated bloomfilter size #666

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ See [Algebird's page on the Scaladex](https://index.scala-lang.org/twitter/algeb
- [Scio](https://github.com/spotify/scio)
- [Packetloop](https://www.packetloop.com) (see [this tweet](https://twitter.com/cloudjunky/status/355073917720858626))
- Ebay uses Algebird for machine learning: [ScalaDays talk](http://www.slideshare.net/VitalyGordon/scalable-and-flexible-machine-learning-with-scala-linkedin)
- [Apple (FEAR Team)](https://news.ycombinator.com/item?id=16969118)

Other projects built with Algebird, as compiled by the Scaladex: [![Scaladex Dependents](https://index.scala-lang.org/count.svg?q=dependencies:twitter/algebird*&subject=scaladex:&color=blue&style=flat-square)](https://index.scala-lang.org/search?q=dependencies:twitter/algebird-core)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,16 @@ object BloomFilter {
* This is \hat{S}^{-1}(t) in the cardinality estimation paper used above.
*/
def sInverse(t: Int): Double =
scala.math.log1p(-t.toDouble / width) / (numHashes * scala.math.log1p(-1.0 / width))
if (numBits == width) 0.0
else
scala.math.log(1 - t.toDouble / width) / (numHashes * scala.math.log1p(-1.0 / width))

// Variable names correspond to those used in the paper.
val t = numBits
val n = sInverse(t).round.toInt
// Take the min and max because the probability formula assumes
// nl <= sInverse(t - 1) and sInverse(t + 1) <= nr

val nl =
scala.math.min(sInverse(t - 1).floor, (1 - approximationWidth) * n).toInt
val nr =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,6 @@ class BloomFilterTest extends WordSpec with Matchers {
val items = (1 until exactCardinality).map { _.toString }
val bf = bfMonoid.create(items: _*)
val size = bf.size

assert(size ~ exactCardinality)
assert(size.min <= size.estimate)
assert(size.max >= size.estimate)
Expand Down Expand Up @@ -410,6 +409,16 @@ class BloomFilterTest extends WordSpec with Matchers {
}
}

"BloomFilter method `size`" should {

"return the appropriate size when it's saturated " in {
val bfMonoid = BloomFilterMonoid[String](5, 13)
val strings = List(8, 9, 8, 10, 1, 8, 11, 12, 13, 14, 15, 67, 18981, 1122, 86787).map(_.toString)
val bf = bfMonoid.create(strings: _*)
assert(bf.size.isZero)
}
}

"BloomFilter method `checkAndAdd`" should {

"be identical to method `+`" in {
Expand Down