Skip to content

Commit

Permalink
do not create unnecessary subtrees with 1 child
Browse files Browse the repository at this point in the history
  • Loading branch information
Cliff Moon committed May 31, 2010
1 parent 835c17b commit 9bf9e57
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion apps/luwak/src/luwak_tree.erl
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ subtree_update(Riak, File, Order, InsertPos, TreePos, Parent = #n{}, Blocks) ->

list_into_nodes(Riak, Children, Order, StartingPos) ->
?debugFmt("list_into_nodes(Riak, ~p, ~p, ~p)~n", [Children, Order, StartingPos]),
Written = map_sublist(fun(Sublist) ->
Written = map_sublist(fun([{SubNode,Length}]) ->
{SubNode,Length};
(Sublist) ->
Length = luwak_tree_utils:blocklist_length(Sublist),
{ok, Obj} = create_node(Riak, Sublist),
{riak_object:key(Obj), Length}
Expand Down Expand Up @@ -238,3 +240,8 @@ create_node(Riak, Children) ->
Name = skerl:hexhash(?HASH_LEN, term_to_binary(Children)),
Obj = riak_object:new(?N_BUCKET, Name, N),
{Riak:put(Obj, 2), Obj}.


truncate(List) when is_list(List) ->
lists:map(fun({Data,Length}) -> {truncate(Data),Length} end, List);
truncate(Data = <<Prefix:8/binary, _/binary>>) -> Prefix.

0 comments on commit 9bf9e57

Please sign in to comment.