summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ht.erl10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/ht.erl b/src/ht.erl
index 93a765e..7915e78 100644
--- a/src/ht.erl
+++ b/src/ht.erl
@@ -129,17 +129,19 @@ consistency(Tree, V1, V2) ->
%% @doc Return a list of hashes showing the path from leaf Index to
%% the tree head in the tree of version Version.
-spec path(tree(), non_neg_integer(), non_neg_integer()) -> {tree(), list()}.
-path(Tree, _Index, -1) ->
- {Tree, []};
path(Tree, Index, Version) ->
path(Tree, 0, Index, Version).
-spec path(tree(), non_neg_integer(), non_neg_integer(), non_neg_integer()) ->
{tree(), list()}.
+path(Tree, _Layer, _Index, -1) ->
+ {Tree, []};
+path(Tree = #tree{version = V}, _, _, Version) when Version > V ->
+ {Tree, []}; % FIXME: Return an error?
path(Tree, Layer, Index, Version) ->
%% The magic here is to tell path/6 to stop at Version >> Layer.
- {Tree, path(update(Tree, Version), Layer, Index,
- Version bsr Layer, Version, [])}.
+ UpdTree = update(Tree, Version),
+ {UpdTree, path(UpdTree, Layer, Index, Version bsr Layer, Version, [])}.
%% @doc Return path from {Layer,I} to head of tree Version. I is the
%% leftmost and ILast the rightmost node to consider, at Layer.