Commit 9b808ece authored by POTTIER Francois's avatar POTTIER Francois

Added [Misc.levels].

parent b0a8ac1c
......@@ -344,3 +344,22 @@ let rec best (preferable : 'a -> 'a -> bool) (xs : 'a list) : 'a option =
| None ->
(* There is no best element. *)
None
let rec levels1 cmp x1 xs =
match xs with
| [] ->
[x1], []
| x2 :: xs ->
let ys1, yss = levels1 cmp x2 xs in
if cmp x1 x2 = 0 then
x1 :: ys1, yss
else
[x1], ys1 :: yss
let levels cmp xs =
match xs with
| [] ->
[]
| x1 :: xs ->
let ys1, yss = levels1 cmp x1 xs in
ys1 :: yss
......@@ -183,3 +183,9 @@ val new_encode_decode: int -> (string -> int) * (int -> string) * (unit -> unit)
is quadratic. *)
val best: ('a -> 'a -> bool) -> 'a list -> 'a option
(* Assuming that the list [xs] is sorted with respect to the ordering [cmp],
[levels cmp xs] is the list of levels of [xs], where a level is a maximal
run of adjacent equal elements. Every level is a nonempty list. *)
val levels: ('a -> 'a -> int) -> 'a list -> 'a list list
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment