mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 03:05:28 -05:00
break: remove klist type and functions from core
This commit is contained in:
parent
8c3d716ab1
commit
c85c135157
13 changed files with 2 additions and 135 deletions
|
|
@ -490,9 +490,6 @@ let shuffle a =
|
|||
let shuffle_with st a =
|
||||
_shuffle (Random.State.int st) a 0 (Array.length a)
|
||||
|
||||
let rec _to_klist a i j () =
|
||||
if i=j then `Nil else `Cons (a.(i), _to_klist a (i+1) j)
|
||||
|
||||
let random_choose a =
|
||||
let n = Array.length a in
|
||||
if n = 0 then invalid_arg "Array.random_choose";
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ type 'a t = 'a -> hash
|
|||
|
||||
type 'a iter = ('a -> unit) -> unit
|
||||
type 'a gen = unit -> 'a option
|
||||
type 'a klist = unit -> [`Nil | `Cons of 'a * 'a klist]
|
||||
|
||||
let combine f s x = Hashtbl.seeded_hash s (f x)
|
||||
|
||||
|
|
@ -87,9 +86,3 @@ let gen f g =
|
|||
| None -> s
|
||||
| Some x -> aux (combine2 s (f x))
|
||||
in aux 0x42
|
||||
|
||||
let klist f l =
|
||||
let rec aux l s = match l () with
|
||||
| `Nil -> s
|
||||
| `Cons (x,tail) -> aux tail (combine2 s (f x))
|
||||
in aux l 0x42
|
||||
|
|
|
|||
|
|
@ -74,9 +74,7 @@ val combine6 : hash -> hash -> hash -> hash -> hash -> hash -> hash
|
|||
|
||||
type 'a iter = ('a -> unit) -> unit
|
||||
type 'a gen = unit -> 'a option
|
||||
type 'a klist = unit -> [`Nil | `Cons of 'a * 'a klist]
|
||||
|
||||
val seq : 'a t -> 'a Seq.t t
|
||||
val iter : 'a t -> 'a iter t
|
||||
val gen : 'a t -> 'a gen t
|
||||
val klist : 'a t -> 'a klist t
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@
|
|||
type 'a iter = ('a -> unit) -> unit
|
||||
type 'a gen = unit -> 'a option
|
||||
type 'a printer = Format.formatter -> 'a -> unit
|
||||
type 'a klist = unit -> [`Nil | `Cons of 'a * 'a klist]
|
||||
type 'a ktree = unit -> [`Nil | `Node of 'a * 'a ktree list]
|
||||
|
||||
module type PARTIAL_ORD = sig
|
||||
|
|
@ -152,9 +151,9 @@ module type S = sig
|
|||
|
||||
(** {2 Conversions}
|
||||
|
||||
The interface of [of_gen], [of_iter], [of_klist]
|
||||
The interface of [of_gen], [of_iter]
|
||||
has changed since 0.16 (the old signatures
|
||||
are now [add_seq], [add_gen], [add_klist]). *)
|
||||
are now [add_seq], [add_gen]). *)
|
||||
|
||||
val to_list : t -> elt list
|
||||
(** Return the elements of the heap, in no particular order. *)
|
||||
|
|
@ -203,14 +202,6 @@ module type S = sig
|
|||
(** Iterate on the elements, in increasing order.
|
||||
@since 2.8 *)
|
||||
|
||||
val add_klist : t -> elt klist -> t (** @since 0.16 *)
|
||||
|
||||
val of_klist : elt klist -> t
|
||||
(** Build a heap from a given [klist]. Complexity: [O(n log n)]. *)
|
||||
|
||||
val to_klist : t -> elt klist
|
||||
(** Return a [klist] of the elements of the heap. *)
|
||||
|
||||
val add_gen : t -> elt gen -> t (** @since 0.16 *)
|
||||
|
||||
val of_gen : elt gen -> t
|
||||
|
|
@ -396,23 +387,6 @@ module Make(E : PARTIAL_ORD) : S with type elt = E.t = struct
|
|||
| None -> Seq.Nil
|
||||
| Some (h', x) -> Seq.Cons (x, to_seq_sorted h')
|
||||
|
||||
let rec add_klist h l = match l() with
|
||||
| `Nil -> h
|
||||
| `Cons (x, l') ->
|
||||
let h' = add h x in
|
||||
add_klist h' l'
|
||||
|
||||
let of_klist l = add_klist empty l
|
||||
|
||||
let to_klist h =
|
||||
let rec next stack () = match stack with
|
||||
| [] -> `Nil
|
||||
| E :: stack' -> next stack' ()
|
||||
| N (_, x, a, b) :: stack' ->
|
||||
`Cons (x, next (a :: b :: stack'))
|
||||
in
|
||||
next [h]
|
||||
|
||||
let rec add_gen h g = match g () with
|
||||
| None -> h
|
||||
| Some x ->
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ type 'a iter = ('a -> unit) -> unit
|
|||
@since 2.8 *)
|
||||
|
||||
type 'a gen = unit -> 'a option
|
||||
type 'a klist = unit -> [`Nil | `Cons of 'a * 'a klist]
|
||||
type 'a ktree = unit -> [`Nil | `Node of 'a * 'a ktree list]
|
||||
type 'a printer = Format.formatter -> 'a -> unit
|
||||
|
||||
|
|
@ -146,16 +145,6 @@ module type S = sig
|
|||
Renamed from [to_std_seq_sorted] since NEXT_RELEASE.
|
||||
@since NEXT_RELEASE *)
|
||||
|
||||
val add_klist : t -> elt klist -> t
|
||||
(** [add_klist h klist] adds the klist [klist] to the heap [h].
|
||||
@since 0.16 *)
|
||||
|
||||
val of_klist : elt klist -> t
|
||||
(** [of_klist klist] builds a heap from a given [klist]. Complexity: [O(n log n)]. *)
|
||||
|
||||
val to_klist : t -> elt klist
|
||||
(** [to_klist h] returns a [klist] of the elements of the heap [h]. *)
|
||||
|
||||
val add_gen : t -> elt gen -> t
|
||||
(** [add_gen h gen] adds the gen [gen] to the heap [h].
|
||||
@since 0.16 *)
|
||||
|
|
|
|||
|
|
@ -1672,7 +1672,6 @@ end
|
|||
|
||||
type 'a iter = ('a -> unit) -> unit
|
||||
type 'a gen = unit -> 'a option
|
||||
type 'a klist = unit -> [`Nil | `Cons of 'a * 'a klist]
|
||||
type 'a printer = Format.formatter -> 'a -> unit
|
||||
type 'a random_gen = Random.State.t -> 'a
|
||||
|
||||
|
|
@ -1770,24 +1769,6 @@ let of_gen g =
|
|||
Q.(list int) (fun l -> of_gen(to_gen l) = l)
|
||||
*)
|
||||
|
||||
let to_klist l =
|
||||
let rec make l () = match l with
|
||||
| [] -> `Nil
|
||||
| x::l' -> `Cons (x, make l')
|
||||
in make l
|
||||
|
||||
let of_klist l =
|
||||
let rec direct i g =
|
||||
if i = 0 then safe [] g
|
||||
else match l () with
|
||||
| `Nil -> []
|
||||
| `Cons (x,l') -> x :: direct (i-1) l'
|
||||
and safe acc l = match l () with
|
||||
| `Nil -> List.rev acc
|
||||
| `Cons (x,l') -> safe (x::acc) l'
|
||||
in
|
||||
direct direct_depth_default_ l
|
||||
|
||||
module Infix = struct
|
||||
let[@inline] (>|=) l f = map f l
|
||||
let[@inline] (>>=) l f = flat_map f l
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ type 'a iter = ('a -> unit) -> unit
|
|||
@since 2.8 *)
|
||||
|
||||
type 'a gen = unit -> 'a option
|
||||
type 'a klist = unit -> [`Nil | `Cons of 'a * 'a klist]
|
||||
type 'a printer = Format.formatter -> 'a -> unit
|
||||
type 'a random_gen = Random.State.t -> 'a
|
||||
|
||||
|
|
@ -782,13 +781,6 @@ val of_gen : 'a gen -> 'a t
|
|||
(** [of_gen gen] builds a list from a given [gen].
|
||||
In the result, elements appear in the same order as they did in the source [gen]. *)
|
||||
|
||||
val to_klist : 'a t -> 'a klist
|
||||
(** [to_klist l] returns a [klist] of the elements of the list [l]. *)
|
||||
|
||||
val of_klist : 'a klist -> 'a t
|
||||
(** [of_klist klist] builds a list from a given [klist].
|
||||
In the result, elements appear in the same order as they did in the source [klist]. *)
|
||||
|
||||
(** {2 Infix Operators}
|
||||
It is convenient to {!open CCList.Infix} to access the infix operators
|
||||
without cluttering the scope too much.
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ type 'a iter = ('a -> unit) -> unit
|
|||
@since 2.8 *)
|
||||
|
||||
type 'a gen = unit -> 'a option
|
||||
type 'a klist = unit -> [`Nil | `Cons of 'a * 'a klist]
|
||||
type 'a printer = Format.formatter -> 'a -> unit
|
||||
type 'a random_gen = Random.State.t -> 'a
|
||||
|
||||
|
|
@ -786,13 +785,6 @@ val of_gen : 'a gen -> 'a t
|
|||
(** [of_gen gen] builds a list from a given [gen].
|
||||
In the result, elements appear in the same order as they did in the source [gen]. *)
|
||||
|
||||
val to_klist : 'a t -> 'a klist
|
||||
(** [to_klist l] returns a [klist] of the elements of the list [l]. *)
|
||||
|
||||
val of_klist : 'a klist -> 'a t
|
||||
(** [of_klist klist] builds a list from a given [klist].
|
||||
In the result, elements appear in the same order as they did in the source [klist]. *)
|
||||
|
||||
(** {2 Infix Operators}
|
||||
It is convenient to {!open CCList.Infix} to access the infix operators
|
||||
without cluttering the scope too much.
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ open CCShims_
|
|||
|
||||
type 'a iter = ('a -> unit) -> unit
|
||||
type 'a gen = unit -> 'a option
|
||||
type 'a klist = unit -> [`Nil | `Cons of 'a * 'a klist]
|
||||
|
||||
(* standard implementations *)
|
||||
|
||||
|
|
@ -420,20 +419,6 @@ module Split = struct
|
|||
|
||||
let seq_cpy ?(drop=default_drop) ~by s = _mkseq ~drop ~by s String.sub
|
||||
|
||||
let _mkklist ~drop ~by s k =
|
||||
let by = Find.compile by in
|
||||
let rec make state () = match _split ~by s state with
|
||||
| None -> `Nil
|
||||
| Some (state', 0, 0) when drop.first -> make state' ()
|
||||
| Some (_, i, 0) when drop.last && i=length s -> `Nil
|
||||
| Some (state', i, len) ->
|
||||
`Cons (k s i len , make state')
|
||||
in make (SplitAt 0)
|
||||
|
||||
let klist ?(drop=default_drop) ~by s = _mkklist ~drop ~by s _tuple3
|
||||
|
||||
let klist_cpy ?(drop=default_drop) ~by s = _mkklist ~drop ~by s String.sub
|
||||
|
||||
let _mk_iter ~drop ~by s f k =
|
||||
let by = Find.compile by in
|
||||
let rec aux state = match _split ~by s state with
|
||||
|
|
@ -828,22 +813,6 @@ let of_seq seq =
|
|||
Seq.iter (Buffer.add_char b) seq;
|
||||
Buffer.contents b
|
||||
|
||||
let rec _to_klist s i len () =
|
||||
if len=0 then `Nil
|
||||
else `Cons (s.[i], _to_klist s (i+1)(len-1))
|
||||
|
||||
let of_klist l =
|
||||
let b = Buffer.create 15 in
|
||||
let rec aux l = match l() with
|
||||
| `Nil ->
|
||||
Buffer.contents b
|
||||
| `Cons (x,l') ->
|
||||
Buffer.add_char b x;
|
||||
aux l'
|
||||
in aux l
|
||||
|
||||
let to_klist s = _to_klist s 0 (String.length s)
|
||||
|
||||
let to_list s = _to_list s [] 0 (String.length s)
|
||||
|
||||
let of_list l =
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ type 'a iter = ('a -> unit) -> unit
|
|||
@since 2.8 *)
|
||||
|
||||
type 'a gen = unit -> 'a option
|
||||
type 'a klist = unit -> [`Nil | `Cons of 'a * 'a klist]
|
||||
|
||||
include module type of struct include String end
|
||||
(** {{: https://caml.inria.fr/pub/docs/manual-ocaml/libref/String.html} Documentation for the standard String module}*)
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ type 'a iter = ('a -> unit) -> unit
|
|||
@since 2.8 *)
|
||||
|
||||
type 'a gen = unit -> 'a option
|
||||
type 'a klist = unit -> [`Nil | `Cons of 'a * 'a klist]
|
||||
|
||||
include module type of struct include StringLabels end
|
||||
(** {{: https://caml.inria.fr/pub/docs/manual-ocaml/libref/StringLabels.html} Documentation for the standard StringLabels module}*)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ type rw = [`RW]
|
|||
type ro = [`RO]
|
||||
|
||||
type 'a iter = ('a -> unit) -> unit
|
||||
type 'a klist = unit -> [`Nil | `Cons of 'a * 'a klist]
|
||||
type 'a gen = unit -> 'a option
|
||||
type 'a equal = 'a -> 'a -> bool
|
||||
type 'a ord = 'a -> 'a -> int
|
||||
|
|
@ -1067,18 +1066,6 @@ let to_gen v =
|
|||
let v = (1--10) in to_list v = Gen.to_list (to_gen v)
|
||||
*)
|
||||
|
||||
let of_klist ?(init=create ()) l =
|
||||
let rec aux l = match l() with
|
||||
| `Nil -> init
|
||||
| `Cons (x,l') -> push init x; aux l'
|
||||
in aux l
|
||||
|
||||
let to_klist v =
|
||||
let rec aux i () =
|
||||
if i=v.size then `Nil
|
||||
else `Cons (v.vec.(i), aux (i+1))
|
||||
in aux 0
|
||||
|
||||
let to_string ?(start="") ?(stop="") ?(sep=", ") item_to_string v =
|
||||
start ^ (to_list v |> List.map item_to_string |> String.concat sep) ^ stop
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ type 'a iter = ('a -> unit) -> unit
|
|||
(** Fast internal iterator.
|
||||
@since 2.8 *)
|
||||
|
||||
type 'a klist = unit -> [`Nil | `Cons of 'a * 'a klist]
|
||||
type 'a gen = unit -> 'a option
|
||||
type 'a equal = 'a -> 'a -> bool
|
||||
type 'a ord = 'a -> 'a -> int
|
||||
|
|
@ -339,8 +338,6 @@ val slice_iter : ('a,_) t -> int -> int -> 'a iter
|
|||
@since NEXT_RELEASE
|
||||
*)
|
||||
|
||||
val of_klist : ?init:('a, rw) t -> 'a klist -> ('a, rw) t
|
||||
val to_klist : ('a,_) t -> 'a klist
|
||||
val of_gen : ?init:('a, rw) t -> 'a gen -> ('a, rw) t
|
||||
val to_gen : ('a,_) t -> 'a gen
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue