Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

408 cleanup #436

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions src/core/CCArray.ml
Original file line number Diff line number Diff line change
Expand Up @@ -455,15 +455,6 @@ let pp_i ?(pp_start = fun _ () -> ()) ?(pp_stop = fun _ () -> ())
let to_string ?(sep = ", ") item_to_string a =
Array.to_list a |> List.map item_to_string |> String.concat sep

let to_seq a =
let rec aux i () =
if i >= length a then
Seq.Nil
else
Seq.Cons (a.(i), aux (i + 1))
in
aux 0

let to_iter a k = iter k a

let to_gen a =
Expand Down
8 changes: 0 additions & 8 deletions src/core/CCArray.mli
Original file line number Diff line number Diff line change
Expand Up @@ -240,14 +240,6 @@ val to_iter : 'a t -> 'a iter
in modification of the iterator.
@since 2.8 *)

val to_seq : 'a t -> 'a Seq.t
(** [to_seq a] returns a [Seq.t] of the elements of an array [a].
The input array [a] is shared with the sequence and modification of it will result
in modification of the sequence.
Renamed from [to_std_seq] since 3.0.
@since 3.0
*)

val to_gen : 'a t -> 'a gen
(** [to_gen a] returns a [gen] of the elements of an array [a]. *)

Expand Down
25 changes: 1 addition & 24 deletions src/core/CCArrayLabels.mli
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,6 @@ val fold2 : f:('acc -> 'a -> 'b -> 'acc) -> init:'acc -> 'a t -> 'b t -> 'acc
@raise Invalid_argument if [a] and [b] have distinct lengths.
@since 0.20 *)

val iter2 : f:('a -> 'b -> unit) -> 'a t -> 'b t -> unit
(** [iter2 ~f a b] iterates on the two arrays [a] and [b] stepwise.
It is equivalent to [f a0 b0; …; f a.(length a - 1) b.(length b - 1); ()].

@raise Invalid_argument if [a] and [b] have distinct lengths.
@since 0.20 *)

val shuffle : 'a t -> unit
(** [shuffle a] randomly shuffles the array [a], in place. *)

Expand All @@ -248,14 +241,6 @@ val to_iter : 'a t -> 'a iter
in modification of the iterator.
@since 2.8 *)

val to_seq : 'a t -> 'a Seq.t
(** [to_seq a] returns a [Seq.t] of the elements of an array [a].
The input array [a] is shared with the sequence and modification of it will result
in modification of the sequence.
Renamed from [to_std_seq] since 3.0.
@since 3.0
*)

val to_gen : 'a t -> 'a gen
(** [to_gen a] returns a [gen] of the elements of an array [a]. *)

Expand Down Expand Up @@ -286,14 +271,6 @@ val pp_i :
By defaults [pp_start] and [pp_stop] does nothing and [pp_sep] defaults to
(fun out -> Format.fprintf out ",@ "). *)

val map2 : f:('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c t
(** [map2 ~f a b] applies function [f] to all elements of [a] and [b],
and builds an array with the results returned by [f]:
[[| f a.(0) b.(0); …; f a.(length a - 1) b.(length b - 1)|]].

@raise Invalid_argument if [a] and [b] have distinct lengths.
@since 0.20 *)

val rev : 'a t -> 'a t
(** [rev a] copies the array [a] and reverses it in place.
@since 0.20 *)
Expand All @@ -308,7 +285,7 @@ val filter_map : f:('a -> 'b option) -> 'a t -> 'b t
element of [a] is discarded. *)

