struct
module T = Biocaml_interval_tree
type 'a t = 'a T.t Map.t
let intersects lmap (k,r) =
Option.value_map (Map.find lmap k) ~default:false ~f:(fun x -> Range.(T.intersects x r.lo r.hi))
let closest lmap (k,r) =
Option.bind
(Map.find lmap k)
Range.(fun x ->
try
let lo,hi,label,d = T.find_closest r.lo r.hi x in
Some ((k, ok_exn (make lo hi)), label, d)
with T.Empty_tree -> None
)
let intersecting_elems lmap (k, { Range.lo ; hi }) =
match Map.find lmap k with
| Some x ->
T.find_intersecting_elem lo hi x
/@ (fun (lo,hi,x) -> (k, ok_exn (Range.make lo hi)), x)
| None -> Stream.empty ()
let to_stream lmap =
(Map.to_stream lmap)
/@ (fun (k,t) -> Stream.map ~f:(fun (lo,hi,x) -> (k, ok_exn (Range.make lo hi)), x) (T.to_stream t))
|> Stream.concat
let of_stream e =
let accu =
Accu.create T.empty (fun x -> fst x |> fst)
(fun ((_,r),v) -> Range.(T.add ~data:v ~low:r.lo ~high:r.hi)) in
Stream.iter ~f:(fun loc -> Accu.add accu loc loc ) e ;
Map.of_stream (Accu.stream accu)
end