Don't guard against overly large key spaces for now.
This commit is contained in:
parent
a50e8bdb0d
commit
f8cd7ed5c1
1 changed files with 7 additions and 6 deletions
|
@ -63,13 +63,14 @@ is_element(Key, B, [Idx | T]) ->
|
|||
|
||||
%% @doc Adds the key to the filter.
|
||||
-spec add_element(term(), #bloom{}) -> #bloom{}.
|
||||
add_element(Key, #bloom{keys=Keys, n=N, bitmap=Bitmap}=B)
|
||||
when Keys < N ->
|
||||
add_element(Key, #bloom{keys=Keys, bitmap=Bitmap}=B) -> % TODO: when Keys < N
|
||||
Idxs = calc_idxs(Key, B),
|
||||
Bitmap0 = set_bits(Bitmap, Idxs),
|
||||
case Bitmap0 == Bitmap of
|
||||
true -> B#bloom{bitmap=Bitmap0}; % Don't increment key count for duplicates.
|
||||
false -> B#bloom{bitmap=Bitmap0, keys=Keys + 1}
|
||||
NewBitmap = set_bits(Bitmap, Idxs),
|
||||
case NewBitmap == Bitmap of
|
||||
true ->
|
||||
B#bloom{bitmap=NewBitmap};
|
||||
false ->
|
||||
B#bloom{bitmap=NewBitmap, keys=Keys + 1}
|
||||
end.
|
||||
|
||||
%% @internal
|
||||
|
|
Loading…
Reference in a new issue