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
|
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) =
|
||||||
|
case helpAppend (start, finish, tree) of
|
||||||
|
UPDATE t => t
|
||||||
|
| APPEND newNode =>
|
||||||
let
|
let
|
||||||
val maxSize = getFinishIdx tree
|
val maxSize = getFinishIdx tree
|
||||||
in
|
in
|
||||||
case helpAppend (start, finish, tree) of
|
BRANCH (#[tree, newNode], #[maxSize, finish])
|
||||||
UPDATE t => t
|
|
||||||
| APPEND newNode => BRANCH (#[tree, newNode], #[maxSize, finish])
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
6
shf.mlb
6
shf.mlb
@@ -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
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user