From 2556f97239f436a46e6590344370064ed69c0893 Mon Sep 17 00:00:00 2001 From: Linus Nordberg Date: Sun, 1 Jun 2014 17:03:28 +0200 Subject: Clean upp append/2, append/3 a bit. --- src/ht.erl | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'src/ht.erl') diff --git a/src/ht.erl b/src/ht.erl index 0badb19..8e801b9 100644 --- a/src/ht.erl +++ b/src/ht.erl @@ -66,22 +66,21 @@ size(Head) -> -spec append(head(), leaf() | iolist() | binary()) -> head(). append(#head{version = 0}, Leaf) when is_record(Leaf, leaf) -> mkhead(1, Leaf); -append(Head, Leaf) when is_record(Leaf, leaf) -> - N = Head#head.version, +append(#head{version = N, tree = Tree}, Leaf) when is_record(Leaf, leaf) -> Level = fls(N), - RBD = rightbranchdepth(Head#head.tree), + RBD = rightbranchdepth(Tree), %io:format("N=~p, Level=~p, RBD=~p~n", [N, Level, RBD]), - #head{version = N + 1, tree = append(Head#head.tree, Leaf, RBD-Level-1)}; + #head{version = N + 1, tree = append_at(Tree, Leaf, RBD-Level-1)}; append(Head, Data) -> append(Head, mkleaf(Data)). --spec append(tree(), tree(), pos_integer()) -> tree(). -append(Dest, Newtree, _) when is_record(Dest, leaf) -> +-spec append_at(tree(), tree(), pos_integer()) -> tree(). +append_at(Dest, Newtree, _) when is_record(Dest, leaf) -> mkinner(Dest, Newtree); -append(Dest, Newtree, 0) when is_record(Dest, inner) -> +append_at(Dest, Newtree, 0) when is_record(Dest, inner) -> mkinner(Dest, Newtree); -append(Dest, Newtree, Depth) when is_record(Dest, inner) -> - mkinner(Dest#inner.child0, append(Dest#inner.child1, Newtree, Depth - 1)). +append_at(Dest, Newtree, Depth) when is_record(Dest, inner) -> + mkinner(Dest#inner.child0, append_at(Dest#inner.child1, Newtree, Depth - 1)). %% @doc Return an audit path. %% -- cgit v1.1