Skip to content
This repository has been archived by the owner on Nov 9, 2022. It is now read-only.

Commit

Permalink
fix the calculation of the plain bloomfilter's capacity
Browse files Browse the repository at this point in the history
  • Loading branch information
gmcabrita committed Jul 13, 2018
1 parent 62bf7f3 commit 06c6d25
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/bloomex.ex
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ defmodule Bloomex do

mb =
case mode do
:size -> 1 + trunc(-log2(1 - :math.pow(1 - p, 1 / e)))
:size -> 1 + trunc(-log2(1 - :math.pow(1 - p, 1 / capacity)))
:bits -> capacity
end

Expand Down
8 changes: 4 additions & 4 deletions test/bloomex_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ defmodule BloomexTest do
bloom = Bloomex.plain(50, 0.10)
assert Bloomex.member?(bloom, 5) == false

assert Bloomex.capacity(bloom) == 1
assert Bloomex.capacity(bloom) == 52
assert Bloomex.size(bloom) == 0

bloom = Bloomex.add(bloom, 2) |> Bloomex.add(3) |> Bloomex.add(2) |> Bloomex.add(10)
assert Bloomex.member?(bloom, 1) == true
assert Bloomex.member?(bloom, 10) == true
end

test "plain add" do
Expand All @@ -31,14 +31,14 @@ defmodule BloomexTest do
bloom = Bloomex.scalable(6000, 0.001, 0.001, 3)

bloom = Enum.reduce(1..10000, bloom, fn x, acc -> Bloomex.add(acc, x) end)
assert Bloomex.size(bloom) == 7025
assert Bloomex.size(bloom) == 9998
end

test "scalable force mb to be bigger than 16" do
bloom = Bloomex.scalable(100, 0.1, 0.1, 3)

bloom = Enum.reduce(1..90000, bloom, fn x, acc -> Bloomex.add(acc, x) end)
assert Bloomex.member?(bloom, 1) == true
assert Bloomex.size(bloom) == 61993
assert Bloomex.size(bloom) == 80253
end
end

0 comments on commit 06c6d25

Please sign in to comment.