reindentation

This commit is contained in:
Simon Cruanes 2017-01-25 00:03:30 +01:00
parent 416d19a763
commit 03fd42e67d
77 changed files with 1673 additions and 1673 deletions

View file

@ -106,7 +106,7 @@ let sorted cmp a =
(*$= & ~cmp:(=) ~printer:Q.Print.(array int) (*$= & ~cmp:(=) ~printer:Q.Print.(array int)
[||] (sorted Pervasives.compare [||]) [||] (sorted Pervasives.compare [||])
[|0;1;2;3;4|] (sorted Pervasives.compare [|3;2;1;4;0|]) [|0;1;2;3;4|] (sorted Pervasives.compare [|3;2;1;4;0|])
*) *)
(*$Q (*$Q
Q.(array int) (fun a -> \ Q.(array int) (fun a -> \
@ -160,7 +160,7 @@ let rev a =
rev [| 1; 2; 3 |] = [| 3; 2; 1 |] rev [| 1; 2; 3 |] = [| 3; 2; 1 |]
rev [| 1; 2; |] = [| 2; 1 |] rev [| 1; 2; |] = [| 2; 1 |]
rev [| |] = [| |] rev [| |] = [| |]
*) *)
let rec find_aux f a i = let rec find_aux f a i =
if i = Array.length a then None if i = Array.length a then None
@ -588,9 +588,9 @@ end
let sort_generic (type arr)(type elt) let sort_generic (type arr)(type elt)
(module A : MONO_ARRAY with type t = arr and type elt = elt) (module A : MONO_ARRAY with type t = arr and type elt = elt)
?(cmp=Pervasives.compare) a ?(cmp=Pervasives.compare) a
= =
let module S = SortGeneric(A) in let module S = SortGeneric(A) in
S.sort ~cmp a S.sort ~cmp a

View file

@ -267,7 +267,7 @@ let rec _to_klist a i j () =
let reverse_in_place a = _reverse_in_place a.arr a.i ~len:(length a) let reverse_in_place a = _reverse_in_place a.arr a.i ~len:(length a)
(*$T (*$T
let a = 1--6 in let s = make a 2 ~len:3 in \ let a = 1--6 in let s = make a 2 ~len:3 in \
reverse_in_place s; a = [| 1; 2; 5; 4; 3; 6 |] reverse_in_place s; a = [| 1; 2; 5; 4; 3; 6 |]
*) *)
@ -343,7 +343,7 @@ let find_idx p a =
(*$= (*$=
(Some (1,"c")) (find_idx ((=) "c") (make [| "a"; "b"; "c" |] 1 2)) (Some (1,"c")) (find_idx ((=) "c") (make [| "a"; "b"; "c" |] 1 2))
*) *)
let lookup_exn ?(cmp=Pervasives.compare) k a = let lookup_exn ?(cmp=Pervasives.compare) k a =
_lookup_exn ~cmp k a.arr a.i (a.j-1) - a.i _lookup_exn ~cmp k a.arr a.i (a.j-1) - a.i
@ -354,7 +354,7 @@ let lookup ?(cmp=Pervasives.compare) k a =
(*$= (*$=
(Some 1) (lookup "c" (make [| "a"; "b"; "c" |] 1 2)) (Some 1) (lookup "c" (make [| "a"; "b"; "c" |] 1 2))
*) *)
let bsearch ?(cmp=Pervasives.compare) k a = let bsearch ?(cmp=Pervasives.compare) k a =
match bsearch_ ~cmp k a.arr a.i (a.j - 1) with match bsearch_ ~cmp k a.arr a.i (a.j - 1) with
@ -373,7 +373,7 @@ let exists2 p a b =
_exists2 p a.arr b.arr a.i b.i ~len:(min (length a) (length b)) _exists2 p a.arr b.arr a.i b.i ~len:(min (length a) (length b))
(*$T (*$T
exists2 (=) (make [| 1;2;3;4 |] 1 ~len:2) (make [| 0;1;3;4 |] 1 ~len:3) exists2 (=) (make [| 1;2;3;4 |] 1 ~len:2) (make [| 0;1;3;4 |] 1 ~len:3)
*) *)
let _iter2 f a b i j ~len = let _iter2 f a b i j ~len =

View file

@ -2,7 +2,7 @@
(* This file is free software, part of containers. See file "license" for more details. *) (* This file is free software, part of containers. See file "license" for more details. *)
(** {1 Basic Float functions} (** {1 Basic Float functions}
@since 0.6.1 *) @since 0.6.1 *)
type t = float type t = float
type fpclass = Pervasives.fpclass = type fpclass = Pervasives.fpclass =

View file

@ -152,7 +152,7 @@ let tee a b =
Format.fprintf fmt "coucou@."; Format.fprintf fmt "coucou@.";
assert_equal ~printer:CCFun.id "coucou\n" (Buffer.contents buf1); assert_equal ~printer:CCFun.id "coucou\n" (Buffer.contents buf1);
assert_equal ~printer:CCFun.id "coucou\n" (Buffer.contents buf2); assert_equal ~printer:CCFun.id "coucou\n" (Buffer.contents buf2);
*) *)
let to_file filename format = let to_file filename format =
let oc = open_out filename in let oc = open_out filename in

View file

@ -3,7 +3,7 @@
(** {1 Helpers for Format} (** {1 Helpers for Format}
@since 0.8 *) @since 0.8 *)
type 'a sequence = ('a -> unit) -> unit type 'a sequence = ('a -> unit) -> unit

View file

