mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-18 08:36:41 -05:00
add CCHeap.to_string
This commit is contained in:
parent
f8bdceda14
commit
1e0669e1b0
2 changed files with 24 additions and 0 deletions
|
|
@ -202,6 +202,10 @@ module type S = sig
|
||||||
val to_tree : t -> elt ktree
|
val to_tree : t -> elt ktree
|
||||||
(** Return a [ktree] of the elements of the heap. *)
|
(** Return a [ktree] of the elements of the heap. *)
|
||||||
|
|
||||||
|
val to_string : ?sep:string -> (elt -> string) -> t -> string
|
||||||
|
(** Print the heap in a string
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
val pp : ?sep:string -> elt printer -> t printer
|
val pp : ?sep:string -> elt printer -> t printer
|
||||||
(** @since 0.16
|
(** @since 0.16
|
||||||
Renamed from {!print} @since 2.0 *)
|
Renamed from {!print} @since 2.0 *)
|
||||||
|
|
@ -404,6 +408,22 @@ module Make(E : PARTIAL_ORD) : S with type elt = E.t = struct
|
||||||
| E -> `Nil
|
| E -> `Nil
|
||||||
| N (_, x, l, r) -> `Node(x, [to_tree l; to_tree r])
|
| N (_, x, l, r) -> `Node(x, [to_tree l; to_tree r])
|
||||||
|
|
||||||
|
let to_string ?(sep=",") elt_to_string h =
|
||||||
|
to_list_sorted h
|
||||||
|
|> List.map elt_to_string
|
||||||
|
|> String.concat sep
|
||||||
|
|
||||||
|
(*$Q
|
||||||
|
Q.(list int) (fun l -> \
|
||||||
|
let h = H.of_list l in \
|
||||||
|
(H.to_string string_of_int h) \
|
||||||
|
= (List.sort Stdlib.compare l |> List.map string_of_int |> String.concat ","))
|
||||||
|
Q.(list int) (fun l -> \
|
||||||
|
let h = H.of_list l in \
|
||||||
|
(H.to_string ~sep:" " string_of_int h) \
|
||||||
|
= (List.sort Stdlib.compare l |> List.map string_of_int |> String.concat " "))
|
||||||
|
*)
|
||||||
|
|
||||||
let pp ?(sep=",") pp_elt out h =
|
let pp ?(sep=",") pp_elt out h =
|
||||||
let first=ref true in
|
let first=ref true in
|
||||||
iter
|
iter
|
||||||
|
|
|
||||||
|
|
@ -142,6 +142,10 @@ module type S = sig
|
||||||
val to_tree : t -> elt ktree
|
val to_tree : t -> elt ktree
|
||||||
(** Return a [ktree] of the elements of the heap. *)
|
(** Return a [ktree] of the elements of the heap. *)
|
||||||
|
|
||||||
|
val to_string : ?sep:string -> (elt -> string) -> t -> string
|
||||||
|
(** Print the heap in a string
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
val pp : ?sep:string -> elt printer -> t printer
|
val pp : ?sep:string -> elt printer -> t printer
|
||||||
(** Printer.
|
(** Printer.
|
||||||
Renamed from {!print} since 2.0
|
Renamed from {!print} since 2.0
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue