add function to persistent-vector.sml to check if we are in a specific range
This commit is contained in:
@@ -15,6 +15,31 @@ struct
|
||||
|
||||
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 =
|
||||
case t of
|
||||
BRANCH (_, sizes) => Vector.sub (sizes, Vector.length sizes - 1)
|
||||
@@ -66,11 +91,12 @@ struct
|
||||
end
|
||||
|
||||
fun append (start, finish, tree) =
|
||||
case helpAppend (start, finish, tree) of
|
||||
UPDATE t => t
|
||||
| APPEND newNode =>
|
||||
let
|
||||
val maxSize = getFinishIdx tree
|
||||
in
|
||||
case helpAppend (start, finish, tree) of
|
||||
UPDATE t => t
|
||||
| APPEND newNode => BRANCH (#[tree, newNode], #[maxSize, finish])
|
||||
BRANCH (#[tree, newNode], #[maxSize, finish])
|
||||
end
|
||||
end
|
||||
|
||||
6
shf.mlb
6
shf.mlb
@@ -11,14 +11,14 @@ message-types/draw-msg.sml
|
||||
message-types/search-msg.sml
|
||||
message-types/mailbox-type.sml
|
||||
|
||||
fcore/escape-string.sml
|
||||
fcore/bin-search.sml
|
||||
|
||||
ann
|
||||
"allowVectorExps true"
|
||||
in
|
||||
fcore/persistent-vector.sml
|
||||
end
|
||||
|
||||
fcore/escape-string.sml
|
||||
fcore/bin-search.sml
|
||||
fcore/search-list/nfa.sml
|
||||
fcore/search-list.sml
|
||||
|
||||
|
||||
Reference in New Issue
Block a user