@ -8,22 +8,22 @@
external (|>) : 'a -> ('a -> 'b) -> 'b = "%revapply" external (|>) : 'a -> ('a -> 'b) -> 'b = "%revapply"
external (@@) : ('a -> 'b) -> 'a -> 'b = "%apply" external (@@) : ('a -> 'b) -> 'a -> 'b = "%apply"
#else #else
let (|>) x f = f x let (|>) x f = f x
let (@@) f x = f x let (@@) f x = f x
#endif #endif
#if OCAML_MAJOR >= 4 && OCAML_MINOR >= 3 #if OCAML_MAJOR >= 4 && OCAML_MINOR >= 3
let opaque_identity = Sys.opaque_identity let opaque_identity = Sys.opaque_identity
#else #else
let opaque_identity x = x let opaque_identity x = x
#endif #endif
let compose f g x = g (f x) let compose f g x = g (f x)

View file

@ -73,7 +73,7 @@ val opaque_identity : 'a -> 'a
(** {2 Monad} (** {2 Monad}
Functions with a fixed domain are monads in their codomain *) Functions with a fixed domain are monads in their codomain *)
module Monad(X : sig type t end) : sig module Monad(X : sig type t end) : sig
type 'a t = X.t -> 'a type 'a t = X.t -> 'a

View file

@ -3,7 +3,7 @@
(** {1 Extension to the standard Hashtbl} (** {1 Extension to the standard Hashtbl}
@since 0.4 *) @since 0.4 *)
type 'a sequence = ('a -> unit) -> unit type 'a sequence = ('a -> unit) -> unit
type 'a eq = 'a -> 'a -> bool type 'a eq = 'a -> 'a -> bool

View file

@ -105,8 +105,8 @@ type _ ret_type =
| Ret_bytes : Bytes.t ret_type | Ret_bytes : Bytes.t ret_type
let read_all_ let read_all_
: type a. op:a ret_type -> size:int -> in_channel -> a : type a. op:a ret_type -> size:int -> in_channel -> a
= fun ~op ~size ic -> = fun ~op ~size ic ->
let buf = ref (Bytes.create size) in let buf = ref (Bytes.create size) in
let len = ref 0 in let len = ref 0 in
try try

View file

@ -3,22 +3,22 @@
(** {1 IO Utils} (** {1 IO Utils}
Simple utilities to deal with basic Input/Output tasks in a resource-safe Simple utilities to deal with basic Input/Output tasks in a resource-safe
way. For advanced IO tasks, the user is advised to use something way. For advanced IO tasks, the user is advised to use something
like Lwt or Async, that are far more comprehensive. like Lwt or Async, that are far more comprehensive.
Examples: Examples:
- obtain the list of lines of a file: - obtain the list of lines of a file:
{[ {[
# let l = CCIO.(with_in "/tmp/some_file" read_lines);; # let l = CCIO.(with_in "/tmp/some_file" read_lines);;
]} ]}
- transfer one file into another: - transfer one file into another:
{[ {[
# CCIO.( # CCIO.(
with_in "/tmp/input" with_in "/tmp/input"
(fun ic -> (fun ic ->
let chunks = read_chunks ic in let chunks = read_chunks ic in
@ -27,12 +27,12 @@ Examples:
write_gen oc chunks write_gen oc chunks
) )
) )
) ;; ) ;;
]} ]}
@since 0.6 @since 0.6
@before 0.12 was in 'containers.io', now moved into 'containers' @before 0.12 was in 'containers.io', now moved into 'containers'
*) *)
@ -112,18 +112,18 @@ val tee : ('a -> unit) list -> 'a gen -> 'a gen
(** {2 File and file names} (** {2 File and file names}
How to list recursively files in a directory: How to list recursively files in a directory:
{[ {[
# let files = CCIO.File.read_dir ~recurse:true (CCIO.File.make "/tmp");; # let files = CCIO.File.read_dir ~recurse:true (CCIO.File.make "/tmp");;
# CCIO.write_lines stdout files;; # CCIO.write_lines stdout files;;
]} ]}
See {!File.walk} if you also need to list directories: See {!File.walk} if you also need to list directories:
{[ {[
# let content = CCIO.File.walk (CCIO.File.make "/tmp");; # let content = CCIO.File.walk (CCIO.File.make "/tmp");;
# Gen.map CCIO.File.show_walk_item content |> CCIO.write_lines stdout;; # Gen.map CCIO.File.show_walk_item content |> CCIO.write_lines stdout;;
]} ]}
*) *)
module File : sig module File : sig

View file

@ -769,7 +769,7 @@ let set_at_idx i x l0 =
set_at_idx 0 10 [1;2;3] = [10;2;3] set_at_idx 0 10 [1;2;3] = [10;2;3]
set_at_idx 4 10 [1;2;3] = [1;2;3] set_at_idx 4 10 [1;2;3] = [1;2;3]
set_at_idx 1 10 [1;2;3] = [1;10;3] set_at_idx 1 10 [1;2;3] = [1;10;3]
*) *)
let insert_at_idx i x l = let insert_at_idx i x l =
let rec aux l acc i x = match l with let rec aux l acc i x = match l with
@ -784,7 +784,7 @@ let insert_at_idx i x l =
insert_at_idx 0 10 [1;2;3] = [10;1;2;3] insert_at_idx 0 10 [1;2;3] = [10;1;2;3]
insert_at_idx 4 10 [1;2;3] = [1;2;3;10] insert_at_idx 4 10 [1;2;3] = [1;2;3;10]
insert_at_idx 1 10 [1;2;3] = [1;10;2;3] insert_at_idx 1 10 [1;2;3] = [1;10;2;3]
*) *)
let remove_at_idx i l0 = let remove_at_idx i l0 =
let rec aux l acc i = match l with let rec aux l acc i = match l with
@ -1148,4 +1148,4 @@ let pp ?(start="") ?(stop="") ?(sep=", ") pp_item fmt l =
(CCFormat.to_string \ (CCFormat.to_string \
(CCFormat.hbox(CCList.pp ~start:"[" ~stop:"]" CCFormat.int)) \ (CCFormat.hbox(CCList.pp ~start:"[" ~stop:"]" CCFormat.int)) \
[1;2;3]) [1;2;3])
*) *)

