add function to persistent-vector.sml to check if we are in a specific range

This commit is contained in:
2025-09-29 14:29:43 +01:00
parent 13ccdbb202
commit 8ba16daf7a
2 changed files with 34 additions and 8 deletions

View File

@@ -15,6 +15,31 @@ struct
datatype append_result = APPEND of t | UPDATE of t datatype append_result = APPEND of t | UPDATE of t
fun isInRange (checkIdx, t) =
case t of
BRANCH (nodes, sizes) =>
let
val searchIdx = BinSearch.equalOrMore (checkIdx, sizes)
in
if searchIdx = ~1 then
false
else
isInRange (checkIdx, Vector.sub (nodes, searchIdx))
end
| LEAF (values, sizes) =>
let
val searchIdx = BinSearch.equalOrMore (checkIdx, sizes)
in
if searchIdx = ~1 then
false
else
let
val {start, finish} = Vector.sub (values, searchIdx)
in
checkIdx >= start andalso checkIdx <= finish
end
end
fun getFinishIdx t = fun getFinishIdx t =
case t of case t of
BRANCH (_, sizes) => Vector.sub (sizes, Vector.length sizes - 1) BRANCH (_, sizes) => Vector.sub (sizes, Vector.length sizes - 1)
@@ -66,11 +91,12 @@ struct
end end
fun append (start, finish, tree) = fun append (start, finish, tree) =
let
val maxSize = getFinishIdx tree
in
case helpAppend (start, finish, tree) of case helpAppend (start, finish, tree) of
UPDATE t => t UPDATE t => t
| APPEND newNode => BRANCH (#[tree, newNode], #[maxSize, finish]) | APPEND newNode =>
end let
val maxSize = getFinishIdx tree
in
BRANCH (#[tree, newNode], #[maxSize, finish])
end
end end

View File

@@ -11,14 +11,14 @@ message-types/draw-msg.sml
message-types/search-msg.sml message-types/search-msg.sml
message-types/mailbox-type.sml message-types/mailbox-type.sml
fcore/escape-string.sml
fcore/bin-search.sml
ann ann
"allowVectorExps true" "allowVectorExps true"
in in
fcore/persistent-vector.sml fcore/persistent-vector.sml
end end
fcore/escape-string.sml
fcore/bin-search.sml
fcore/search-list/nfa.sml fcore/search-list/nfa.sml
fcore/search-list.sml fcore/search-list.sml