From 959538bec4c7945e6310653ddfaf7a336c81c502 Mon Sep 17 00:00:00 2001 From: Linus Nordberg Date: Sun, 1 Jun 2014 16:04:21 +0200 Subject: Add note about appending trees. Also remove unused code and clearify append/1. --- src/ht.erl | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src') 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)). -- cgit v1.1