View file

@ -331,7 +331,7 @@ module Assoc : sig
end end
(** {2 References on Lists} (** {2 References on Lists}
@since 0.3.3 *) @since 0.3.3 *)
module Ref : sig module Ref : sig
type 'a t = 'a list ref type 'a t = 'a list ref

View file

@ -331,7 +331,7 @@ module Assoc : sig
end end
(** {2 References on Lists} (** {2 References on Lists}
@since 0.3.3 *) @since 0.3.3 *)
module Ref : sig module Ref : sig
type 'a t = 'a list ref type 'a t = 'a list ref

View file

@ -52,7 +52,7 @@ let option c o1 o2 = match o1, o2 with
(*$Q (*$Q
Q.(option int) (fun o -> option int None o <= 0) Q.(option int) (fun o -> option int None o <= 0)
*) *)
let pair o_x o_y (x1,y1) (x2,y2) = let pair o_x o_y (x1,y1) (x2,y2) =
let c = o_x x1 x2 in let c = o_x x1 x2 in

View file

@ -3,48 +3,48 @@
(** {1 Very Simple Parser Combinators} (** {1 Very Simple Parser Combinators}
{[ {[
open CCParse;; open CCParse;;
type tree = L of int | N of tree * tree;; type tree = L of int | N of tree * tree;;
let mk_leaf x = L x let mk_leaf x = L x
let mk_node x y = N(x,y) let mk_node x y = N(x,y)
let ptree = fix @@ fun self -> let ptree = fix @@ fun self ->
skip_space *> skip_space *>
( (try_ (char '(') *> (pure mk_node <*> self <*> self) <* char ')') ( (try_ (char '(') *> (pure mk_node <*> self <*> self) <* char ')')
<|> <|>
(U.int >|= mk_leaf) ) (U.int >|= mk_leaf) )
;; ;;
parse_string_exn ptree "(1 (2 3))" ;; parse_string_exn ptree "(1 (2 3))" ;;
parse_string_exn ptree "((1 2) (3 (4 5)))" ;; parse_string_exn ptree "((1 2) (3 (4 5)))" ;;
]} ]}
{6 Parse a list of words} {6 Parse a list of words}
{[ {[
open Containers.Parse;; open Containers.Parse;;
let p = U.list ~sep:"," U.word;; let p = U.list ~sep:"," U.word;;
parse_string_exn p "[abc , de, hello ,world ]";; parse_string_exn p "[abc , de, hello ,world ]";;
]} ]}
{6 Stress Test} {6 Stress Test}
This makes a list of 100_000 integers, prints it and parses it back. This makes a list of 100_000 integers, prints it and parses it back.
{[ {[
let p = CCParse.(U.list ~sep:"," U.int);; let p = CCParse.(U.list ~sep:"," U.int);;
let l = CCList.(1 -- 100_000);; let l = CCList.(1 -- 100_000);;
let l_printed = let l_printed =
CCFormat.(to_string (within "[" "]" (list ~sep:(return ",@,") int))) l;; CCFormat.(to_string (within "[" "]" (list ~sep:(return ",@,") int))) l;;
let l' = CCParse.parse_string_exn p l_printed;; let l' = CCParse.parse_string_exn p l_printed;;
assert (l=l');; assert (l=l');;
]} ]}
*) *)
@ -99,7 +99,7 @@ assert (l=l');;
assert_equal ~printer assert_equal ~printer
(Ok ["abc"; "de"; "hello"; "world"]) (Ok ["abc"; "de"; "hello"; "world"])
(parse_string p "[abc , de, hello ,world ]"); (parse_string p "[abc , de, hello ,world ]");
*) *)
(*$R (*$R
let test n = let test n =

View file

@ -3,7 +3,7 @@
(** {1 References} (** {1 References}
@since 0.9 *) @since 0.9 *)
type 'a printer = Format.formatter -> 'a -> unit type 'a printer = Format.formatter -> 'a -> unit
type 'a ord = 'a -> 'a -> int type 'a ord = 'a -> 'a -> int

View file

@ -2,7 +2,7 @@
(* This file is free software, part of containers. See file "license" for more details. *) (* This file is free software, part of containers. See file "license" for more details. *)
(** {1 References} (** {1 References}
@since 0.9 *) @since 0.9 *)
type 'a printer = Format.formatter -> 'a -> unit type 'a printer = Format.formatter -> 'a -> unit
type 'a ord = 'a -> 'a -> int type 'a ord = 'a -> 'a -> int

View file

@ -36,17 +36,17 @@ let compare = String.compare
let hash s = Hashtbl.hash s let hash s = Hashtbl.hash s
#if OCAML_MAJOR >= 4 && OCAML_MINOR >= 2 #if OCAML_MAJOR >= 4 && OCAML_MINOR >= 2
let init = String.init let init = String.init
#else #else
let init n f = let init n f =
let buf = Bytes.init n f in let buf = Bytes.init n f in
Bytes.unsafe_to_string buf Bytes.unsafe_to_string buf
#endif #endif
let length = String.length let length = String.length
@ -580,31 +580,31 @@ let set s i c =
let iter = String.iter let iter = String.iter
#if OCAML_MAJOR >= 4 #if OCAML_MAJOR >= 4
let map = String.map let map = String.map
let iteri = String.iteri let iteri = String.iteri
#else #else
let map f s = init (length s) (fun i -> f s.[i]) let map f s = init (length s) (fun i -> f s.[i])
let iteri f s = let iteri f s =
for i = 0 to String.length s - 1 do for i = 0 to String.length s - 1 do
f i s.[i] f i s.[i]
done done
#endif #endif
#if OCAML_MAJOR >= 4 && OCAML_MINOR >= 2 #if OCAML_MAJOR >= 4 && OCAML_MINOR >= 2
let mapi = String.mapi let mapi = String.mapi
#else #else
let mapi f s = init (length s) (fun i -> f i s.[i]) let mapi f s = init (length s) (fun i -> f i s.[i])
#endif #endif
let filter_map f s = let filter_map f s =
let buf = Buffer.create (String.length s) in let buf = Buffer.create (String.length s) in
@ -677,18 +677,18 @@ let exists2 p s1 s2 =
try iter2 (fun c1 c2 -> if p c1 c2 then raise MyExit) s1 s2; false try iter2 (fun c1 c2 -> if p c1 c2 then raise MyExit) s1 s2; false
with MyExit -> true with MyExit -> true
(** {2 Ascii functions} *) (** {2 Ascii functions} *)
#if OCAML_MAJOR >= 4 && OCAML_MINOR >= 3 #if OCAML_MAJOR >= 4 && OCAML_MINOR >= 3
let capitalize_ascii = String.capitalize_ascii let capitalize_ascii = String.capitalize_ascii
let uncapitalize_ascii = String.uncapitalize_ascii let uncapitalize_ascii = String.uncapitalize_ascii
let uppercase_ascii = String.uppercase_ascii let uppercase_ascii = String.uppercase_ascii
let lowercase_ascii = String.lowercase_ascii let lowercase_ascii = String.lowercase_ascii
#else #else
let capitalize_ascii s = let capitalize_ascii s =
mapi mapi
(fun i c -> if i=0 then CCChar.uppercase_ascii c else c) (fun i c -> if i=0 then CCChar.uppercase_ascii c else c)
s s
@ -703,7 +703,7 @@ let uppercase_ascii = map CCChar.uppercase_ascii
let lowercase_ascii = map CCChar.lowercase_ascii let lowercase_ascii = map CCChar.lowercase_ascii
#endif #endif

View file

@ -3,8 +3,8 @@
(** {1 Basic String Utils} (** {1 Basic String Utils}
Consider using {!Containers_string.KMP} for pattern search, or Regex Consider using {!Containers_string.KMP} for pattern search, or Regex
libraries. *) libraries. *)
type 'a gen = unit -> 'a option type 'a gen = unit -> 'a option
type 'a sequence = ('a -> unit) -> unit type 'a sequence = ('a -> unit) -> unit

