allow to specify the blocksize in persistent

This commit is contained in:
Simon Cruanes 2013-10-20 22:02:19 +02:00
parent d0bedb7a76
commit 85b063737f
2 changed files with 9 additions and 4 deletions

View file

@ -231,8 +231,9 @@ end
(** Iterate on the sequence, storing elements in a data structure.
The resulting sequence can be iterated on as many times as needed. *)
let persistent (seq : 'a t) : 'a t =
let l = MList.of_seq seq in
let persistent ?(blocksize=64) seq =
if blocksize < 2 then failwith "Sequence.persistent: blocksize too small";
let l = MList.of_seq ~size:blocksize seq in
from_iter (fun k -> MList.iter k l)
(** Sort the sequence. Eager, O(n) ram and O(n ln(n)) time. *)

View file

@ -151,11 +151,15 @@ val fmap : ('a -> 'b option) -> 'a t -> 'b t
val intersperse : 'a -> 'a t -> 'a t
(** Insert the single element between every element of the sequence *)
val persistent : 'a t -> 'a t
val persistent : ?blocksize:int -> 'a t -> 'a t
(** Iterate on the sequence, storing elements in a data structure.
The resulting sequence can be iterated on as many times as needed.
{b Note}: calling persistent on an already persistent sequence
will still make a new copy of the sequence! *)
will still make a new copy of the sequence!
@param blocksize the size of chunks in the unrolled list
used to store elements. Use bigger values for bigger sequences.
Default: 64 *)
val sort : ?cmp:('a -> 'a -> int) -> 'a t -> 'a t
(** Sort the sequence. Eager, O(n) ram and O(n ln(n)) time.