mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-07 11:45:31 -05:00
add more printers
This commit is contained in:
parent
b3a527055f
commit
a8c8561a83
8 changed files with 64 additions and 0 deletions
|
|
@ -179,6 +179,7 @@ let blit_of_string a i b j len =
|
||||||
|
|
||||||
type 'a gen = unit -> 'a option
|
type 'a gen = unit -> 'a option
|
||||||
type 'a sequence = ('a -> unit) -> unit
|
type 'a sequence = ('a -> unit) -> unit
|
||||||
|
type 'a printer = Format.formatter -> 'a -> unit
|
||||||
|
|
||||||
let to_seq a k = iter k a
|
let to_seq a k = iter k a
|
||||||
|
|
||||||
|
|
@ -203,6 +204,17 @@ let to_seq_slice a i len =
|
||||||
let to_gen_slice a i len =
|
let to_gen_slice a i len =
|
||||||
to_gen (sub a i len)
|
to_gen (sub a i len)
|
||||||
|
|
||||||
|
let print out s =
|
||||||
|
Format.pp_print_string out "bigstring \"";
|
||||||
|
iter
|
||||||
|
(function
|
||||||
|
| '\n' -> Format.pp_print_string out "\\n"
|
||||||
|
| '\t' -> Format.pp_print_string out "\\t"
|
||||||
|
| '\\' -> Format.pp_print_string out "\\\\"
|
||||||
|
| c -> Format.pp_print_char out c
|
||||||
|
) s;
|
||||||
|
Format.pp_print_char out '"'
|
||||||
|
|
||||||
(** {2 Memory-map} *)
|
(** {2 Memory-map} *)
|
||||||
|
|
||||||
let map_file_descr ?pos ?(shared=false) fd len =
|
let map_file_descr ?pos ?(shared=false) fd len =
|
||||||
|
|
|
||||||
|
|
@ -99,6 +99,7 @@ val blit_of_string : string -> int -> t -> int -> int -> unit
|
||||||
|
|
||||||
type 'a gen = unit -> 'a option
|
type 'a gen = unit -> 'a option
|
||||||
type 'a sequence = ('a -> unit) -> unit
|
type 'a sequence = ('a -> unit) -> unit
|
||||||
|
type 'a printer = Format.formatter -> 'a -> unit
|
||||||
|
|
||||||
val to_seq : t -> char sequence
|
val to_seq : t -> char sequence
|
||||||
|
|
||||||
|
|
@ -108,6 +109,9 @@ val to_seq_slice : t -> int -> int -> char sequence
|
||||||
|
|
||||||
val to_gen_slice : t -> int -> int -> char gen
|
val to_gen_slice : t -> int -> int -> char gen
|
||||||
|
|
||||||
|
val print : t printer
|
||||||
|
(** @since NEXT_RELEASE *)
|
||||||
|
|
||||||
(** {2 Memory-map} *)
|
(** {2 Memory-map} *)
|
||||||
|
|
||||||
val with_map_file :
|
val with_map_file :
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
type 'a sequence = ('a -> unit) -> unit
|
type 'a sequence = ('a -> unit) -> unit
|
||||||
type 'a klist = unit -> [`Nil | `Cons of 'a * 'a klist]
|
type 'a klist = unit -> [`Nil | `Cons of 'a * 'a klist]
|
||||||
type 'a equal = 'a -> 'a -> bool
|
type 'a equal = 'a -> 'a -> bool
|
||||||
|
type 'a printer = Format.formatter -> 'a -> unit
|
||||||
|
|
||||||
(** {2 Basics} *)
|
(** {2 Basics} *)
|
||||||
|
|
||||||
|
|
@ -465,3 +466,13 @@ let (--) a b =
|
||||||
0 -- 0 |> to_list = [0]
|
0 -- 0 |> to_list = [0]
|
||||||
*)
|
*)
|
||||||
|
|
||||||
|
let print pp_x out d =
|
||||||
|
let first = ref true in
|
||||||
|
Format.fprintf out "@[<hov2>queue {";
|
||||||
|
iter
|
||||||
|
(fun x ->
|
||||||
|
if !first then first:= false else Format.fprintf out ";@ ";
|
||||||
|
pp_x out x
|
||||||
|
) d;
|
||||||
|
Format.fprintf out "}@]"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
type 'a sequence = ('a -> unit) -> unit
|
type 'a sequence = ('a -> unit) -> unit
|
||||||
type 'a klist = unit -> [`Nil | `Cons of 'a * 'a klist]
|
type 'a klist = unit -> [`Nil | `Cons of 'a * 'a klist]
|
||||||
type 'a equal = 'a -> 'a -> bool
|
type 'a equal = 'a -> 'a -> bool
|
||||||
|
type 'a printer = Format.formatter -> 'a -> unit
|
||||||
|
|
||||||
(** {2 Basics} *)
|
(** {2 Basics} *)
|
||||||
|
|
||||||
|
|
@ -148,3 +149,5 @@ val (--) : int -> int -> int t
|
||||||
(** [a -- b] is the integer range from [a] to [b], both included.
|
(** [a -- b] is the integer range from [a] to [b], both included.
|
||||||
@since 0.10 *)
|
@since 0.10 *)
|
||||||
|
|
||||||
|
val print : 'a printer -> 'a t printer
|
||||||
|
(** @since NEXT_RELEASE *)
|
||||||
|
|
|
||||||
|
|
@ -274,3 +274,17 @@ let rec as_tree t () = match t with
|
||||||
| L (k, v) -> `Node (`Leaf (k, v), [])
|
| L (k, v) -> `Node (`Leaf (k, v), [])
|
||||||
| N (prefix, switch, l, r) ->
|
| N (prefix, switch, l, r) ->
|
||||||
`Node (`Node (prefix, switch), [as_tree l; as_tree r])
|
`Node (`Node (prefix, switch), [as_tree l; as_tree r])
|
||||||
|
|
||||||
|
type 'a printer = Format.formatter -> 'a -> unit
|
||||||
|
|
||||||
|
let print pp_x out m =
|
||||||
|
Format.fprintf out "@[<hov2>intmap {@,";
|
||||||
|
let first = ref true in
|
||||||
|
iter
|
||||||
|
(fun k v ->
|
||||||
|
if !first then first := false else Format.pp_print_string out ", ";
|
||||||
|
Format.fprintf out "%d -> " k;
|
||||||
|
pp_x out v;
|
||||||
|
Format.pp_print_cut out ()
|
||||||
|
) m;
|
||||||
|
Format.fprintf out "}@]"
|
||||||
|
|
|
||||||
|
|
@ -94,3 +94,9 @@ val highest_bit : int -> int
|
||||||
type 'a tree = unit -> [`Nil | `Node of 'a * 'a tree list]
|
type 'a tree = unit -> [`Nil | `Node of 'a * 'a tree list]
|
||||||
|
|
||||||
val as_tree : 'a t -> [`Node of int * int | `Leaf of int * 'a ] tree
|
val as_tree : 'a t -> [`Node of int * int | `Leaf of int * 'a ] tree
|
||||||
|
|
||||||
|
type 'a printer = Format.formatter -> 'a -> unit
|
||||||
|
|
||||||
|
val print : 'a printer -> 'a t printer
|
||||||
|
(** @since NEXT_RELEASE *)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -89,4 +89,14 @@ let of_seq seq =
|
||||||
seq (fun x -> l := x :: !l);
|
seq (fun x -> l := x :: !l);
|
||||||
of_list (List.rev !l)
|
of_list (List.rev !l)
|
||||||
|
|
||||||
|
type 'a printer = Format.formatter -> 'a -> unit
|
||||||
|
|
||||||
|
let print pp_item out v =
|
||||||
|
Format.fprintf out "[|";
|
||||||
|
iteri
|
||||||
|
(fun i x ->
|
||||||
|
if i > 0 then Format.fprintf out ";@ ";
|
||||||
|
pp_item out x
|
||||||
|
) v;
|
||||||
|
Format.fprintf out "|]"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -102,4 +102,8 @@ val to_seq : 'a t -> 'a sequence
|
||||||
|
|
||||||
val of_seq : 'a sequence -> 'a t
|
val of_seq : 'a sequence -> 'a t
|
||||||
|
|
||||||
|
type 'a printer = Format.formatter -> 'a -> unit
|
||||||
|
|
||||||
|
val print : 'a printer -> 'a t printer
|
||||||
|
(** @since NEXT_RELEASE *)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue