summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordberg.se>2014-06-01 16:04:21 +0200
committerLinus Nordberg <linus@nordberg.se>2014-06-01 16:04:21 +0200
commit959538bec4c7945e6310653ddfaf7a336c81c502 (patch)
treeccfd0fb1d21274aa829499c11fc04a74a39d8ffa /src
parentccb77fd278c077e16d4b08820b4e79ac5852e081 (diff)
Add note about appending trees.
Also remove unused code and clearify append/1.
Diffstat (limited to 'src')
-rw-r--r--src/ht.erl16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/ht.erl b/src/ht.erl
index ff7b52a..c10ae33 100644
--- a/src/ht.erl
+++ b/src/ht.erl
@@ -44,10 +44,10 @@ size(Head) ->
%%
%% Walk down the tree in Head, stop at The Right Place and make Leaf
%% the right sibling of that place. To find the right place, let d be
-%% the depth of the tree, then go down the tree on the right side to
-%% level l, where l is the position of the first set bit in d, looking
-%% at d "from the right". l=0 is where the leafs are and l=d-1 is the
-%% root.
+%% the depth of the tree, then go down the tree on the right hand side
+%% to level l, where l is the position of the first set bit in d,
+%% looking at d from the least significant bit. l=0 is where the leafs
+%% are and l=d-1 is the root.
%%
%% The depth of the tree is found by walking down the right path. It
%% would be better if we inserted the leaf and calculated the nodes on
@@ -58,15 +58,19 @@ size(Head) ->
%% Example: N=4 (100) => l=2, the root (soon not to be root).
%% Example: N=5 (101) => l=0, the rightmost leaf.
%% Example: N=6 (110) => l=1, the last and rightmost inner node.
+%%
+%% NOTE: Adding a tree requires some more work. One thing is that if
+%% the tree to append doesn't fit in right-hand subtree, it has to be
+%% added in smaller pieces.
+%%
-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,
- %Depth = depth(Head),
Level = fls(N),
RBD = rightbranchdepth(Head#head.tree),
- %io:format("N=~p, Depth=~p, Level=~p, RBD=~p~n", [N, Depth, Level, RBD]),
+ %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)};
append(Head, Data) ->
append(Head, mkleaf(Data)).