View file

@ -309,7 +309,7 @@ let top_exn v =
1 -- 10 |> top = Some 10 1 -- 10 |> top = Some 10
create () |> top = None create () |> top = None
1 -- 10 |> top_exn = 10 1 -- 10 |> top_exn = 10
*) *)
let copy v = { let copy v = {
size = v.size; size = v.size;
@ -398,7 +398,7 @@ let uniq_sort cmp v =
in in
if v.size > 0 if v.size > 0
then traverse v.vec.(0) 1 1 then traverse v.vec.(0) 1 1
(* start at 1, to get the first element in hand *) (* start at 1, to get the first element in hand *)
(*$T (*$T
let v = of_list [1;4;5;3;2;4;1] in \ let v = of_list [1;4;5;3;2;4;1] in \
@ -418,7 +418,7 @@ let iteri k v =
(*$T (*$T
let v = (0--6) in \ let v = (0--6) in \
iteri (fun i x -> if i = 3 then remove v i) v; length v = 6 iteri (fun i x -> if i = 3 then remove v i) v; length v = 6
*) *)
let map f v = let map f v =
if _empty_array v if _empty_array v
@ -431,7 +431,7 @@ let map f v =
(*$T (*$T
let v = create() in push v 1; push v 2; push v 3; \ let v = create() in push v 1; push v 2; push v 3; \
to_list (map string_of_int v) = ["1"; "2"; "3"] to_list (map string_of_int v) = ["1"; "2"; "3"]
*) *)
let filter' p v = let filter' p v =
let i = ref 0 in (* cur element *) let i = ref 0 in (* cur element *)
@ -718,7 +718,7 @@ let to_gen v =
(*$T (*$T
let v = (1--10) in to_list v = Gen.to_list (to_gen v) let v = (1--10) in to_list v = Gen.to_list (to_gen v)
*) *)
let of_klist ?(init=create ()) l = let of_klist ?(init=create ()) l =
let rec aux l = match l() with let rec aux l = match l() with

View file

@ -3,13 +3,13 @@
(** {1 Drop-In replacement to Stdlib} (** {1 Drop-In replacement to Stdlib}
This module is meant to be opened if one doesn't want to use both, say, This module is meant to be opened if one doesn't want to use both, say,
[List] and [CCList]. Instead, [List] is now an alias to [List] and [CCList]. Instead, [List] is now an alias to
{[struct {[struct
include List include List
include CCList include CCList
end end
]} ]}
*) *)
module Array = struct module Array = struct

View file

@ -78,11 +78,11 @@ let cardinal bv =
(*$R (*$R
let bv1 = CCBV.create ~size:87 true in let bv1 = CCBV.create ~size:87 true in
assert_equal ~printer:string_of_int 87 (CCBV.cardinal bv1); assert_equal ~printer:string_of_int 87 (CCBV.cardinal bv1);
*) *)
(*$Q (*$Q
Q.small_int (fun n -> CCBV.cardinal (CCBV.create ~size:n true) = n) Q.small_int (fun n -> CCBV.cardinal (CCBV.create ~size:n true) = n)
*) *)
let is_empty bv = let is_empty bv =
try try
@ -166,7 +166,7 @@ let clear bv =
Array.iteri (fun i _ -> bv.a.(i) <- 0) bv.a Array.iteri (fun i _ -> bv.a.(i) <- 0) bv.a
(*$T (*$T
let bv = create ~size:37 true in cardinal bv = 37 && (clear bv; cardinal bv= 0) let bv = create ~size:37 true in cardinal bv = 37 && (clear bv; cardinal bv= 0)
*) *)
(*$R (*$R
@ -299,7 +299,7 @@ let union bv1 bv2 =
*) *)
(*$T (*$T
union (of_list [1;2;3;4;5]) (of_list [7;3;5;6]) |> to_sorted_list = CCList.range 1 7 union (of_list [1;2;3;4;5]) (of_list [7;3;5;6]) |> to_sorted_list = CCList.range 1 7
*) *)
let inter_into ~into bv = let inter_into ~into bv =

View file

@ -3,9 +3,9 @@
(** {2 Imperative Bitvectors} (** {2 Imperative Bitvectors}
The size of the bitvector is rounded up to the multiple of 30 or 62. The size of the bitvector is rounded up to the multiple of 30 or 62.
In other words some functions such as {!iter} might iterate on more In other words some functions such as {!iter} might iterate on more
bits than what was originally asked for. bits than what was originally asked for.
*) *)
type t type t

View file

@ -99,7 +99,7 @@ let rec all_bits_ acc w =
all_bits_ 0 2 = 3 all_bits_ 0 2 = 3
all_bits_ 0 3 = 7 all_bits_ 0 3 = 7
all_bits_ 0 4 = 15 all_bits_ 0 4 = 15
*) *)
(* increment and return previous value *) (* increment and return previous value *)
let get_then_incr n = let get_then_incr n =

View file

@ -25,28 +25,28 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
(** {1 Caches} (** {1 Caches}
Particularly useful for memoization. See {!with_cache} and {!with_cache_rec} Particularly useful for memoization. See {!with_cache} and {!with_cache_rec}
for more details. for more details.
@since 0.6 *) @since 0.6 *)
type 'a equal = 'a -> 'a -> bool type 'a equal = 'a -> 'a -> bool
type 'a hash = 'a -> int type 'a hash = 'a -> int
(** {2 Value interface} (** {2 Value interface}
Typical use case: one wants to memoize a function [f : 'a -> 'b]. Code sample: Typical use case: one wants to memoize a function [f : 'a -> 'b]. Code sample:
{[ {[
let f x = let f x =
print_endline "call f"; print_endline "call f";
x + 1;; x + 1;;
let f' = with_cache (lru 256) f;; let f' = with_cache (lru 256) f;;
f' 0;; (* prints *) f' 0;; (* prints *)
f' 1;; (* prints *) f' 1;; (* prints *)
f' 0;; (* doesn't print, returns cached value *) f' 0;; (* doesn't print, returns cached value *)
]} ]}
@since 0.6 *) @since 0.6 *)
type ('a, 'b) t type ('a, 'b) t
@ -65,15 +65,15 @@ val with_cache_rec : ('a,'b) t -> (('a -> 'b) -> 'a -> 'b) -> 'a -> 'b
It is similar to {!with_cache} but with a function that takes as It is similar to {!with_cache} but with a function that takes as
first argument its own recursive version. first argument its own recursive version.
Example (memoized Fibonacci function): Example (memoized Fibonacci function):
{[ {[
let fib = with_cache_rec (lru 256) let fib = with_cache_rec (lru 256)
(fun fib' n -> match n with (fun fib' n -> match n with
| 1 | 2 -> 1 | 1 | 2 -> 1
| _ -> fib' (n-1) + fib' (n-2) | _ -> fib' (n-1) + fib' (n-2)
);; );;
fib 70;; fib 70;;
]} ]}
*) *)
val size : (_,_) t -> int val size : (_,_) t -> int

