modify PersistentVector.nextMatch and relevant functions so that they index using the roles of rope-like metadata
This commit is contained in:
@@ -131,29 +131,42 @@ 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, acc) =
|
||||||
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 + acc, finish = finish + acc}
|
||||||
|
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 {start = ~1, finish = ~1}
|
||||||
else helpNextMatch (cursorIdx, Vector.sub (nodes, idx))
|
else
|
||||||
|
let
|
||||||
|
val prevSize =
|
||||||
|
if idx = 0 then
|
||||||
|
0
|
||||||
|
else
|
||||||
|
Vector.sub (sizes, idx - 1)
|
||||||
|
val acc = acc + prevSize
|
||||||
|
val cursorIdx = cursorIdx - prevSize
|
||||||
|
in
|
||||||
|
helpNextMatch (cursorIdx, Vector.sub (nodes, idx), acc)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
fun startNextMatch (cursorIdx, tree) =
|
fun startNextMatch (cursorIdx, tree) =
|
||||||
@@ -173,7 +186,17 @@ struct
|
|||||||
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 helpNextMatch (cursorIdx, Vector.sub (nodes, idx))
|
else
|
||||||
|
let
|
||||||
|
val prevSize =
|
||||||
|
if idx = 0 then
|
||||||
|
0
|
||||||
|
else
|
||||||
|
Vector.sub (sizes, idx - 1)
|
||||||
|
val cursorIdx = cursorIdx - prevSize
|
||||||
|
in
|
||||||
|
helpNextMatch (cursorIdx, Vector.sub (nodes, idx), prevSize)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
fun loopNextMatch (prevStart, prevFinish, tree, count) =
|
fun loopNextMatch (prevStart, prevFinish, tree, count) =
|
||||||
@@ -208,6 +231,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)
|
||||||
|
|||||||
Reference in New Issue
Block a user