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