Skip to content

Commit 48da271

Browse files
committed
Lwd_table: stackless compute_sub_size
1 parent 7bc9bb9 commit 48da271

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

lib/lwd/lwd_table.ml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -270,17 +270,22 @@ and balance version = function
270270
else (node.version <- version; node.size <- 1 + sl + sr; self)
271271
)
272272

273-
let rec _compute_sub_size1 version = function
273+
let rec compute_sub_size version = function
274274
| Root _ -> ()
275275
| Leaf -> ()
276276
| Node node as self ->
277-
if node.size = 0 then begin
278-
_compute_sub_size1 version node.left;
279-
_compute_sub_size1 version node.right;
280-
ignore (balance version self)
281-
end
282-
283-
let compute_sub_size = _compute_sub_size1
277+
if node.size = 0 then
278+
match node.left with
279+
| Node {size = 0; _} ->
280+
compute_sub_size version node.left
281+
| _ ->
282+
match node.right with
283+
| Node {size = 0; _} ->
284+
compute_sub_size version node.right
285+
| _ ->
286+
let parent = node.parent in
287+
ignore (balance version self);
288+
compute_sub_size version parent
284289

285290
let rec reset_version version = function
286291
| Leaf -> ()

0 commit comments

Comments
 (0)