Hello,
I am trying to learn how to use Seq.of_dispenser and my function is this.
let get_containing_data nodes point =
(* TODO Check if 'point' it is out of bounds *)
let mid = point in
let en_d = Int.sub (Int.of_float( log2 (Int.to_float (2 lsl (CCVector.length nodes))))) 1 in
Seq.of_dispenser (fun _ ->
let rec loop_while mid =
if Int.(<) mid en_d then
try
let n = CCVector.get nodes mid in
let popped =
if CCVector.exists (fun ((start : int), _) -> Int.(<=) start point) n.by_start then
CCVector.pop n.by_start
else if CCVector.exists (fun (en_d, _) -> Int.(<=) point en_d ) n.by_start then
CCVector.pop n.by_start
else None in
(match popped with
| Some (_,id) -> Some id
| None ->
let mid = (mid lor (Int.add mid 1)) land lnot (2 lsl (trailing_ones (Int64.of_int mid))) in
loop_while mid
)
with Invalid_argument _mid-> Printf.printf "Invalid_Argument"; None
else None
in loop_while mid
)
node is
type node = {
by_start : (int * int) Node_vector.vector;
by_end : (int * int) Node_vector.vector
}
type interval_tree = {
nodes : node Interval_vector.vector;
}
The type of my function is shown as (node, `a) Internal_Vector.t -> int -> int -> BatSeq.node
I believe I am returning an int. What does BatSeq.node mean here ? I couldn’t print the int Seq.node type.
What are the usecases for of_dispenser ? Here I am using it to search for a value in a data structure(range) repeatedly.
Thanks.