View file

@ -8,7 +8,7 @@ type 'a cell =
| One of 'a | One of 'a
| Two of 'a * 'a | Two of 'a * 'a
| Three of 'a * 'a * 'a | Three of 'a * 'a * 'a
(** A cell holding a small number of elements *) (** A cell holding a small number of elements *)
type 'a node = { type 'a node = {
mutable cell : 'a cell; mutable cell : 'a cell;
@ -112,7 +112,7 @@ let peek_front d = match d.cur.cell with
(*$T (*$T
of_list [1;2;3] |> peek_front = 1 of_list [1;2;3] |> peek_front = 1
try (ignore (of_list [] |> peek_front); false) with Empty -> true try (ignore (of_list [] |> peek_front); false) with Empty -> true
*) *)
(*$R (*$R
let d = of_seq Sequence.(1 -- 10) in let d = of_seq Sequence.(1 -- 10) in
@ -180,7 +180,7 @@ let take_back d =
(*$T (*$T
let q = of_list [1;2;3] in take_back q = 3 && to_list q = [1;2] let q = of_list [1;2;3] in take_back q = 3 && to_list q = [1;2]
*) *)
let take_front_node_ n = match n.cell with let take_front_node_ n = match n.cell with
| Zero -> assert false | Zero -> assert false
@ -190,7 +190,7 @@ let take_front_node_ n = match n.cell with
(*$T (*$T
let q = of_list [1;2;3] in take_front q = 1 && to_list q = [2;3] let q = of_list [1;2;3] in take_front q = 1 && to_list q = [2;3]
*) *)
let take_front d = let take_front d =
if is_empty d then raise Empty if is_empty d then raise Empty
@ -302,7 +302,7 @@ let to_seq d k = iter k d
(*$Q (*$Q
Q.(list int) (fun l -> \ Q.(list int) (fun l -> \
Sequence.of_list l |> of_seq |> to_seq |> Sequence.to_list = l) Sequence.of_list l |> of_seq |> to_seq |> Sequence.to_list = l)
*) *)
let of_list l = let of_list l =
let q = create() in let q = create() in
@ -399,7 +399,7 @@ let compare ?(cmp=Pervasives.compare) a b =
Q.(pair (list int) (list int)) (fun (l1,l2) -> \ Q.(pair (list int) (list int)) (fun (l1,l2) -> \
CCOrd.equiv (compare (of_list l1) (of_list l2)) \ CCOrd.equiv (compare (of_list l1) (of_list l2)) \
(CCList.compare Pervasives.compare l1 l2)) (CCList.compare Pervasives.compare l1 l2))
*) *)
type 'a printer = Format.formatter -> 'a -> unit type 'a printer = Format.formatter -> 'a -> unit

View file

@ -26,9 +26,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
(** {1 Open-Addressing Hash-table} (** {1 Open-Addressing Hash-table}
We use Robin-Hood hashing as described in We use Robin-Hood hashing as described in
http://codecapsule.com/2013/11/17/robin-hood-hashing-backward-shift-deletion/ http://codecapsule.com/2013/11/17/robin-hood-hashing-backward-shift-deletion/
with backward shift. *) with backward shift. *)
type 'a sequence = ('a -> unit) -> unit type 'a sequence = ('a -> unit) -> unit

View file

@ -26,10 +26,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
(** {1 Open-Addressing Hash-table} (** {1 Open-Addressing Hash-table}
This module was previously named [CCHashtbl], but the name is now used for This module was previously named [CCHashtbl], but the name is now used for
an extension of the standard library's hashtables. an extension of the standard library's hashtables.
@since 0.4 *) @since 0.4 *)
type 'a sequence = ('a -> unit) -> unit type 'a sequence = ('a -> unit) -> unit

View file

@ -274,7 +274,7 @@ val scc : ?tbl:('v, 'v scc_state) table ->
Uses {{: https://en.wikipedia.org/wiki/Tarjan's_strongly_connected_components_algorithm} Tarjan's algorithm} Uses {{: https://en.wikipedia.org/wiki/Tarjan's_strongly_connected_components_algorithm} Tarjan's algorithm}
@param tbl table used to map nodes to some hidden state @param tbl table used to map nodes to some hidden state
@raise Sequence_once if the result is iterated on more than once. @raise Sequence_once if the result is iterated on more than once.
*) *)
(** {2 Pretty printing in the DOT (graphviz) format} (** {2 Pretty printing in the DOT (graphviz) format}

View file

@ -179,7 +179,7 @@ let popcount b =
(*$Q (*$Q
Q.int (fun i -> let i = i land (1 lsl 32) in popcount i <= 32) Q.int (fun i -> let i = i land (1 lsl 32) in popcount i <= 32)
*) *)
(* sparse array, using a bitfield and POPCOUNT *) (* sparse array, using a bitfield and POPCOUNT *)
module A_SPARSE = struct module A_SPARSE = struct
@ -281,7 +281,7 @@ end
(** {2 Functors} *) (** {2 Functors} *)
module Make(Key : KEY) module Make(Key : KEY)
: S with type key = Key.t : S with type key = Key.t
= struct = struct
module A = A_SPARSE module A = A_SPARSE

View file

@ -26,7 +26,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
(** {1 Map specialized for Int keys} *) (** {1 Map specialized for Int keys} *)
(* "Fast Mergeable Integer Maps", Okasaki & Gill. (* "Fast Mergeable Integer Maps", Okasaki & Gill.
We use big-endian trees. *) We use big-endian trees. *)
(** Masks with exactly one bit active *) (** Masks with exactly one bit active *)
module Bit : sig module Bit : sig
@ -83,7 +83,7 @@ let is_prefix_ ~prefix y ~bit = prefix = Bit.mask y ~mask:bit
(*$inject (*$inject
let _list_uniq = CCList.sort_uniq ~cmp:(fun a b-> Pervasives.compare (fst a)(fst b)) let _list_uniq = CCList.sort_uniq ~cmp:(fun a b-> Pervasives.compare (fst a)(fst b))
*) *)
(*$Q (*$Q
Q.int (fun i -> \ Q.int (fun i -> \
@ -99,7 +99,7 @@ let is_prefix_ ~prefix y ~bit = prefix = Bit.mask y ~mask:bit
(Bit.highest 2 :> int) = 2 (Bit.highest 2 :> int) = 2
(Bit.highest 17 :> int) = 16 (Bit.highest 17 :> int) = 16
(Bit.highest 300 :> int) = 256 (Bit.highest 300 :> int) = 256
*) *)
(* helper: (* helper:
@ -151,7 +151,7 @@ let rec find_exn k t = match t with
else find_exn k r else find_exn k r
else raise Not_found else raise Not_found
(* XXX could test with lt_unsigned_? *) (* XXX could test with lt_unsigned_? *)
(* (*
if k <= prefix (* search tree *) if k <= prefix (* search tree *)
@ -427,7 +427,7 @@ let to_list t = fold (fun k v l -> (k,v) :: l) t []
(*$Q (*$Q
Q.(list (pair int int)) (fun l -> \ Q.(list (pair int int)) (fun l -> \
of_list l |> cardinal = List.length l) of_list l |> cardinal = List.length l)
*) *)
let add_seq t seq = let add_seq t seq =
let t = ref t in let t = ref t in

View file

@ -25,8 +25,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
(** {1 Map specialized for Int keys} (** {1 Map specialized for Int keys}
{b status: stable} {b status: stable}
@since 0.10 *) @since 0.10 *)
type 'a t type 'a t

View file

@ -6,7 +6,7 @@
module IMap = Map.Make(struct module IMap = Map.Make(struct
type t = int type t = int
let compare : int -> int -> int = compare let compare : int -> int -> int = compare
end) end)
(*$R (*$R
let k1 : int key = newkey () in let k1 : int key = newkey () in

View file

@ -3,34 +3,34 @@
(** {1 Hash Table with Heterogeneous Keys} (** {1 Hash Table with Heterogeneous Keys}
From https://github.com/mjambon/mixtbl (thanks to him). From https://github.com/mjambon/mixtbl (thanks to him).
Example: Example:
{[ {[
let inj_int = CCMixtbl.create_inj () ;; let inj_int = CCMixtbl.create_inj () ;;
let tbl = CCMixtbl.create 10 ;; let tbl = CCMixtbl.create 10 ;;
OUnit.assert_equal None (CCMixtbl.get ~inj:inj_int tbl "a");; OUnit.assert_equal None (CCMixtbl.get ~inj:inj_int tbl "a");;
CCMixtbl.set inj_int tbl "a" 1;; CCMixtbl.set inj_int tbl "a" 1;;
OUnit.assert_equal (Some 1) (CCMixtbl.get ~inj:inj_int tbl "a");; OUnit.assert_equal (Some 1) (CCMixtbl.get ~inj:inj_int tbl "a");;
let inj_string = CCMixtbl.create_inj () ;; let inj_string = CCMixtbl.create_inj () ;;
CCMixtbl.set inj_string tbl "b" "Hello"; CCMixtbl.set inj_string tbl "b" "Hello";
OUnit.assert_equal (Some "Hello") (CCMixtbl.get inj_string tbl "b");; OUnit.assert_equal (Some "Hello") (CCMixtbl.get inj_string tbl "b");;
OUnit.assert_equal None (CCMixtbl.get inj_string tbl "a");; OUnit.assert_equal None (CCMixtbl.get inj_string tbl "a");;
OUnit.assert_equal (Some 1) (CCMixtbl.get inj_int tbl "a");; OUnit.assert_equal (Some 1) (CCMixtbl.get inj_int tbl "a");;
CCMixtbl.set inj_string tbl "a" "Bye";; CCMixtbl.set inj_string tbl "a" "Bye";;
OUnit.assert_equal None (CCMixtbl.get inj_int tbl "a");; OUnit.assert_equal None (CCMixtbl.get inj_int tbl "a");;
OUnit.assert_equal (Some "Bye") (CCMixtbl.get inj_string tbl "a");; OUnit.assert_equal (Some "Bye") (CCMixtbl.get inj_string tbl "a");;
]} ]}
@since 0.6 *) @since 0.6 *)
type 'a t type 'a t
(** A hash table containing values of different types. (** A hash table containing values of different types.

View file

@ -105,10 +105,10 @@ end
module Make(K : OrderedType)(V : OrderedType) : S with type key = K.t and type value = V.t module Make(K : OrderedType)(V : OrderedType) : S with type key = K.t and type value = V.t
(** {2 Two-Way Multimap} (** {2 Two-Way Multimap}
Represents n-to-n mappings between two types. Each element from the "left" Represents n-to-n mappings between two types. Each element from the "left"
is mapped to several right values, and conversely. is mapped to several right values, and conversely.
@since 0.3.3 *) @since 0.3.3 *)
module type BIDIR = sig module type BIDIR = sig
type t type t

View file

@ -159,7 +159,7 @@ let to_gen a =
(*$Q (*$Q
Q.(list int) (fun l -> \ Q.(list int) (fun l -> \
of_list l |> to_gen |> of_gen |> to_list = l) of_list l |> to_gen |> of_gen |> to_list = l)
*) *)
type 'a printer = Format.formatter -> 'a -> unit type 'a printer = Format.formatter -> 'a -> unit

View file

@ -26,11 +26,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
(** {1 Persistent Arrays} (** {1 Persistent Arrays}
From the paper by Jean-Christophe Filliâtre, From the paper by Jean-Christophe Filliâtre,
"A persistent Union-Find data structure", see "A persistent Union-Find data structure", see
{{: https://www.lri.fr/~filliatr/ftp/publis/puf-wml07.ps} the ps version} {{: https://www.lri.fr/~filliatr/ftp/publis/puf-wml07.ps} the ps version}
@since 0.10 *) @since 0.10 *)
type 'a t type 'a t
(** The type of persistent arrays *) (** The type of persistent arrays *)

View file

@ -136,7 +136,7 @@ end
map_same_type _list_uniq map_same_type _list_uniq
(list_of_size Gen.(0 -- 40) (pair small_int small_int)) (list_of_size Gen.(0 -- 40) (pair small_int small_int))
) )
*) *)
(** {2 Implementation} *) (** {2 Implementation} *)

View file

@ -3,12 +3,12 @@
(** {1 Persistent hash-table on top of OCaml's hashtables} (** {1 Persistent hash-table on top of OCaml's hashtables}
Almost as efficient as the regular Hashtbl type, but with a persistent Almost as efficient as the regular Hashtbl type, but with a persistent
interface (rewinding changes to get back in the past history). This is interface (rewinding changes to get back in the past history). This is
mostly useful for backtracking-like uses, or forward uses (never using mostly useful for backtracking-like uses, or forward uses (never using
old values). old values).
This module is not thread-safe. *) This module is not thread-safe. *)
type 'a sequence = ('a -> unit) -> unit type 'a sequence = ('a -> unit) -> unit
type 'a printer = Format.formatter -> 'a -> unit type 'a printer = Format.formatter -> 'a -> unit

View file

@ -44,7 +44,7 @@ let rec set l i v = match l with
| Nil -> invalid_arg "RAL.set" | Nil -> invalid_arg "RAL.set"
| Cons (size,t, l') when i < size -> Cons (size, tree_update_ size t i v, l') | Cons (size,t, l') when i < size -> Cons (size, tree_update_ size t i v, l')
| Cons (size,t, l') -> Cons (size, t, set l' (i - size) v) | Cons (size,t, l') -> Cons (size, t, set l' (i - size) v)
and tree_update_ size t i v =match t, i with and tree_update_ size t i v =match t, i with
| Leaf _, 0 -> Leaf v | Leaf _, 0 -> Leaf v
| Leaf _, _ -> invalid_arg "RAL.set" | Leaf _, _ -> invalid_arg "RAL.set"
| Node (_, t1, t2), 0 -> Node (v, t1, t2) | Node (_, t1, t2), 0 -> Node (v, t1, t2)
@ -456,7 +456,7 @@ let to_list l = fold_rev ~f:(fun acc x -> x :: acc) ~x:[] l
(*$Q (*$Q
Q.(list int) (fun l -> to_list (of_list l) = l) Q.(list int) (fun l -> to_list (of_list l) = l)
*) *)
let add_array l a = Array.fold_right cons a l let add_array l a = Array.fold_right cons a l

View file

@ -572,4 +572,4 @@ end
module Make(X : ORD) = MakeFull(struct module Make(X : ORD) = MakeFull(struct
include X include X
let weight _ = 1 let weight _ = 1
end) end)

View file

@ -24,9 +24,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*) *)
(** {1 Lazy Tree Structure} (** {1 Lazy Tree Structure}
This structure can be used to represent trees and directed This structure can be used to represent trees and directed
graphs (as infinite trees) in a lazy fashion. Like {!CCKList}, it graphs (as infinite trees) in a lazy fashion. Like {!CCKList}, it
is a structural type. *) is a structural type. *)
type 'a sequence = ('a -> unit) -> unit type 'a sequence = ('a -> unit) -> unit
type 'a gen = unit -> 'a option type 'a gen = unit -> 'a option

View file

@ -24,9 +24,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*) *)
(** {1 Lazy Tree Structure} (** {1 Lazy Tree Structure}
This structure can be used to represent trees and directed This structure can be used to represent trees and directed
graphs (as infinite trees) in a lazy fashion. Like {!CCKList}, it graphs (as infinite trees) in a lazy fashion. Like {!CCKList}, it
is a structural type. *) is a structural type. *)
type 'a sequence = ('a -> unit) -> unit type 'a sequence = ('a -> unit) -> unit
type 'a gen = unit -> 'a option type 'a gen = unit -> 'a option
@ -99,8 +99,8 @@ val find : ?pset:'a pset -> ('a -> 'b option) -> 'a t -> 'b option
(** {2 Pretty-printing} (** {2 Pretty-printing}
Example (tree of calls for naive Fibonacci function): Example (tree of calls for naive Fibonacci function):
{[ {[
let mk_fib n = let mk_fib n =
let rec fib' l r i = let rec fib' l r i =
if i=n then r else fib' r (l+r) (i+1) if i=n then r else fib' r (l+r) (i+1)
@ -115,7 +115,7 @@ Example (tree of calls for naive Fibonacci function):
| `Plus n -> Format.fprintf fmt "%d" n;; | `Plus n -> Format.fprintf fmt "%d" n;;
Format.printf "%a@." (CCKTree.print pp_node) (fib 8);; Format.printf "%a@." (CCKTree.print pp_node) (fib 8);;
]} ]}
*) *)
val pp : 'a printer -> 'a t printer val pp : 'a printer -> 'a t printer

