From 1c6e0df15cf19b8cd7eb03ab76ce5d7afd275a3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20S=C3=B8e=20S=C3=B8rensen?= Date: Tue, 25 Sep 2012 15:17:24 +0200 Subject: [PATCH] Bloom filter: Handle hibernate situation in dense_bitmap. --- src/hanoidb_bloom.erl | 5 ++++- src/hanoidb_dense_bitmap.erl | 8 ++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/hanoidb_bloom.erl b/src/hanoidb_bloom.erl index 154bc9d..8d385d7 100644 --- a/src/hanoidb_bloom.erl +++ b/src/hanoidb_bloom.erl @@ -196,7 +196,10 @@ bitmask_new(LogN) -> bitmask_set(I, BM) -> case element(1,BM) of array -> bitarray_set(I, BM); - dense_bitmap_ets -> hanoidb_dense_bitmap:set(I, BM) + dense_bitmap_ets -> hanoidb_dense_bitmap:set(I, BM); + dense_bitmap -> + %% Surprise - we need to mutate a built representation: + hanoidb_dense_bitmap:set(I, hanoidb_dense_bitmap:unbuild(BM)) end. %%% Convert to external form. diff --git a/src/hanoidb_dense_bitmap.erl b/src/hanoidb_dense_bitmap.erl index 3bf25f4..300ccf8 100644 --- a/src/hanoidb_dense_bitmap.erl +++ b/src/hanoidb_dense_bitmap.erl @@ -1,6 +1,6 @@ -module(hanoidb_dense_bitmap). --export([new/1, set/2, build/1, member/2]). +-export([new/1, set/2, build/1, unbuild/1, member/2]). -define(BITS_PER_CELL, 32). -define(REPR_NAME, dense_bitmap). @@ -10,7 +10,6 @@ new(N) -> Width = 1 + (N-1) div ?BITS_PER_CELL, Value = erlang:make_tuple(Width+1, 0, [{1,?REPR_NAME}]), ets:insert(Tab, Value), - %io:format("DB| create(): ~p of width ~p\n", [Tab, Width]), {dense_bitmap_ets, N, Width, Tab}. %% Set a bit. @@ -27,6 +26,11 @@ build({dense_bitmap_ets, _, _, Tab}) -> ets:delete(Tab), Row. +unbuild(Row) when element(1,Row)==?REPR_NAME -> + Tab = ets:new(dense_bitmap, [private, set]), + ets:insert(Tab, Row), + {dense_bitmap_ets, undefined, undefined, Tab}. + member(I, Row) when element(1,Row)==?REPR_NAME -> Cell = 2 + I div ?BITS_PER_CELL, BitInCell = I rem ?BITS_PER_CELL,