mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 03:05:28 -05:00
add a printer into CCHeap
This commit is contained in:
parent
903dac110b
commit
ac6900976a
2 changed files with 16 additions and 0 deletions
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
type 'a sequence = ('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]
|
||||
|
||||
|
|
@ -127,6 +128,9 @@ module type S = sig
|
|||
val to_gen : t -> elt gen
|
||||
|
||||
val to_tree : t -> elt ktree
|
||||
|
||||
val print : ?sep:string -> elt printer -> t printer
|
||||
(** @since NEXT_RELEASE *)
|
||||
end
|
||||
|
||||
module Make(E : PARTIAL_ORD) : S with type elt = E.t = struct
|
||||
|
|
@ -273,4 +277,12 @@ module Make(E : PARTIAL_ORD) : S with type elt = E.t = struct
|
|||
let rec to_tree h () = match h with
|
||||
| E -> `Nil
|
||||
| N (_, x, l, r) -> `Node(x, [to_tree l; to_tree r])
|
||||
|
||||
let print ?(sep=",") pp_elt out h =
|
||||
let first=ref true in
|
||||
iter
|
||||
(fun x ->
|
||||
if !first then first := false else Format.fprintf out "%s@," sep;
|
||||
pp_elt out x)
|
||||
h
|
||||
end
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ type 'a sequence = ('a -> unit) -> unit
|
|||
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
|
||||
|
||||
module type PARTIAL_ORD = sig
|
||||
type t
|
||||
|
|
@ -78,6 +79,9 @@ module type S = sig
|
|||
val to_gen : t -> elt gen
|
||||
|
||||
val to_tree : t -> elt ktree
|
||||
|
||||
val print : ?sep:string -> elt printer -> t printer
|
||||
(** @since NEXT_RELEASE *)
|
||||
end
|
||||
|
||||
module Make(E : PARTIAL_ORD) : S with type elt = E.t
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue