let max_gap_of_positional vl =
let cmp u v = match compare_containment u v with
| Some x -> x
| None -> match compare_positional u v with
| Some x -> x
| None -> assert false
in
let vl = List.sort ~cmp vl in
let rec loop ans vl =
match vl with
| [] | _::[] -> ans
| u::v::vl ->
if before u v
then loop (max ans (gap u v)) (v::vl)
else failwith (
sprintf
"ranges %s and %s not positionally comparable"
(to_string u)
(to_string v)
)
in
match vl with
| [] | _::[] -> failwith "given fewer than two ranges"
| u::v::vl -> loop (gap u v) (v::vl)