diff options
author | Linus Nordberg <linus@nordberg.se> | 2014-06-01 17:03:28 +0200 |
---|---|---|
committer | Linus Nordberg <linus@nordberg.se> | 2014-06-01 17:03:28 +0200 |
commit | 2556f97239f436a46e6590344370064ed69c0893 (patch) | |
tree | 804b94e58b4dfc2b698d094c576f00cfd60119ab /src/ht.erl | |
parent | 0e7d9350d5468305193fc5772c98112b1521a13b (diff) |
Clean upp append/2, append/3 a bit.
Diffstat (limited to 'src/ht.erl')
-rw-r--r-- | src/ht.erl | 17 |
1 files changed, 8 insertions, 9 deletions
@@ -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. %% |