mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-08 12:15:32 -05:00
more combinators for comparisons
This commit is contained in:
parent
e9e861479c
commit
933638244d
2 changed files with 35 additions and 0 deletions
|
|
@ -43,6 +43,22 @@ let (<?>) c (ord,x,y) =
|
||||||
then ord x y
|
then ord x y
|
||||||
else c
|
else c
|
||||||
|
|
||||||
|
let pair o_x o_y (x1,y1) (x2,y2) =
|
||||||
|
let c = o_x x1 x2 in
|
||||||
|
if c = 0
|
||||||
|
then o_y y1 y2
|
||||||
|
else c
|
||||||
|
|
||||||
|
let triple o_x o_y o_z (x1,y1,z1) (x2,y2,z2) =
|
||||||
|
let c = o_x x1 x2 in
|
||||||
|
if c = 0
|
||||||
|
then
|
||||||
|
let c' = o_y y1 y2 in
|
||||||
|
if c' = 0
|
||||||
|
then o_z z1 z2
|
||||||
|
else c'
|
||||||
|
else c
|
||||||
|
|
||||||
let rec list_ ord l1 l2 = match l1, l2 with
|
let rec list_ ord l1 l2 = match l1, l2 with
|
||||||
| [], [] -> 0
|
| [], [] -> 0
|
||||||
| [], _ -> -1
|
| [], _ -> -1
|
||||||
|
|
@ -53,3 +69,16 @@ let rec list_ ord l1 l2 = match l1, l2 with
|
||||||
then list_ ord l1' l2'
|
then list_ ord l1' l2'
|
||||||
else c
|
else c
|
||||||
|
|
||||||
|
let array_ ord a1 a2 =
|
||||||
|
let rec aux i =
|
||||||
|
if i = Array.length a1
|
||||||
|
then if Array.length a1 = Array.length a2 then 0
|
||||||
|
else -1
|
||||||
|
else if i = Array.length a2
|
||||||
|
then 1
|
||||||
|
else
|
||||||
|
let c = ord a1.(i) a2.(i) in
|
||||||
|
if c = 0
|
||||||
|
then aux (i+1) else c
|
||||||
|
in
|
||||||
|
aux 0
|
||||||
|
|
|
||||||
|
|
@ -50,5 +50,11 @@ val (<?>) : int -> ('a t * 'a * 'a) -> int
|
||||||
<?> (CCBool.compare, true, false)]}
|
<?> (CCBool.compare, true, false)]}
|
||||||
*)
|
*)
|
||||||
|
|
||||||
|
val pair : 'a t -> 'b t -> ('a * 'b) t
|
||||||
|
|
||||||
|
val triple : 'a t -> 'b t -> 'c t -> ('a * 'b * 'c) t
|
||||||
|
|
||||||
val list_ : 'a t -> 'a list t
|
val list_ : 'a t -> 'a list t
|
||||||
(** Lexicographic combination on lists *)
|
(** Lexicographic combination on lists *)
|
||||||
|
|
||||||
|
val array_ : 'a t -> 'a array t
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue