mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
add CCHeap.to_seq_sorted
This commit is contained in:
parent
12b38f4c31
commit
8627838faf
2 changed files with 24 additions and 0 deletions
|
|
@ -69,6 +69,15 @@ end
|
|||
)
|
||||
*)
|
||||
|
||||
(*$QR
|
||||
Q.(list_of_size Gen.(return 1_000) int) (fun l ->
|
||||
(* put elements into a heap *)
|
||||
let h = H.of_seq (Sequence.of_list l) in
|
||||
let l' = H.to_seq_sorted h |> Sequence.to_list in
|
||||
is_sorted l'
|
||||
)
|
||||
*)
|
||||
|
||||
module type S = sig
|
||||
type elt
|
||||
type t
|
||||
|
|
@ -146,6 +155,10 @@ module type S = sig
|
|||
|
||||
val to_seq : t -> elt sequence
|
||||
|
||||
val to_seq_sorted : t -> elt sequence
|
||||
(** Iterate on the elements, in increasing order
|
||||
@since NEXT_RELEASE *)
|
||||
|
||||
val add_klist : t -> elt klist -> t (** @since 0.16 *)
|
||||
|
||||
val of_klist : elt klist -> t
|
||||
|
|
@ -273,6 +286,13 @@ module Make(E : PARTIAL_ORD) : S with type elt = E.t = struct
|
|||
|
||||
let to_seq h k = iter k h
|
||||
|
||||
let to_seq_sorted heap =
|
||||
let rec recurse h k = match take h with
|
||||
| None -> ()
|
||||
| Some (h',x) -> k x; recurse h' k
|
||||
in
|
||||
fun k -> recurse heap k
|
||||
|
||||
let rec add_klist h l = match l() with
|
||||
| `Nil -> h
|
||||
| `Cons (x, l') ->
|
||||
|
|
|
|||
|
|
@ -92,6 +92,10 @@ module type S = sig
|
|||
|
||||
val to_seq : t -> elt sequence
|
||||
|
||||
val to_seq_sorted : t -> elt sequence
|
||||
(** Iterate on the elements, in increasing order
|
||||
@since NEXT_RELEASE *)
|
||||
|
||||
val add_klist : t -> elt klist -> t (** @since 0.16 *)
|
||||
|
||||
val of_klist : elt klist -> t
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue