WIP: still sorting out some bugs I've introduced (just for fun).
This commit is contained in:
parent
c9d8ffa8ea
commit
9eabb78d06
6 changed files with 32 additions and 11 deletions
18
src/gb_trees_ext.erl
Normal file
18
src/gb_trees_ext.erl
Normal file
|
@ -0,0 +1,18 @@
|
|||
|
||||
-module(gb_trees_ext).
|
||||
-extends(gb_trees).
|
||||
-export([fold/3]).
|
||||
|
||||
% author: http://erlang.2086793.n4.nabble.com/gb-trees-fold-td2228614.html
|
||||
|
||||
-spec fold(fun((term(), term(), term()) -> term()), term(), gb_tree()) -> term().
|
||||
fold(F, A, {_, T})
|
||||
when is_function(F, 3) ->
|
||||
fold_1(F, A, T).
|
||||
|
||||
fold_1(F, Acc0, {Key, Value, Small, Big}) ->
|
||||
Acc1 = fold_1(F, Acc0, Small),
|
||||
Acc = F(Key, Value, Acc1),
|
||||
fold_1(F, Acc, Big);
|
||||
fold_1(_, Acc, _) ->
|
||||
Acc.
|
|
@ -433,7 +433,7 @@ start_app() ->
|
|||
case application:start(?MODULE) of
|
||||
ok ->
|
||||
ok;
|
||||
{error, {already_started, ?MODULE}} ->
|
||||
{error, {already_started, _}} ->
|
||||
ok;
|
||||
{error, Reason} ->
|
||||
{error, Reason}
|
||||
|
|
|
@ -832,7 +832,7 @@ start_range_fold(FileName, WorkerPID, Range, State) ->
|
|||
SelfOrRef :: pid() | reference(),
|
||||
Range :: #key_range{} ) -> ok.
|
||||
do_range_fold(BT, WorkerPID, SelfOrRef, Range) ->
|
||||
try case hanoidb_reader:range_fold(fun(Key, Value, _) ->
|
||||
try case hanoidb_reader:range_fold(fun(Key, Value, 0) ->
|
||||
WorkerPID ! {level_result, SelfOrRef, Key, Value},
|
||||
{?FOLD_CHUNK_SIZE-1, []};
|
||||
(Key, Value, {N, KVs}) ->
|
||||
|
|
|
@ -202,10 +202,10 @@ finish(#nursery{ dir=Dir, cache=Cache, log_file=LogFile,
|
|||
[{size,?BTREE_SIZE(?TOP_LEVEL)},
|
||||
{compress, none} | Config]),
|
||||
try
|
||||
lists:foreach(fun({Key, Value}) ->
|
||||
ok = hanoidb_writer:add(BT, Key, Value)
|
||||
end,
|
||||
gb_trees:to_list(Cache))
|
||||
gb_trees_ext:fold(fun(Key, Value, Acc) ->
|
||||
ok = hanoidb_writer:add(BT, Key, Value),
|
||||
Acc
|
||||
end, [], Cache)
|
||||
after
|
||||
ok = hanoidb_writer:close(BT)
|
||||
end,
|
||||
|
@ -250,9 +250,8 @@ add(Key, Value, Expiry, Nursery, Top) ->
|
|||
case do_add(Nursery, Key, Value, Expiry, Top) of
|
||||
{ok, Nursery0} ->
|
||||
{ok, Nursery0};
|
||||
{full, Nursery} ->
|
||||
io:format("flush~n"),
|
||||
flush(Nursery, Top)
|
||||
{full, Nursery1} ->
|
||||
flush(Nursery1, Top)
|
||||
end.
|
||||
|
||||
flush(Nursery=#nursery{ dir=Dir, max_level=MaxLevel, config=Config }, Top) ->
|
||||
|
|
|
@ -81,7 +81,7 @@ open(Name, Config) ->
|
|||
{ok, <<BloomSize:32/unsigned>>} = file:pread(File, FileInfo#file_info.size-12, 4),
|
||||
{ok, BloomData} = file:pread(File, FileInfo#file_info.size-12-BloomSize ,BloomSize),
|
||||
|
||||
{ok, Bloom} = binary_to_term(zlib:unzip(BloomData)),
|
||||
{ok, Bloom} = binary_to_term(BloomData),
|
||||
|
||||
%% suck in the root
|
||||
{ok, Root} = read_node(File, RootPos),
|
||||
|
|
|
@ -69,7 +69,7 @@
|
|||
|
||||
open(Name, Options) -> %% TODO: should this be called start_link?
|
||||
hanoidb_util:ensure_expiry(Options),
|
||||
gen_server:start_link({local, ?MODULE}, ?MODULE, [Name, Options], []).
|
||||
gen_server:start_link(?MODULE, ?MODULE, [Name, Options], []).
|
||||
|
||||
add(Ref, Key, Value) ->
|
||||
gen_server:cast(Ref, {add, Key, Value}).
|
||||
|
@ -172,7 +172,11 @@ do_open(Name, Options, OpenOpts) ->
|
|||
%% @doc flush pending nodes and write trailer
|
||||
flush_nodes(#state{ nodes=[], last_node_pos=LastNodePos, last_node_size=_LastNodeSize, bloom=Bloom }=State) ->
|
||||
|
||||
<<<<<<< Updated upstream
|
||||
BloomBin = zlib:zip(term_to_binary(Bloom)),
|
||||
=======
|
||||
BloomBin = term_to_binary(Bloom, [compressed]),
|
||||
>>>>>>> Stashed changes
|
||||
BloomSize = byte_size(BloomBin),
|
||||
|
||||
IdxFile = State#state.index_file,
|
||||
|
|
Loading…
Reference in a new issue