Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Bloom filter: make "don't set if already set" logic more fine-grained. #18

Merged
merged 1 commit into from

2 participants

@eriksoe

This results in a minor "bloom add" performance gain of ~10%.

@eriksoe eriksoe Bloom filter: make "don't set if already set" logic more fine-grained.
This results in a minor "bloom add" performance gain of ~10%.
e1fddd6
@krestenkrab krestenkrab merged commit e3689c3 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 27, 2012
  1. @eriksoe

    Bloom filter: make "don't set if already set" logic more fine-grained.

    eriksoe authored
    This results in a minor "bloom add" performance gain of ~10%.
This page is out of date. Refresh to see the latest.
Showing with 10 additions and 10 deletions.
  1. +5 −9 src/hanoidb_bloom.erl
  2. +5 −1 src/hanoidb_dense_bitmap.erl
View
14 src/hanoidb_bloom.erl
@@ -148,10 +148,7 @@ 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 bitmask_get(I, H) of
- true -> all_set(Mask, I1, (I+I1) band Mask, T);
- false -> false
- end.
+ bitmask_get(I, H) andalso all_set(Mask, I1, (I+I1) band Mask, T).
%% Adds element to set
%%
@@ -175,10 +172,7 @@ add(Elem, #sbf{size=Size, r=R, s=S, b=[H|T]=Bs}=Sbf) ->
hash_add(Hashes, #bloom{mb=Mb, a=A, size=Size} = B) ->
Mask = 1 bsl Mb -1,
{I1, I0} = make_indexes(Mask, Hashes),
- case all_set(Mask, I1, I0, A) of
- true -> B;
- false -> B#bloom{size=Size+1, a=set_bits(Mask, I1, I0, A, [])}
- end.
+ B#bloom{size=Size+1, a=set_bits(Mask, I1, I0, A, [])}.
set_bits(_Mask, _I1, _I, [], Acc) -> lists:reverse(Acc);
set_bits(Mask, I1, I, [H|T], Acc) ->
@@ -226,7 +220,9 @@ bitarray_set(I, A) ->
AI = I div ?W,
V = array:get(AI, A),
V1 = V bor (1 bsl (I rem ?W)),
- array:set(AI, V1, A).
+ if V =:= V1 -> A; % The bit is already set
+ true -> array:set(AI, V1, A)
+ end.
bitarray_get(I, A) ->
AI = I div ?W,
View
6 src/hanoidb_dense_bitmap.erl
@@ -18,7 +18,11 @@ set(I, {dense_bitmap_ets, _,_, Tab}=DBM) ->
BitInCell = I rem ?BITS_PER_CELL,
Old = ets:lookup_element(Tab, ?REPR_NAME, Cell),
New = Old bor (1 bsl BitInCell),
- ets:update_element(Tab, ?REPR_NAME, {Cell,New}),
+ if New =:= Old ->
+ ok; % The bit is already set
+ true ->
+ ets:update_element(Tab, ?REPR_NAME, {Cell,New})
+ end,
DBM.
build({dense_bitmap_ets, _, _, Tab}) ->
Something went wrong with that request. Please try again.