diff --git a/src/core/CCBool.ml b/src/core/CCBool.ml index 89a6a9e5..6478f5ee 100644 --- a/src/core/CCBool.ml +++ b/src/core/CCBool.ml @@ -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 diff --git a/src/core/CCBool.mli b/src/core/CCBool.mli index 3ba02bb2..002f7f1e 100644 --- a/src/core/CCBool.mli +++ b/src/core/CCBool.mli @@ -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 diff --git a/src/core/CCChar.ml b/src/core/CCChar.ml index 42036003..7e03c870 100644 --- a/src/core/CCChar.ml +++ b/src/core/CCChar.ml @@ -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 diff --git a/src/core/CCChar.mli b/src/core/CCChar.mli index 974e9096..c735188b 100644 --- a/src/core/CCChar.mli +++ b/src/core/CCChar.mli @@ -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. diff --git a/src/core/CCFloat.ml b/src/core/CCFloat.ml index 6edd5feb..fc70b703 100644 --- a/src/core/CCFloat.ml +++ b/src/core/CCFloat.ml @@ -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 diff --git a/src/core/CCFloat.mli b/src/core/CCFloat.mli index a4778766..fdad62f9 100644 --- a/src/core/CCFloat.mli +++ b/src/core/CCFloat.mli @@ -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 diff --git a/src/core/CCInt.ml b/src/core/CCInt.ml index f260c719..56bc6e20 100644 --- a/src/core/CCInt.ml +++ b/src/core/CCInt.ml @@ -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 = diff --git a/src/core/CCInt.mli b/src/core/CCInt.mli index 48ef8ac4..86725ded 100644 --- a/src/core/CCInt.mli +++ b/src/core/CCInt.mli @@ -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 diff --git a/src/core/CCInt32.ml b/src/core/CCInt32.ml index 74aaab63..6dc27a1b 100644 --- a/src/core/CCInt32.ml +++ b/src/core/CCInt32.ml @@ -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 diff --git a/src/core/CCInt32.mli b/src/core/CCInt32.mli index 33a0cfab..dc687dd0 100644 --- a/src/core/CCInt32.mli +++ b/src/core/CCInt32.mli @@ -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)}. *) diff --git a/src/core/CCInt64.ml b/src/core/CCInt64.ml index bfaed6f9..ec1470e9 100644 --- a/src/core/CCInt64.ml +++ b/src/core/CCInt64.ml @@ -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 diff --git a/src/core/CCInt64.mli b/src/core/CCInt64.mli index 6d6b7214..cee073d2 100644 --- a/src/core/CCInt64.mli +++ b/src/core/CCInt64.mli @@ -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)}. *) diff --git a/src/core/CCString.ml b/src/core/CCString.ml index c127e097..b11c9bbb 100644 --- a/src/core/CCString.ml +++ b/src/core/CCString.ml @@ -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 diff --git a/src/core/CCString.mli b/src/core/CCString.mli index eb4734f2..af821595 100644 --- a/src/core/CCString.mli +++ b/src/core/CCString.mli @@ -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 *) diff --git a/src/core/CCUtf8_string.ml b/src/core/CCUtf8_string.ml index 60ccf1b5..ad6e6044 100644 --- a/src/core/CCUtf8_string.ml +++ b/src/core/CCUtf8_string.ml @@ -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 diff --git a/src/core/CCUtf8_string.mli b/src/core/CCUtf8_string.mli index 8bec9722..b88bbcf6 100644 --- a/src/core/CCUtf8_string.mli +++ b/src/core/CCUtf8_string.mli @@ -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