add additional test for 'dn' motion after finding bug, fixed bug (rewrote high-level delete fundtion in persistent-vector.sml to address it), and begin adding tests for 'dN' motion

This commit is contained in:
2026-03-28 00:45:08 +00:00
parent 3f6eaa730a
commit 9d46ec9f34
4 changed files with 118 additions and 67 deletions

View File

@@ -483,7 +483,7 @@ struct
else
if splitIdx > Vector.sub (sizes, Vector.length sizes - 1) then
empty
else if splitIdx < Vector.sub (sizes, 0) then
else if splitIdx < #start (Vector.sub (items, 0)) then
tree
else
let
@@ -743,13 +743,6 @@ struct
let
val finish = start + length
val matchBeforeStart = prevMatch (start, tree, 1)
val matchBeforeStart =
if matchBeforeStart >= start then
~1
else
matchBeforeStart
val matchAfterFinish = nextMatch (finish, tree, 1)
val matchAfterFinish =
if matchAfterFinish < finish then
@@ -757,63 +750,47 @@ struct
else
matchAfterFinish
in
if matchBeforeStart = ~1 andalso matchAfterFinish = ~1 then
empty
else if matchAfterFinish = ~1 then
(* there is no match after 'finish', so just split left.
* No need to decrement or split right,
* because the right vector would be empty. *)
splitLeft (start, tree)
else if matchBeforeStart = ~1 then
(* We don't want to use left split
* because there are no elements
* before the deletion range's 'start'.
* So we make a right split and then decrement it. *)
let
val right = splitRight (finish, tree)
in
if isEmpty right then
empty
else
let
val startIdx = getStartIdx right
val shouldBeStartIdx = matchAfterFinish - length
val difference = startIdx - shouldBeStartIdx
in
if difference = 0 then
right
else if isEmpty right then
empty
else
decrementBy (difference, right)
end
end
else
let
val left = splitLeft (start, tree)
val right = splitRight (finish, tree)
in
if isEmpty right then
left
else
let
val leftSize = getFinishIdx left
val rightStartRelative = getStartIdx right
val rightStartAbsolute = leftSize + rightStartRelative
let
val left = splitLeft (start, tree)
val right = splitRight (finish, tree)
in
if isEmpty left andalso isEmpty right then
empty
else if isEmpty left then
(* just decrement right and return it *)
let
val rightStart = getStartIdx right
val shouldBeStartIdx = matchAfterFinish - length
val difference = rightStart - shouldBeStartIdx
in
if difference = 0 then
right
else
decrementBy (difference, right)
end
else if isEmpty right then
(* return left half without doing anything *)
left
else
(* decrement right, and then merge both together *)
let
val leftSize = getFinishIdx left
val rightStartRelative = getStartIdx right
val rightStartAbsolute = leftSize + rightStartRelative
val shouldBeStartIdx = matchAfterFinish - length
val difference = rightStartAbsolute - shouldBeStartIdx
in
if difference = 0 then
val shouldBeStartIdx = matchAfterFinish - length
val difference = rightStartAbsolute - shouldBeStartIdx
in
if difference = 0 then
merge (left, right)
else
let
val right = decrementBy (difference, right)
in
merge (left, right)
else
let
val right = decrementBy (difference, right)
in
merge (left, right)
end
end
end
end
end
end
end
(* Usually, when inserting, we want the absolute metadata