mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-18 08:36:41 -05:00
Add a leq function for each primitive types
This function allows these modules to be passed to CCHeap.Make
This commit is contained in:
parent
8060980266
commit
6ca94be4bd
16 changed files with 46 additions and 2 deletions
|
|
@ -7,6 +7,8 @@ let equal (a:bool) b = Pervasives.(=) a b
|
||||||
|
|
||||||
let compare (a:bool) b = Pervasives.compare a b
|
let compare (a:bool) b = Pervasives.compare a b
|
||||||
|
|
||||||
|
let leq (a:bool) b = Pervasives.(<=) a b
|
||||||
|
|
||||||
let negate = not
|
let negate = not
|
||||||
|
|
||||||
type 'a printer = Format.formatter -> 'a -> unit
|
type 'a printer = Format.formatter -> 'a -> unit
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,10 @@ type t = bool
|
||||||
val compare : t -> t -> int
|
val compare : t -> t -> int
|
||||||
(** Total ordering on booleans, similar to {!Pervasives.compare}. *)
|
(** 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 equal : t -> t -> bool
|
||||||
|
|
||||||
val negate : t -> t
|
val negate : t -> t
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@ include Char
|
||||||
|
|
||||||
let equal (a:char) b = Pervasives.(=) a b
|
let equal (a:char) b = Pervasives.(=) a b
|
||||||
|
|
||||||
|
let leq (a:char) b = Pervasives.(<=) a b
|
||||||
|
|
||||||
let pp_buf = Buffer.add_char
|
let pp_buf = Buffer.add_char
|
||||||
let pp = Format.pp_print_char
|
let pp = Format.pp_print_char
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,10 @@ val compare : t -> t -> int
|
||||||
allows the module [Char] to be passed as argument to the functors
|
allows the module [Char] to be passed as argument to the functors
|
||||||
{!Set.Make} and {!Map.Make}. *)
|
{!Set.Make} and {!Map.Make}. *)
|
||||||
|
|
||||||
|
val leq : t -> t -> bool
|
||||||
|
(** Equivalent of [(<=)]
|
||||||
|
Allows to be passed to {!Heap.Make} *)
|
||||||
|
|
||||||
val lowercase_ascii : t -> t
|
val lowercase_ascii : t -> t
|
||||||
(** Convert the given character to its equivalent lowercase character,
|
(** Convert the given character to its equivalent lowercase character,
|
||||||
using the US-ASCII character set.
|
using the US-ASCII character set.
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,7 @@ let equal (a:float) b = a=b
|
||||||
|
|
||||||
let hash : t -> int = Hashtbl.hash
|
let hash : t -> int = Hashtbl.hash
|
||||||
let compare (a:float) b = Pervasives.compare a b
|
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 printer = Format.formatter -> 'a -> unit
|
||||||
type 'a random_gen = Random.State.t -> 'a
|
type 'a random_gen = Random.State.t -> 'a
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,10 @@ val equal : t -> t -> bool
|
||||||
|
|
||||||
val compare : t -> t -> int
|
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 printer = Format.formatter -> 'a -> unit
|
||||||
type 'a random_gen = Random.State.t -> 'a
|
type 'a random_gen = Random.State.t -> 'a
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ let equal (a:int) b = Pervasives.(=) a b
|
||||||
|
|
||||||
let compare a b = compare 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 hash i = i land max_int
|
||||||
|
|
||||||
let range i j yield =
|
let range i j yield =
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,10 @@ val compare : t -> t -> int
|
||||||
val equal : t -> t -> bool
|
val equal : t -> t -> bool
|
||||||
(** Equality function for integers. *)
|
(** Equality function for integers. *)
|
||||||
|
|
||||||
|
val leq : t -> t -> bool
|
||||||
|
(** Equivalent of [(<=)]
|
||||||
|
Allows to be passed to {!Heap.Make} *)
|
||||||
|
|
||||||
val hash : t -> int
|
val hash : t -> int
|
||||||
|
|
||||||
val sign : t -> int
|
val sign : t -> int
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,8 @@
|
||||||
|
|
||||||
include Int32
|
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
|
module Infix = struct
|
||||||
let (+) = add
|
let (+) = add
|
||||||
|
|
|
||||||
|
|
@ -94,6 +94,10 @@ val equal : t -> t -> bool
|
||||||
(** The equal function for 32-bit integers.
|
(** The equal function for 32-bit integers.
|
||||||
Like {!Pervasives.(=) x y)}. *)
|
Like {!Pervasives.(=) x y)}. *)
|
||||||
|
|
||||||
|
val leq : t -> t -> bool
|
||||||
|
(** Equivalent of [(<=)]
|
||||||
|
Allows to be passed to {!Heap.Make} *)
|
||||||
|
|
||||||
val hash : t -> int
|
val hash : t -> int
|
||||||
(** Like {!Pervasives.abs (to_int x)}. *)
|
(** Like {!Pervasives.abs (to_int x)}. *)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,8 @@
|
||||||
|
|
||||||
include Int64
|
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
|
module Infix = struct
|
||||||
let (+) = add
|
let (+) = add
|
||||||
|
|
|
||||||
|
|
@ -100,6 +100,10 @@ val compare : t -> t -> int
|
||||||
allows the module [CCInt64] to be passed as argument to the functors
|
allows the module [CCInt64] to be passed as argument to the functors
|
||||||
{!Set.Make} and {!Map.Make}. *)
|
{!Set.Make} and {!Map.Make}. *)
|
||||||
|
|
||||||
|
val leq : t -> t -> bool
|
||||||
|
(** Equivalent of [(<=)]
|
||||||
|
Allows to be passed to {!Heap.Make} *)
|
||||||
|
|
||||||
val hash : t -> int
|
val hash : t -> int
|
||||||
(** Like {!Pervasives.abs (to_int x)}. *)
|
(** Like {!Pervasives.abs (to_int x)}. *)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -66,6 +66,8 @@ let equal (a:string) b = Pervasives.(=) a b
|
||||||
let compare_int (a : int) b = Pervasives.compare a b
|
let compare_int (a : int) b = Pervasives.compare a b
|
||||||
let compare = String.compare
|
let compare = String.compare
|
||||||
|
|
||||||
|
let leq (a:string) b = String.compare a b <= 0
|
||||||
|
|
||||||
let hash s = Hashtbl.hash s
|
let hash s = Hashtbl.hash s
|
||||||
|
|
||||||
let length = String.length
|
let length = String.length
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,10 @@ val equal : string -> string -> bool
|
||||||
|
|
||||||
val compare : string -> string -> int
|
val compare : string -> string -> int
|
||||||
|
|
||||||
|
val leq : t -> t -> bool
|
||||||
|
(** Equivalent of [(<=)]
|
||||||
|
Allows to be passed to {!Heap.Make} *)
|
||||||
|
|
||||||
val is_empty : string -> bool
|
val is_empty : string -> bool
|
||||||
(** [is_empty s] returns [true] iff [s] is empty (i.e. its length is 0).
|
(** [is_empty s] returns [true] iff [s] is empty (i.e. its length is 0).
|
||||||
@since 1.5 *)
|
@since 1.5 *)
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ type 'a gen = unit -> 'a option
|
||||||
type 'a sequence = ('a -> unit) -> unit
|
type 'a sequence = ('a -> unit) -> unit
|
||||||
|
|
||||||
let equal (a:string) b = Pervasives.(=) a b
|
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 hash : string -> int = Hashtbl.hash
|
||||||
let pp = Format.pp_print_string
|
let pp = Format.pp_print_string
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,10 @@ val hash : t -> int
|
||||||
|
|
||||||
val compare : t -> 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 pp : Format.formatter -> t -> unit
|
||||||
|
|
||||||
val to_string : t -> string
|
val to_string : t -> string
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue