From 5b4c903d53a46e2ed859dbefa329347f5ba6a3cc Mon Sep 17 00:00:00 2001 From: martinsumner Date: Mon, 2 Jan 2017 20:02:49 +0000 Subject: [PATCH] Check before update on bloom --- src/leveled_sst.erl | 2 +- src/leveled_tinybloom.erl | 21 +++++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/leveled_sst.erl b/src/leveled_sst.erl index f7903f7..addabe5 100644 --- a/src/leveled_sst.erl +++ b/src/leveled_sst.erl @@ -72,7 +72,7 @@ -define(SLOT_SIZE, 128). % This is not configurable -define(COMPRESSION_LEVEL, 1). -define(BINARY_SETTINGS, [{compressed, ?COMPRESSION_LEVEL}]). --define(LEVEL_BLOOM_BITS, [{0, 12}, {1, 10}, {2, 8}, {default, 6}]). +-define(LEVEL_BLOOM_BITS, [{0, 8}, {1, 10}, {2, 8}, {default, 6}]). -define(MERGE_SCANWIDTH, 16). -define(DISCARD_EXT, ".discarded"). -define(DELETE_TIMEOUT, 10000). diff --git a/src/leveled_tinybloom.erl b/src/leveled_tinybloom.erl index 73982e5..9d85b9a 100644 --- a/src/leveled_tinybloom.erl +++ b/src/leveled_tinybloom.erl @@ -51,6 +51,7 @@ enter(Key, Bloom) -> Hash = leveled_codec:magic_hash(Key), enter({hash, Hash}, Bloom). + check({hash, Hash}, Bloom) -> {Slot0, Q, Bit1, Bit2, Bit3} = split_hash(Hash), Slot = Slot0 rem dict:size(Bloom), @@ -83,16 +84,23 @@ check(Key, Bloom) -> %%%============================================================================ split_hash(Hash) -> + Slot = split_for_slot(Hash), + {Q1, H1, H2, H3} = split_for_bits(Hash), + {Slot, Q1, H1, H2, H3}. + +split_for_slot(Hash) -> SlotH1 = Hash band 255, SlotH2 = (Hash bsr 8) band 255, SlotH3 = (Hash bsr 16) band 255, SlotH4 = (Hash bsr 24) band 255, - Slot = (SlotH1 bxor SlotH2) bxor (SlotH3 bxor SlotH4), + (SlotH1 bxor SlotH2) bxor (SlotH3 bxor SlotH4). + +split_for_bits(Hash) -> Q1 = Hash band 3, H1 = (Hash bsr 2) band 1023, H2 = (Hash bsr 12) band 1023, H3 = (Hash bsr 22) band 1023, - {Slot, Q1, H1, H2, H3}. + {Q1, H1, H2, H3}. split_array(Bin, Q) -> case Q of @@ -113,9 +121,14 @@ split_array(Bin, Q) -> add_to_array(Bit, BitArray, ArrayLength) -> RestLen = ArrayLength - Bit - 1, <> = BitArray, - <>. + case B of + 0 -> + <>; + 1 -> + BitArray + end. getbit(Bit, BitArray, ArrayLength) -> RestLen = ArrayLength - Bit - 1,