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)
[||] (sorted Pervasives.compare [||])
[|0;1;2;3;4|] (sorted Pervasives.compare [|3;2;1;4;0|])
*)
*)
(*$Q
Q.(array int) (fun a -> \
@ -160,7 +160,7 @@ let rev a =
rev [| 1; 2; 3 |] = [| 3; 2; 1 |]
rev [| 1; 2; |] = [| 2; 1 |]
rev [| |] = [| |]
*)
*)
let rec find_aux f a i =
if i = Array.length a then None
@ -588,9 +588,9 @@ end
let sort_generic (type arr)(type elt)
(module A : MONO_ARRAY with type t = arr and type elt = elt)
?(cmp=Pervasives.compare) a
=
(module A : MONO_ARRAY with type t = arr and type elt = elt)
?(cmp=Pervasives.compare) a
=
let module S = SortGeneric(A) in
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)
(*$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 |]
*)
@ -343,7 +343,7 @@ let find_idx p a =
(*$=
(Some (1,"c")) (find_idx ((=) "c") (make [| "a"; "b"; "c" |] 1 2))
*)
*)
let lookup_exn ?(cmp=Pervasives.compare) k a =
_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))
*)
*)
let bsearch ?(cmp=Pervasives.compare) k a =
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))
(*$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 =

View file

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

View file

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

View file

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

View file

@ -8,22 +8,22 @@
external (|>) : 'a -> ('a -> 'b) -> 'b = "%revapply"
external (@@) : ('a -> 'b) -> 'a -> 'b = "%apply"
#else
#else
let (|>) x f = f x
let (|>) x f = 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
#else
#else
let opaque_identity x = x
let opaque_identity x = x
#endif
#endif
let compose f g x = g (f x)

View file

@ -73,7 +73,7 @@ val opaque_identity : 'a -> 'a
(** {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
type 'a t = X.t -> 'a

View file

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

View file

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

View file

@ -3,22 +3,22 @@
(** {1 IO Utils}
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
like Lwt or Async, that are far more comprehensive.
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
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"
(fun ic ->
let chunks = read_chunks ic in
@ -27,12 +27,12 @@ Examples:
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}
How to list recursively files in a directory:
{[
# let files = CCIO.File.read_dir ~recurse:true (CCIO.File.make "/tmp");;
# CCIO.write_lines stdout files;;
]}
How to list recursively files in a directory:
{[
# let files = CCIO.File.read_dir ~recurse:true (CCIO.File.make "/tmp");;
# 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");;
# Gen.map CCIO.File.show_walk_item content |> CCIO.write_lines stdout;;
]}
{[
# let content = CCIO.File.walk (CCIO.File.make "/tmp");;
# Gen.map CCIO.File.show_walk_item content |> CCIO.write_lines stdout;;
]}
*)
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 4 10 [1;2;3] = [1;2;3]
set_at_idx 1 10 [1;2;3] = [1;10;3]
*)
*)
let insert_at_idx i x l =
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 4 10 [1;2;3] = [1;2;3;10]
insert_at_idx 1 10 [1;2;3] = [1;10;2;3]
*)
*)
let remove_at_idx i l0 =
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.hbox(CCList.pp ~start:"[" ~stop:"]" CCFormat.int)) \
[1;2;3])
*)
*)

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -36,17 +36,17 @@ let compare = String.compare
let hash s = Hashtbl.hash s
#if OCAML_MAJOR >= 4 && OCAML_MINOR >= 2
#if OCAML_MAJOR >= 4 && OCAML_MINOR >= 2
let init = String.init
#else
#else
let init n f =
let init n f =
let buf = Bytes.init n f in
Bytes.unsafe_to_string buf
#endif
#endif
let length = String.length
@ -580,31 +580,31 @@ let set s i c =
let iter = String.iter
#if OCAML_MAJOR >= 4
#if OCAML_MAJOR >= 4
let map = String.map
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 =
for i = 0 to String.length s - 1 do
f i s.[i]
done
#endif
#endif
#if OCAML_MAJOR >= 4 && OCAML_MINOR >= 2
#if OCAML_MAJOR >= 4 && OCAML_MINOR >= 2
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 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
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 uncapitalize_ascii = String.uncapitalize_ascii
let uppercase_ascii = String.uppercase_ascii
let lowercase_ascii = String.lowercase_ascii
#else
#else
let capitalize_ascii s =
let capitalize_ascii s =
mapi
(fun i c -> if i=0 then CCChar.uppercase_ascii c else c)
s
@ -703,7 +703,7 @@ let uppercase_ascii = map CCChar.uppercase_ascii
let lowercase_ascii = map CCChar.lowercase_ascii
#endif
#endif

