diff options
-rw-r--r-- | src/ht.erl | 10 |
1 files changed, 6 insertions, 4 deletions
@@ -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. |