val monoid_product : f:('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c t
(** [monoid_product ~f a b] passes all combinaisons of tuples from the two arrays [a] and [b]
(** [monoid_product ~f a b] passes all combinaisons of tuples from the two arrays [a] and [b]
to the function [f].
@since 2.8 *)

Expand Down
12 changes: 1 addition & 11 deletions src/core/CCBool.ml
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
(* This file is free software, part of containers. See file "license" for more details. *)



type t = bool

let equal (a : bool) b = Stdlib.( = ) a b
let compare (a : bool) b = Stdlib.compare a b

let to_int (x : bool) : int =
if x then
1
else
0
include Bool

let of_int x : t = x <> 0

Expand Down
13 changes: 2 additions & 11 deletions src/core/CCBool.mli
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,8 @@

(** Basic Bool functions *)

type t = bool

val compare : t -> t -> int
(** [compare b1 b2] is the total ordering on booleans [b1] and [b2], similar to {!Stdlib.compare}. *)

val equal : t -> t -> bool
(** [equal b1 b2] is [true] if [b1] and [b2] are the same. *)

val to_int : t -> int
(** [to_int true = 1], [to_int false = 0].
@since 2.7 *)
include module type of Bool
(** @inline *)

val of_int : int -> t
(** [of_int i] is the same as [i <> 0]
Expand Down
61 changes: 1 addition & 60 deletions src/core/CCFloat.ml
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
(* This file is free software, part of containers. See file "license" for more details. *)



type t = float

type fpclass = Stdlib.fpclass =
| FP_normal
| FP_subnormal
| FP_zero
| FP_infinite
| FP_nan
include Float

module Infix = struct
let ( = ) : t -> t -> bool = Stdlib.( = )
Expand All @@ -29,47 +20,11 @@ include Infix

[@@@ocaml.warning "-32"]

let nan = Stdlib.nan
let infinity = Stdlib.infinity
let neg_infinity = Stdlib.neg_infinity
let max_value = infinity
let min_value = neg_infinity
let max_finite_value = Stdlib.max_float
let epsilon = Stdlib.epsilon_float
let pi = 0x1.921fb54442d18p+1
let is_nan x = Stdlib.(classify_float x = Stdlib.FP_nan)
let add = ( +. )
let sub = ( -. )
let mul = ( *. )
let div = ( /. )
let neg = ( ~-. )
let abs = Stdlib.abs_float
let scale = ( *. )

let min (x : t) y =
match Stdlib.classify_float x, Stdlib.classify_float y with
| FP_nan, _ -> y
| _, FP_nan -> x
| _ ->
if x < y then
x
else
y

let max (x : t) y =
match Stdlib.classify_float x, Stdlib.classify_float y with
| FP_nan, _ -> y
| _, FP_nan -> x
| _ ->
if x > y then
x
else
y

let equal (a : float) b = a = b
let hash : t -> int = Hashtbl.hash
let compare (a : float) b = Stdlib.compare a b

[@@@ocaml.warning "+32"]

type 'a printer = Format.formatter -> 'a -> unit
Expand All @@ -93,22 +48,8 @@ let sign_exn (a : float) =
else
compare a 0.

let round x =
let low = floor x in
let high = ceil x in
if x -. low > high -. x then
high
else
low

let to_int (a : float) = Stdlib.int_of_float a
let of_int (a : int) = Stdlib.float_of_int a
let to_string (a : float) = Stdlib.string_of_float a
let of_string_exn (a : string) = Stdlib.float_of_string a

let of_string_opt (a : string) =
try Some (Stdlib.float_of_string a) with Failure _ -> None

let random n st = Random.State.float st n
let random_small = random 100.0
let random_range i j st = i +. random (j -. i) st
Expand Down
68 changes: 1 addition & 67 deletions src/core/CCFloat.mli
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,7 @@
(** Basic operations on floating-point numbers
@since 0.6.1 *)



type t = float

type fpclass = Stdlib.fpclass =
| FP_normal
| FP_subnormal
| FP_zero
| FP_infinite
| FP_nan

val nan : t
(** [nan] is Not a Number (NaN). Equal to {!Stdlib.nan}. *)
include module type of Float

val max_value : t
(** [max_value] is Positive infinity. Equal to {!Stdlib.infinity}. *)
Expand All @@ -26,50 +14,13 @@ val min_value : t
val max_finite_value : t
(** [max_finite_value] is the largest finite float value. Equal to {!Stdlib.max_float}. *)

val epsilon : t
(** [epsilon] is the smallest positive float x such that [1.0 +. x <> 1.0].
Equal to {!Stdlib.epsilon_float}. *)

val pi : t
(** [pi] is the constant pi. The ratio of a circumference to its diameter.
@since 3.0 *)

val is_nan : t -> bool
(** [is_nan f] returns [true] if f is NaN, [false] otherwise. *)

val add : t -> t -> t
(** [add x y] is equal to [x +. y]. *)

val sub : t -> t -> t
(** [sub x y] is equal to [x -. y]. *)

val neg : t -> t
(** [neg x] is equal to [~-. x]. *)

val abs : t -> t
(** [abs x] is the absolute value of the floating-point number [x].
Equal to {!Stdlib.abs_float}. *)

val scale : t -> t -> t
(** [scale x y] is equal to [x *. y]. *)

val min : t -> t -> t
(** [min x y] returns the min of the two given values [x] and [y]. *)

val max : t -> t -> t
(** [max x y] returns the max of the two given values [x] and [y]. *)

val equal : t -> t -> bool
(** [equal x y] is [true] if [x] and [y] are the same. *)

val compare : t -> t -> int
(** [compare x y] is {!Stdlib.compare x y}. *)

type 'a printer = Format.formatter -> 'a -> unit
type 'a random_gen = Random.State.t -> 'a

val pp : t printer
val hash : t -> int
val random : t -> t random_gen
val random_small : t random_gen
val random_range : t -> t -> t random_gen
Expand All @@ -78,11 +29,6 @@ val fsign : t -> t
(** [fsign x] is one of [-1., -0., +0., +1.], or [nan] if [x] is NaN.
@since 0.7 *)

val round : t -> t
(** [round x] returns the closest integer value, either above or below.
For [n + 0.5], [round] returns [n].
@since 0.20 *)

exception TrapNaN of string

val sign_exn : t -> int
Expand All @@ -91,23 +37,11 @@ val sign_exn : t -> int
Note that infinities have defined signs in OCaml.
@since 0.7 *)

val to_int : t -> int
(** Alias to {!int_of_float}.
Unspecified if outside of the range of integers. *)

val of_int : int -> t
(** Alias to {!float_of_int}. *)

val to_string : t -> string

val of_string_exn : string -> t
(** Alias to {!float_of_string}.
@raise Failure in case of failure.
@since 1.2 *)

val of_string_opt : string -> t option
(** @since 3.0 *)

val equal_precision : epsilon:t -> t -> t -> bool
(** Equality with allowed error up to a non negative epsilon value. *)

Expand Down
28 changes: 0 additions & 28 deletions src/core/CCInt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,8 @@

include Int

type t = int
type 'a iter = ('a -> unit) -> unit

let zero = 0
let one = 1
let minus_one = -1
let add = ( + )
let sub = ( - )
let mul = ( * )
let div = ( / )
let succ = succ
let pred = pred
let abs = abs
let max_int = max_int
let min_int = min_int
let equal (a : int) b = Stdlib.( = ) a b
let compare (a : int) b = compare a b

(* use FNV:
https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function *)
let hash (n : int) : int =
Expand Down Expand Up @@ -65,7 +49,6 @@ let range' i j yield =
range i (j + 1) yield

let sign i = compare i 0
let neg i = -i

let pow a b =
let rec aux acc = function
Expand Down Expand Up @@ -147,11 +130,8 @@ let random_small = random 100
let random_range i j st = i + random (j - i) st
let pp fmt = Format.pp_print_int fmt
let most_significant_bit = -1 lxor (-1 lsr 1)
let to_string = string_of_int
let of_string s = try Some (int_of_string s) with Failure _ -> None
let of_string_exn = Stdlib.int_of_string
let to_float = float_of_int
let of_float = int_of_float

type output = char -> unit

Expand Down Expand Up @@ -248,11 +228,3 @@ let popcount (b : int) : int =
let b = add b (shift_right_logical b 32) in
let b = logand b 0x7fL in
to_int b

let logand = ( land )
let logor = ( lor )
let logxor = ( lxor )
let lognot = lnot
let shift_left = ( lsl )
let shift_right = ( asr )
let shift_right_logical = ( lsr )
Loading