View file

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

View file

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

View file

@ -3,13 +3,13 @@
(** {1 Drop-In replacement to Stdlib}
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
{[struct
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
{[struct
include List
include CCList
end
]}
]}
*)
module Array = struct

View file

@ -78,11 +78,11 @@ let cardinal bv =
(*$R
let bv1 = CCBV.create ~size:87 true in
assert_equal ~printer:string_of_int 87 (CCBV.cardinal bv1);
*)
*)
(*$Q
Q.small_int (fun n -> CCBV.cardinal (CCBV.create ~size:n true) = n)
*)
*)
let is_empty bv =
try
@ -166,7 +166,7 @@ let clear bv =
Array.iteri (fun i _ -> bv.a.(i) <- 0) bv.a
(*$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
@ -299,7 +299,7 @@ let union bv1 bv2 =
*)
(*$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 =

View file

@ -3,9 +3,9 @@
(** {2 Imperative Bitvectors}
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
bits than what was originally asked for.
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
bits than what was originally asked for.
*)
type t

View file

@ -99,7 +99,7 @@ let rec all_bits_ acc w =
all_bits_ 0 2 = 3
all_bits_ 0 3 = 7
all_bits_ 0 4 = 15
*)
*)
(* increment and return previous value *)
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}
Particularly useful for memoization. See {!with_cache} and {!with_cache_rec}
for more details.
@since 0.6 *)
Particularly useful for memoization. See {!with_cache} and {!with_cache_rec}
for more details.
@since 0.6 *)
type 'a equal = 'a -> 'a -> bool
type 'a hash = 'a -> int
(** {2 Value interface}
Typical use case: one wants to memoize a function [f : 'a -> 'b]. Code sample:
{[
let f x =
Typical use case: one wants to memoize a function [f : 'a -> 'b]. Code sample:
{[
let f x =
print_endline "call f";
x + 1;;
let f' = with_cache (lru 256) f;;
f' 0;; (* prints *)
f' 1;; (* prints *)
f' 0;; (* doesn't print, returns cached value *)
]}
let f' = with_cache (lru 256) f;;
f' 0;; (* prints *)
f' 1;; (* prints *)
f' 0;; (* doesn't print, returns cached value *)
]}
@since 0.6 *)
@since 0.6 *)
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
first argument its own recursive version.
Example (memoized Fibonacci function):
{[
let fib = with_cache_rec (lru 256)
{[
let fib = with_cache_rec (lru 256)
(fun fib' n -> match n with
| 1 | 2 -> 1
| _ -> fib' (n-1) + fib' (n-2)
);;
fib 70;;
]}
fib 70;;
]}
*)
val size : (_,_) t -> int

View file

@ -8,7 +8,7 @@ type 'a cell =
| One of 'a
| Two of '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 = {
mutable cell : 'a cell;
@ -112,7 +112,7 @@ let peek_front d = match d.cur.cell with
(*$T
of_list [1;2;3] |> peek_front = 1
try (ignore (of_list [] |> peek_front); false) with Empty -> true
*)
*)
(*$R
let d = of_seq Sequence.(1 -- 10) in
@ -180,7 +180,7 @@ let take_back d =
(*$T
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
| Zero -> assert false
@ -190,7 +190,7 @@ let take_front_node_ n = match n.cell with
(*$T
let q = of_list [1;2;3] in take_front q = 1 && to_list q = [2;3]
*)
*)
let take_front d =
if is_empty d then raise Empty
@ -302,7 +302,7 @@ let to_seq d k = iter k d
(*$Q
Q.(list int) (fun l -> \
Sequence.of_list l |> of_seq |> to_seq |> Sequence.to_list = l)
*)
*)
let of_list l =
let q = create() in
@ -399,7 +399,7 @@ let compare ?(cmp=Pervasives.compare) a b =
Q.(pair (list int) (list int)) (fun (l1,l2) -> \
CCOrd.equiv (compare (of_list l1) (of_list l2)) \
(CCList.compare Pervasives.compare l1 l2))
*)
*)
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}
We use Robin-Hood hashing as described in
http://codecapsule.com/2013/11/17/robin-hood-hashing-backward-shift-deletion/
with backward shift. *)
We use Robin-Hood hashing as described in
http://codecapsule.com/2013/11/17/robin-hood-hashing-backward-shift-deletion/
with backward shift. *)
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}
This module was previously named [CCHashtbl], but the name is now used for
an extension of the standard library's hashtables.
This module was previously named [CCHashtbl], but the name is now used for
an extension of the standard library's hashtables.
@since 0.4 *)
@since 0.4 *)
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}
@param tbl table used to map nodes to some hidden state
@raise Sequence_once if the result is iterated on more than once.
*)
*)
(** {2 Pretty printing in the DOT (graphviz) format}

View file

@ -179,7 +179,7 @@ let popcount b =
(*$Q
Q.int (fun i -> let i = i land (1 lsl 32) in popcount i <= 32)
*)
*)
(* sparse array, using a bitfield and POPCOUNT *)
module A_SPARSE = struct
@ -281,7 +281,7 @@ end
(** {2 Functors} *)
module Make(Key : KEY)
: S with type key = Key.t
: S with type key = Key.t
= struct
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} *)
(* "Fast Mergeable Integer Maps", Okasaki & Gill.
We use big-endian trees. *)
We use big-endian trees. *)
(** Masks with exactly one bit active *)
module Bit : sig
@ -83,7 +83,7 @@ let is_prefix_ ~prefix y ~bit = prefix = Bit.mask y ~mask:bit
(*$inject
let _list_uniq = CCList.sort_uniq ~cmp:(fun a b-> Pervasives.compare (fst a)(fst b))
*)
*)
(*$Q
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 17 :> int) = 16
(Bit.highest 300 :> int) = 256
*)
*)
(* helper:
@ -151,7 +151,7 @@ let rec find_exn k t = match t with
else find_exn k r
else raise Not_found
(* XXX could test with lt_unsigned_? *)
(* XXX could test with lt_unsigned_? *)
(*
if k <= prefix (* search tree *)
@ -427,7 +427,7 @@ let to_list t = fold (fun k v l -> (k,v) :: l) t []
(*$Q
Q.(list (pair int int)) (fun l -> \
of_list l |> cardinal = List.length l)
*)
*)
let add_seq t seq =
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}
{b status: stable}
@since 0.10 *)
{b status: stable}
@since 0.10 *)
type 'a t

View file

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

View file

