persistent-vector.sml was in a partial state where some functions use rope-like metadata and some functions do not, so change 'nextMatch' function to use rope-like metatadata (still need to change other functions)

This commit is contained in:
2026-01-15 05:25:17 +00:00
parent e1077b7780
commit d6da7a3ea3

View File

@@ -131,49 +131,41 @@ struct
BRANCH (#[tree, newNode], #[maxSize, finish]) BRANCH (#[tree, newNode], #[maxSize, finish])
end end
(* todo: modify below functions so that they also
* use rope-like metadata *)
fun getStart tree = fun getStart tree =
case tree of case tree of
LEAF (values, _) => Vector.sub (values, 0) LEAF (values, _) => Vector.sub (values, 0)
| BRANCH (nodes, _) => getStart (Vector.sub (nodes, 0)) | BRANCH (nodes, _) => getStart (Vector.sub (nodes, 0))
fun helpNextMatch (cursorIdx, tree) = fun helpNextMatch (cursorIdx, tree, absOffset) =
case tree of case tree of
LEAF (values, sizes) => LEAF (values, sizes) =>
let let
val idx = BinSearch.equalOrMore (cursorIdx, sizes) val idx = BinSearch.equalOrMore (cursorIdx, sizes)
in in
if idx = ~1 then {start = ~1, finish = ~1} if idx = ~1 then {start = ~1, finish = ~1}
else Vector.sub (values, idx) else
let
val {start, finish} = Vector.sub (values, idx)
in
{start = start + absOffset, finish = finish + absOffset}
end
end end
| BRANCH (nodes, sizes) => | BRANCH (nodes, sizes) =>
let let
val idx = BinSearch.equalOrMore (cursorIdx, sizes) val idx = BinSearch.equalOrMore (cursorIdx, sizes)
in in
if idx = ~1 then {start = ~1, finish = ~1} if idx = ~1 then
else helpNextMatch (cursorIdx, Vector.sub (nodes, idx)) {start = ~1, finish = ~1}
end else if idx = 0 then
helpNextMatch (cursorIdx, Vector.sub (nodes, idx), absOffset)
fun startNextMatch (cursorIdx, tree) = else
case tree of let
LEAF (values, sizes) => val prevSize = Vector.sub (sizes, idx - 1)
if Vector.length sizes = 0 then val cursorIdx = cursorIdx - prevSize
{start = ~1, finish = ~1} val absOffset = absOffset + prevSize
else in
let helpNextMatch (cursorIdx, Vector.sub (nodes, idx), absOffset)
val idx = BinSearch.equalOrMore (cursorIdx, sizes) end
val idx = if idx = ~1 then 0 else idx
in
Vector.sub (values, idx)
end
| BRANCH (nodes, sizes) =>
let
val idx = BinSearch.equalOrMore (cursorIdx, sizes)
in
if idx = ~1 then {start = ~1, finish = ~1}
else helpNextMatch (cursorIdx, Vector.sub (nodes, idx))
end end
fun loopNextMatch (prevStart, prevFinish, tree, count) = fun loopNextMatch (prevStart, prevFinish, tree, count) =
@@ -181,7 +173,7 @@ struct
prevStart prevStart
else else
let let
val {start, finish} = startNextMatch (prevFinish + 1, tree) val {start, finish} = helpNextMatch (prevFinish + 1, tree, 0)
in in
if start = ~1 then if start = ~1 then
let val {start, finish} = getStart tree let val {start, finish} = getStart tree
@@ -196,7 +188,7 @@ struct
~1 ~1
else else
let let
val {start, finish} = startNextMatch (cursorIdx, tree) val {start, finish} = helpNextMatch (cursorIdx, tree, 0)
in in
if start = ~1 then if start = ~1 then
let val {start, finish} = getStart tree let val {start, finish} = getStart tree
@@ -208,6 +200,9 @@ struct
loopNextMatch (start, finish, tree, count - 1) loopNextMatch (start, finish, tree, count - 1)
end end
(* todo: modify below functions so that they also
* use rope-like metadata *)
fun getLast tree = fun getLast tree =
case tree of case tree of
LEAF (values, _) => Vector.sub (values, Vector.length values - 1) LEAF (values, _) => Vector.sub (values, Vector.length values - 1)