View file

@ -10,7 +10,7 @@ type 'a gen = unit -> 'a option
type t = [ type t = [
| `Atom of string | `Atom of string
| `List of t list | `List of t list
] ]
type sexp = t type sexp = t
let equal a b = a = b let equal a b = a = b

View file

@ -12,7 +12,7 @@ type 'a gen = unit -> 'a option
type t = [ type t = [
| `Atom of string | `Atom of string
| `List of t list | `List of t list
] ]
type sexp = t type sexp = t
val equal : t -> t -> bool val equal : t -> t -> bool

View file

@ -3,10 +3,10 @@
(** {1 High-level Functions on top of Unix} (** {1 High-level Functions on top of Unix}
Some useful functions built on top of Unix. Some useful functions built on top of Unix.
{b status: unstable} {b status: unstable}
@since 0.10 *) @since 0.10 *)
type 'a or_error = ('a, string) Result.result type 'a or_error = ('a, string) Result.result
type 'a gen = unit -> 'a option type 'a gen = unit -> 'a option
@ -100,7 +100,7 @@ val async_call : ?env:string array ->
(** {2 Accessors} (** {2 Accessors}
@since 0.11 *) @since 0.11 *)
val stdout : < stdout : 'a; .. > -> 'a val stdout : < stdout : 'a; .. > -> 'a
val stderr : < stderr : 'a; .. > -> 'a val stderr : < stderr : 'a; .. > -> 'a