mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
doc
This commit is contained in:
parent
11611894e9
commit
5ad2b2df83
2 changed files with 17 additions and 5 deletions
7
gen.ml
7
gen.ml
|
|
@ -860,6 +860,10 @@ let intersperse x gen =
|
||||||
let product gena genb =
|
let product gena genb =
|
||||||
let all_a = ref [] in
|
let all_a = ref [] in
|
||||||
let all_b = ref [] in
|
let all_b = ref [] in
|
||||||
|
(* cur: current state, i.e., what we have to do next. Can be stop,
|
||||||
|
getLeft/getRight (to obtain next element from first/second generator),
|
||||||
|
or prodLeft/prodRIght to compute the product of an element with a list
|
||||||
|
of already met elements *)
|
||||||
let cur = ref `GetLeft in
|
let cur = ref `GetLeft in
|
||||||
let rec next () =
|
let rec next () =
|
||||||
match !cur with
|
match !cur with
|
||||||
|
|
@ -937,7 +941,8 @@ let sort ?(cmp=Pervasives.compare) gen =
|
||||||
then raise EOG
|
then raise EOG
|
||||||
else Heap.pop h
|
else Heap.pop h
|
||||||
|
|
||||||
(* FIXME: use a set *)
|
(* NOTE: using a set is not really possible, because once we have built the
|
||||||
|
set there is no simple way to iterate on it *)
|
||||||
let sort_uniq ?(cmp=Pervasives.compare) gen =
|
let sort_uniq ?(cmp=Pervasives.compare) gen =
|
||||||
uniq ~eq:(fun x y -> cmp x y = 0) (sort ~cmp gen)
|
uniq ~eq:(fun x y -> cmp x y = 0) (sort ~cmp gen)
|
||||||
|
|
||||||
|
|
|
||||||
15
gen.mli
15
gen.mli
|
|
@ -46,7 +46,11 @@ type 'a t = unit -> 'a
|
||||||
|
|
||||||
type 'a gen = 'a t
|
type 'a gen = 'a t
|
||||||
|
|
||||||
(** {2 Common signature for transient and restartable generators} *)
|
(** {2 Common signature for transient and restartable generators}
|
||||||
|
|
||||||
|
The signature {!S} abstracts on a type ['a t], where the [t] can be
|
||||||
|
the type of transient or restartable generators. Some functions specify
|
||||||
|
explicitely that they use ['a gen] (transient generators). *)
|
||||||
|
|
||||||
module type S = sig
|
module type S = sig
|
||||||
type 'a t
|
type 'a t
|
||||||
|
|
@ -312,6 +316,7 @@ val repeatedly : (unit -> 'a) -> 'a t
|
||||||
if the function is a random generator). *)
|
if the function is a random generator). *)
|
||||||
|
|
||||||
include S with type 'a t := 'a gen
|
include S with type 'a t := 'a gen
|
||||||
|
(** Operations on {b transient} generators *)
|
||||||
|
|
||||||
(** {2 Restartable generators} *)
|
(** {2 Restartable generators} *)
|
||||||
|
|
||||||
|
|
@ -333,8 +338,10 @@ end
|
||||||
(** {2 Utils} *)
|
(** {2 Utils} *)
|
||||||
|
|
||||||
val persistent : 'a t -> 'a Restart.t
|
val persistent : 'a t -> 'a Restart.t
|
||||||
(** Store content of the generator in memory, to be able to iterate on it
|
(** Store content of the transient generator in memory, to be able to iterate
|
||||||
several times later *)
|
on it several times later. If possible, consider using combinators
|
||||||
|
from {!Restart} directly instead. *)
|
||||||
|
|
||||||
val start : 'a Restart.t -> 'a t
|
val start : 'a Restart.t -> 'a t
|
||||||
(** Create a new transient generator *)
|
(** Create a new transient generator.
|
||||||
|
[start gen] is the same as [gen ()] but is included for readability. *)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue