More timing - and changes slot width
This commit is contained in:
parent
b37f3acb1e
commit
60bddbc874
2 changed files with 34 additions and 15 deletions
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
-include("include/leveled.hrl").
|
-include("include/leveled.hrl").
|
||||||
|
|
||||||
-define(SLOT_SIZE, 128).
|
-define(SLOT_SIZE, 256).
|
||||||
-define(COMPRESSION_LEVEL, 1).
|
-define(COMPRESSION_LEVEL, 1).
|
||||||
|
|
||||||
-include_lib("eunit/include/eunit.hrl").
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
|
@ -110,8 +110,8 @@ generate_randomkeys(Seqn, Count, Acc, BucketLow, BRange) ->
|
||||||
|
|
||||||
|
|
||||||
simple_slotbin_test() ->
|
simple_slotbin_test() ->
|
||||||
KVList0 = generate_randomkeys(1, 256, 1, 4),
|
KVList0 = generate_randomkeys(1, ?SLOT_SIZE * 2, 1, 4),
|
||||||
KVList1 = lists:sublist(lists:ukeysort(1, KVList0), 1, 128),
|
KVList1 = lists:sublist(lists:ukeysort(1, KVList0), 1, ?SLOT_SIZE),
|
||||||
ExtractHashFun =
|
ExtractHashFun =
|
||||||
fun({K, V}) ->
|
fun({K, V}) ->
|
||||||
{_SQN, H} = leveled_codec:strip_to_seqnhashonly({K, V}),
|
{_SQN, H} = leveled_codec:strip_to_seqnhashonly({K, V}),
|
||||||
|
|
|
@ -73,18 +73,35 @@ check(Key, Bloom) ->
|
||||||
check({hash, Hash}, Bloom).
|
check({hash, Hash}, Bloom).
|
||||||
|
|
||||||
tiny_empty() ->
|
tiny_empty() ->
|
||||||
<<0:1024>>.
|
<<0:2048>>.
|
||||||
|
|
||||||
tiny_enter({hash, no_lookup}, Bloom) ->
|
tiny_enter({hash, no_lookup}, Bloom) ->
|
||||||
Bloom;
|
Bloom;
|
||||||
tiny_enter({hash, Hash}, Bloom) ->
|
tiny_enter({hash, Hash}, Bloom) ->
|
||||||
{Bit0, Bit1, Bit2} = split_hash_for_tinybloom(Hash),
|
{Half, Bit0, Bit1, Bit2} = split_hash_for_tinybloom(Hash),
|
||||||
FoldFun =
|
AddFun = fun(Bit, Arr0) -> add_to_array(Bit, Arr0, 1024) end,
|
||||||
fun(K, Arr) -> add_to_array(K, Arr, 1024) end,
|
case Half of
|
||||||
lists:foldl(FoldFun, Bloom, lists:usort([Bit0, Bit1, Bit2])).
|
0 ->
|
||||||
|
<<Bin1:1024/bitstring, Bin2:1024/bitstring>> = Bloom,
|
||||||
|
NewBin = lists:foldl(AddFun, Bin1, [Bit0, Bit1, Bit2]),
|
||||||
|
<<NewBin/bitstring, Bin2/bitstring>>;
|
||||||
|
1 ->
|
||||||
|
<<Bin1:1024/bitstring, Bin2:1024/bitstring>> = Bloom,
|
||||||
|
NewBin = lists:foldl(AddFun, Bin2, [Bit0, Bit1, Bit2]),
|
||||||
|
<<Bin1/bitstring, NewBin/bitstring>>
|
||||||
|
end.
|
||||||
|
|
||||||
tiny_check({hash, Hash}, Bloom) ->
|
tiny_check({hash, Hash}, FullBloom) ->
|
||||||
{Bit0, Bit1, Bit2} = split_hash_for_tinybloom(Hash),
|
{Half, Bit0, Bit1, Bit2} = split_hash_for_tinybloom(Hash),
|
||||||
|
Bloom =
|
||||||
|
case Half of
|
||||||
|
0 ->
|
||||||
|
<<Bin1:1024/bitstring, _Bin2:1024/bitstring>> = FullBloom,
|
||||||
|
Bin1;
|
||||||
|
1 ->
|
||||||
|
<<_Bin1:1024/bitstring, Bin2:1024/bitstring>> = FullBloom,
|
||||||
|
Bin2
|
||||||
|
end,
|
||||||
case getbit(Bit0, Bloom, 1024) of
|
case getbit(Bit0, Bloom, 1024) of
|
||||||
<<0:1>> ->
|
<<0:1>> ->
|
||||||
false;
|
false;
|
||||||
|
@ -114,10 +131,12 @@ split_hash(Hash) ->
|
||||||
{H0, H1, H2}.
|
{H0, H1, H2}.
|
||||||
|
|
||||||
split_hash_for_tinybloom(Hash) ->
|
split_hash_for_tinybloom(Hash) ->
|
||||||
H0 = Hash band 1023,
|
% Tiny bloom can make k=3 from one hash
|
||||||
H1 = (Hash bsr 10) band 1023,
|
Half = Hash band 1,
|
||||||
H2 = (Hash bsr 20) band 1023,
|
H0 = (Hash bsr 1) band 1023,
|
||||||
{H0, H1, H2}.
|
H1 = (Hash bsr 11) band 1023,
|
||||||
|
H2 = (Hash bsr 21) band 1023,
|
||||||
|
{Half, H0, H1, H2}.
|
||||||
|
|
||||||
add_to_array(Bit, BitArray, ArrayLength) ->
|
add_to_array(Bit, BitArray, ArrayLength) ->
|
||||||
RestLen = ArrayLength - Bit - 1,
|
RestLen = ArrayLength - Bit - 1,
|
||||||
|
@ -193,7 +212,7 @@ simple_test() ->
|
||||||
?assertMatch(true, FP < (N div 4)).
|
?assertMatch(true, FP < (N div 4)).
|
||||||
|
|
||||||
tiny_test() ->
|
tiny_test() ->
|
||||||
N = 128,
|
N = 256,
|
||||||
K = 32, % more checks out then in K * checks
|
K = 32, % more checks out then in K * checks
|
||||||
KLin = lists:map(fun(X) -> "Key_" ++
|
KLin = lists:map(fun(X) -> "Key_" ++
|
||||||
integer_to_list(X) ++
|
integer_to_list(X) ++
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue