From 328a4e76f1d15d9426e373fad22d85cd7b561748 Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Mon, 1 Dec 2025 13:51:12 +0000 Subject: [PATCH] done implementing 'helpInsert' (both leaf and branch caases)for persistent-vector.sml --- fcore/persistent-vector.sml | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/fcore/persistent-vector.sml b/fcore/persistent-vector.sml index b23c803..4c780b2 100644 --- a/fcore/persistent-vector.sml +++ b/fcore/persistent-vector.sml @@ -425,7 +425,13 @@ struct if finish > Vector.sub (sizes, Vector.length sizes - 1) then if Vector.length sizes = maxSize then (* have to split *) - raise Fail "umimp" + let + val rightItems = #[{start = start, finish = finish}] + val rightSize = #[finish] + val right = LEAF (rightItems, rightSize) + in + INSERT_SPLIT (tree, right) + end else (* can just append *) let @@ -439,7 +445,13 @@ struct (* prepend *) if Vector.length sizes = maxSize then (* have to split *) - raise Fail "umimp" + let + val leftItems = #[{start = start, finish = finish}] + val leftSize = #[finish] + val left = LEAF (leftItems, leftSize) + in + INSERT_SPLIT (left, tree) + end else (* just prepend *) let @@ -461,16 +473,27 @@ struct val leftItems = VectorSlice.slice (items, 0, leftLen) val rightItems = VectorSlice.slice (items, idx, rightLen) + val midSize = VectorSlice.full #[finish] + val midItem = VectorSlice.full #[{start = start, finish = finish}] in if Vector.length items = maxSize then (* have to return split *) - raise Fail "umimp" + let + val leftSizes = VectorSlice.concat [leftSizes, midSize] + val rightSizes = VectorSlice.vector rightSizes + + val leftItems = VectorSlice.concat [leftItems, midItem] + val rightItems = VectorSlice.vector rightItems + + val left = LEAF (leftItems, leftSizes) + val right = LEAF (rightItems, rightSizes) + in + INSERT_SPLIT (left, right) + end else (* have to return update *) let - val midSize = VectorSlice.full #[finish] val sizes = VectorSlice.concat [leftSizes, midSize, rightSizes] - val midItem = VectorSlice.full #[{start = start, finish = finish}] val items = VectorSlice.concat [leftItems, midItem, rightItems] in INSERT_UPDATE (LEAF (items, sizes))