From 4280f580a25444865f99103a82a504b411aa1169 Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Sat, 17 Jan 2026 22:46:08 +0000 Subject: [PATCH] add function to decrement persistent-vector.sml. (The plan is to split the left and right, and then decrement the right metadata so that the absolute indices match.) --- fcore/persistent-vector.sml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/fcore/persistent-vector.sml b/fcore/persistent-vector.sml index 2808b0d..74f7840 100644 --- a/fcore/persistent-vector.sml +++ b/fcore/persistent-vector.sml @@ -508,6 +508,27 @@ struct end end + fun decrementBy (decBy, tree) = + case tree of + BRANCH (nodes, sizes) => + let + val child = decrementBy (decBy, Vector.sub (nodes, 0)) + val nodes = Vector.update (nodes, 0, child) + val sizes = Vector.map (fn sz => sz - decBy) sizes + in + BRANCH (nodes, sizes) + end + | LEAF (items, sizes) => + let + val items = Vector.map + (fn {start, finish} => + {start = start - decBy, finish = finish - decBy} + ) items + val sizes = Vector.map #finish items + in + LEAF (items, sizes) + end + (* functions only for testing *) fun fromListLoop (lst, acc) = case lst of