mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-05 19:00:31 -05:00
forgot to update examples/
This commit is contained in:
parent
2033f07aff
commit
7ed1bced9d
5 changed files with 20 additions and 28 deletions
|
|
@ -6,4 +6,4 @@
|
|||
#load "containers.cma";;
|
||||
#require "threads";;
|
||||
#load "thread_containers.cma";;
|
||||
open Enum.Infix;;
|
||||
open Gen.Infix;;
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ let collatz n filename =
|
|||
Format.printf "print graph to %s@." filename;
|
||||
let out = open_out filename in
|
||||
let fmt = Format.formatter_of_out_channel out in
|
||||
LazyGraph.Dot.pp ~name:"collatz" g fmt (Enum.singleton n);
|
||||
LazyGraph.Dot.pp ~name:"collatz" g fmt (Gen.singleton n);
|
||||
Format.pp_print_flush fmt ();
|
||||
close_out out
|
||||
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
(** Compute the memory footprint of a value (and its subvalues). Reference is
|
||||
http://rwmj.wordpress.com/2009/08/05/ocaml-internals-part-2-strings-and-other-types/ *)
|
||||
|
||||
open Enum.Infix
|
||||
open Gen.Infix
|
||||
|
||||
(** A graph vertex is an Obj.t value *)
|
||||
let graph =
|
||||
let force x =
|
||||
if Obj.is_block x
|
||||
then
|
||||
let children = Enum.map (fun i -> i, Obj.field x i) (0--(Obj.size x - 1)) in
|
||||
let children = Gen.map (fun i -> i, Obj.field x i) (0--(Obj.size x - 1)) in
|
||||
LazyGraph.Node (x, Obj.tag x, children)
|
||||
else
|
||||
LazyGraph.Node (x, Obj.obj x, Enum.empty)
|
||||
LazyGraph.Node (x, Obj.obj x, Gen.empty)
|
||||
in LazyGraph.make ~eq:(==) force
|
||||
|
||||
let word_size = Sys.word_size / 8
|
||||
|
|
@ -24,13 +24,13 @@ let size x =
|
|||
let compute_size x =
|
||||
let o = Obj.repr x in
|
||||
let vertices = LazyGraph.bfs graph o in
|
||||
Enum.fold (fun sum (o',_,_) -> size o' + sum) 0 vertices
|
||||
Gen.fold (fun sum (o',_,_) -> size o' + sum) 0 vertices
|
||||
|
||||
let print_val fmt x =
|
||||
let o = Obj.repr x in
|
||||
let graph' = LazyGraph.map ~edges:(fun i -> [`Label (string_of_int i)])
|
||||
~vertices:(fun v -> [`Label (string_of_int v); `Shape "box"]) graph in
|
||||
LazyGraph.Dot.pp ~name:"value" graph' fmt (Enum.singleton o)
|
||||
LazyGraph.Dot.pp ~name:"value" graph' fmt (Gen.singleton o)
|
||||
|
||||
let print_val_file filename x =
|
||||
let out = open_out filename in
|
||||
|
|
@ -46,7 +46,7 @@ let process_val ~name x =
|
|||
module ISet = Set.Make(struct type t = int let compare = compare end)
|
||||
|
||||
let mk_circ n =
|
||||
let start = Enum.to_list (1--n) in
|
||||
let start = Gen.to_list (1--n) in
|
||||
(* make the end of the list point to its beginning *)
|
||||
let rec cycle l = match l with
|
||||
| [] -> assert false
|
||||
|
|
@ -57,10 +57,10 @@ let mk_circ n =
|
|||
start
|
||||
|
||||
let _ =
|
||||
let s = Enum.fold (fun s x -> ISet.add x s) ISet.empty (1--100) in
|
||||
let s = Gen.fold (fun s x -> ISet.add x s) ISet.empty (1--100) in
|
||||
process_val ~name:"foo" s;
|
||||
let l = Enum.to_list (Enum.map (fun i -> Enum.to_list (i--(i+42)))
|
||||
(Enum.of_list [0;100;1000])) in
|
||||
let l = Gen.to_list (Gen.map (fun i -> Gen.to_list (i--(i+42)))
|
||||
(Gen.of_list [0;100;1000])) in
|
||||
process_val ~name:"bar" l;
|
||||
let l' = mk_circ 100 in
|
||||
process_val ~name:"baaz" l';
|
||||
|
|
|
|||
10
gen.ml
10
gen.ml
|
|
@ -798,14 +798,6 @@ let pp ?(start="") ?(stop="") ?(sep=",") ?(horizontal=false) pp_elem formatter e
|
|||
next true;
|
||||
Format.fprintf formatter "%s@]" stop
|
||||
|
||||
let (@@) = append
|
||||
|
||||
let (>>=) e f = flatMap f e
|
||||
|
||||
let (--) = int_range
|
||||
|
||||
let (|>) x f = f x
|
||||
|
||||
module Infix = struct
|
||||
let (@@) = append
|
||||
|
||||
|
|
@ -815,3 +807,5 @@ module Infix = struct
|
|||
|
||||
let (|>) x f = f x
|
||||
end
|
||||
|
||||
include Infix
|
||||
|
|
|
|||
16
gen.mli
16
gen.mli
|
|
@ -278,15 +278,6 @@ val pp : ?start:string -> ?stop:string -> ?sep:string -> ?horizontal:bool ->
|
|||
(Format.formatter -> 'a -> unit) -> Format.formatter -> 'a t -> unit
|
||||
(** Pretty print an enum *)
|
||||
|
||||
|
||||
val (@@) : 'a t -> 'a t -> 'a t
|
||||
|
||||
val (>>=) : 'a t -> ('a -> 'b t) -> 'b t
|
||||
|
||||
val (--) : int -> int -> int t
|
||||
|
||||
val (|>) : 'a -> ('a -> 'b) -> 'b
|
||||
|
||||
module Infix : sig
|
||||
val (@@) : 'a t -> 'a t -> 'a t
|
||||
|
||||
|
|
@ -297,3 +288,10 @@ module Infix : sig
|
|||
val (|>) : 'a -> ('a -> 'b) -> 'b
|
||||
end
|
||||
|
||||
val (@@) : 'a t -> 'a t -> 'a t
|
||||
|
||||
val (>>=) : 'a t -> ('a -> 'b t) -> 'b t
|
||||
|
||||
val (--) : int -> int -> int t
|
||||
|
||||
val (|>) : 'a -> ('a -> 'b) -> 'b
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue