Browse files

Bloom filter: Prepare for having other representations.

  • Loading branch information...
1 parent f978f56 commit 5e69a0ca0476a17cc17b25092684294910bfaede @eriksoe eriksoe committed Sep 25, 2012
Showing with 9 additions and 3 deletions.
  1. +9 −3 src/hanoidb_bloom.erl
View
12 src/hanoidb_bloom.erl
@@ -148,9 +148,12 @@ masked_pair(Mask, X, Y) -> {X band Mask, Y band Mask}.
all_set(_Mask, _I1, _I, []) -> true;
all_set(Mask, I1, I, [H|T]) ->
- case bitarray_get(I, H) of
- true -> all_set(Mask, I1, (I+I1) band Mask, T);
- false -> false
+ case element(1, H) of
+ array ->
+ case bitarray_get(I, H) of
+ true -> all_set(Mask, I1, (I+I1) band Mask, T);
+ false -> false
+ end
end.
%% Adds element to set
@@ -184,6 +187,7 @@ set_bits(_Mask, _I1, _I, [], Acc) -> lists:reverse(Acc);
set_bits(Mask, I1, I, [H|T], Acc) ->
set_bits(Mask, I1, (I+I1) band Mask, T, [bitarray_set(I, H) | Acc]).
+%%%========== Bitarray representation - suitable for sparse arrays ==========
bitarray_new(N) -> array:new((N-1) div ?W + 1, {default, 0}).
bitarray_set(I, A) ->
@@ -197,6 +201,8 @@ bitarray_get(I, A) ->
V = array:get(AI, A),
V band (1 bsl (I rem ?W)) =/= 0.
+%%%^^^^^^^^^^ Bitarray representation - suitable for sparse arrays ^^^^^^^^^^
+
encode(Bloom) ->
zlib:gzip(term_to_binary(Bloom)).

0 comments on commit 5e69a0c

Please sign in to comment.