Skip to content

Commit

Permalink
Merge pull request #355 from mweiden/bloomfilter-exception
Browse files Browse the repository at this point in the history
BloomFilter should warn or raise on unrealistic input.
  • Loading branch information
ianoc committed Oct 22, 2014
2 parents e12d97f + 547b7ee commit 5b34a8b
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,16 @@ object BloomFilter {
def optimalNumHashes(numEntries: Int, width: Int): Int = math.ceil(width / numEntries * math.log(2)).toInt

// Compute optimal width: m = - n ln(p) / (ln(2))^2
def optimalWidth(numEntries: Int, fpProb: Double): Int = math.ceil(-1 * numEntries * math.log(fpProb) / math.log(2) / math.log(2)).toInt
def optimalWidth(numEntries: Int, fpProb: Double): Int = {
val widthEstimate = math.ceil(-1 * numEntries * math.log(fpProb) / math.log(2) / math.log(2)).toInt

if (widthEstimate == Int.MaxValue) {
throw new java.lang.IllegalArgumentException(
"BloomFilter cannot guarantee the specified false positive probability for the number of entries!")
}

return widthEstimate
}
}

/**
Expand Down

0 comments on commit 5b34a8b

Please sign in to comment.