@ -3,34 +3,34 @@
(** {1 Hash Table with Heterogeneous Keys}
From https://github.com/mjambon/mixtbl (thanks to him).
Example:
From https://github.com/mjambon/mixtbl (thanks to him).
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 None (CCMixtbl.get inj_string tbl "a");;
OUnit.assert_equal (Some 1) (CCMixtbl.get inj_int tbl "a");;
CCMixtbl.set inj_string tbl "a" "Bye";;
OUnit.assert_equal (Some "Hello") (CCMixtbl.get inj_string tbl "b");;
OUnit.assert_equal None (CCMixtbl.get inj_string tbl "a");;
OUnit.assert_equal (Some 1) (CCMixtbl.get inj_int tbl "a");;
CCMixtbl.set inj_string tbl "a" "Bye";;
OUnit.assert_equal None (CCMixtbl.get inj_int tbl "a");;
OUnit.assert_equal (Some "Bye") (CCMixtbl.get inj_string tbl "a");;
]}
OUnit.assert_equal None (CCMixtbl.get inj_int tbl "a");;
OUnit.assert_equal (Some "Bye") (CCMixtbl.get inj_string tbl "a");;
]}
@since 0.6 *)
@since 0.6 *)
type 'a t
(** 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
(** {2 Two-Way Multimap}
Represents n-to-n mappings between two types. Each element from the "left"
is mapped to several right values, and conversely.
Represents n-to-n mappings between two types. Each element from the "left"
is mapped to several right values, and conversely.
@since 0.3.3 *)
@since 0.3.3 *)
module type BIDIR = sig
type t

View file

@ -159,7 +159,7 @@ let to_gen a =
(*$Q
Q.(list int) (fun l -> \
of_list l |> to_gen |> of_gen |> to_list = l)
*)
*)
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}
From the paper by Jean-Christophe Filliâtre,
"A persistent Union-Find data structure", see
{{: https://www.lri.fr/~filliatr/ftp/publis/puf-wml07.ps} the ps version}
From the paper by Jean-Christophe Filliâtre,
"A persistent Union-Find data structure", see
{{: https://www.lri.fr/~filliatr/ftp/publis/puf-wml07.ps} the ps version}
@since 0.10 *)
@since 0.10 *)
type 'a t
(** The type of persistent arrays *)

View file

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

View file

@ -3,12 +3,12 @@
(** {1 Persistent hash-table on top of OCaml's hashtables}
Almost as efficient as the regular Hashtbl type, but with a persistent
interface (rewinding changes to get back in the past history). This is
mostly useful for backtracking-like uses, or forward uses (never using
old values).
Almost as efficient as the regular Hashtbl type, but with a persistent
interface (rewinding changes to get back in the past history). This is
mostly useful for backtracking-like uses, or forward uses (never using
old values).
This module is not thread-safe. *)
This module is not thread-safe. *)
type 'a sequence = ('a -> unit) -> 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"
| 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)
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 _, _ -> invalid_arg "RAL.set"
| 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.(list int) (fun l -> to_list (of_list l) = 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
include X
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}
This structure can be used to represent trees and directed
graphs (as infinite trees) in a lazy fashion. Like {!CCKList}, it
is a structural type. *)
This structure can be used to represent trees and directed
graphs (as infinite trees) in a lazy fashion. Like {!CCKList}, it
is a structural type. *)
type 'a sequence = ('a -> unit) -> unit
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}
This structure can be used to represent trees and directed
graphs (as infinite trees) in a lazy fashion. Like {!CCKList}, it
is a structural type. *)
This structure can be used to represent trees and directed
graphs (as infinite trees) in a lazy fashion. Like {!CCKList}, it
is a structural type. *)
type 'a sequence = ('a -> unit) -> unit
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}
Example (tree of calls for naive Fibonacci function):
{[
Example (tree of calls for naive Fibonacci function):
{[
let mk_fib n =
let rec fib' l r i =
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;;
Format.printf "%a@." (CCKTree.print pp_node) (fib 8);;
]}
]}
*)
val pp : 'a printer -> 'a t printer

View file

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

View file

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

View file

@ -3,10 +3,10 @@
(** {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}
@since 0.10 *)
{b status: unstable}
@since 0.10 *)
type 'a or_error = ('a, string) Result.result
type 'a gen = unit -> 'a option
@ -100,7 +100,7 @@ val async_call : ?env:string array ->
(** {2 Accessors}
@since 0.11 *)
@since 0.11 *)
val stdout : < stdout : 'a; .. > -> 'a
val stderr : < stderr : 'a; .. > -> 'a