Add a leq function for each primitive types

This function allows these modules to be passed to CCHeap.Make
This commit is contained in:
juloo 2018-05-29 15:12:21 +02:00
parent 8060980266
commit 6ca94be4bd
16 changed files with 46 additions and 2 deletions

View file

@ -7,6 +7,8 @@ let equal (a:bool) b = Pervasives.(=) a b
let compare (a:bool) b = Pervasives.compare a b
let leq (a:bool) b = Pervasives.(<=) a b
let negate = not
type 'a printer = Format.formatter -> 'a -> unit

View file

@ -8,6 +8,10 @@ type t = bool
val compare : t -> t -> int
(** Total ordering on booleans, similar to {!Pervasives.compare}. *)
val leq : t -> t -> bool
(** Equivalent of [(<=)]
Allows to be passed to {!Heap.Make} *)
val equal : t -> t -> bool
val negate : t -> t

View file

@ -8,6 +8,8 @@ include Char
let equal (a:char) b = Pervasives.(=) a b
let leq (a:char) b = Pervasives.(<=) a b
let pp_buf = Buffer.add_char
let pp = Format.pp_print_char

View file

@ -15,6 +15,10 @@ val compare : t -> t -> int
allows the module [Char] to be passed as argument to the functors
{!Set.Make} and {!Map.Make}. *)
val leq : t -> t -> bool
(** Equivalent of [(<=)]
Allows to be passed to {!Heap.Make} *)
val lowercase_ascii : t -> t
(** Convert the given character to its equivalent lowercase character,
using the US-ASCII character set.

View file

@ -76,6 +76,7 @@ let equal (a:float) b = a=b
let hash : t -> int = Hashtbl.hash
let compare (a:float) b = Pervasives.compare a b
let leq (a:float) b = Pervasives.(<=) a b
type 'a printer = Format.formatter -> 'a -> unit
type 'a random_gen = Random.State.t -> 'a

View file

@ -55,6 +55,10 @@ val equal : t -> t -> bool
val compare : t -> t -> int
val leq : t -> t -> bool
(** Equivalent of [(<=)]
Allows to be passed to {!Heap.Make} *)
type 'a printer = Format.formatter -> 'a -> unit
type 'a random_gen = Random.State.t -> 'a

View file

@ -7,6 +7,8 @@ let equal (a:int) b = Pervasives.(=) a b
let compare a b = compare a b
let leq (a:int) b = Pervasives.(<=) a b
let hash i = i land max_int
let range i j yield =

View file

@ -11,6 +11,10 @@ val compare : t -> t -> int
val equal : t -> t -> bool
(** Equality function for integers. *)
val leq : t -> t -> bool
(** Equivalent of [(<=)]
Allows to be passed to {!Heap.Make} *)
val hash : t -> int
val sign : t -> int

View file

@ -2,7 +2,8 @@
include Int32
let equal (x:t) y = Pervasives.(=) x y
let equal (x:int32) y = Pervasives.(=) x y
let leq (a:int32) b = Pervasives.(<=) a b
module Infix = struct
let (+) = add

View file

@ -94,6 +94,10 @@ val equal : t -> t -> bool
(** The equal function for 32-bit integers.
Like {!Pervasives.(=) x y)}. *)
val leq : t -> t -> bool
(** Equivalent of [(<=)]
Allows to be passed to {!Heap.Make} *)
val hash : t -> int
(** Like {!Pervasives.abs (to_int x)}. *)

View file

@ -2,7 +2,8 @@
include Int64
let equal (x:t) y = Pervasives.(=) x y
let equal (x:int64) y = Pervasives.(=) x y
let leq (a:int64) b = Pervasives.(<=) a b
module Infix = struct
let (+) = add

View file

@ -100,6 +100,10 @@ val compare : t -> t -> int
allows the module [CCInt64] to be passed as argument to the functors
{!Set.Make} and {!Map.Make}. *)
val leq : t -> t -> bool
(** Equivalent of [(<=)]
Allows to be passed to {!Heap.Make} *)
val hash : t -> int
(** Like {!Pervasives.abs (to_int x)}. *)

View file

@ -66,6 +66,8 @@ let equal (a:string) b = Pervasives.(=) a b
let compare_int (a : int) b = Pervasives.compare a b
let compare = String.compare
let leq (a:string) b = String.compare a b <= 0
let hash s = Hashtbl.hash s
let length = String.length

View file

@ -64,6 +64,10 @@ val equal : string -> string -> bool
val compare : string -> string -> int
val leq : t -> t -> bool
(** Equivalent of [(<=)]
Allows to be passed to {!Heap.Make} *)
val is_empty : string -> bool
(** [is_empty s] returns [true] iff [s] is empty (i.e. its length is 0).
@since 1.5 *)

View file

@ -10,6 +10,7 @@ type 'a gen = unit -> 'a option
type 'a sequence = ('a -> unit) -> unit
let equal (a:string) b = Pervasives.(=) a b
let leq (a:string) b = String.compare a b <= 0
let hash : string -> int = Hashtbl.hash
let pp = Format.pp_print_string

View file

@ -29,6 +29,10 @@ val hash : t -> int
val compare : t -> t -> int
val leq : t -> t -> bool
(** Equivalent of [(<=)]
Allows to be passed to {!Heap.Make} *)
val pp : Format.formatter -> t -> unit
val to_string : t -> string