mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
style: reindent
This commit is contained in:
parent
b874ff9bf9
commit
972a6f2720
8 changed files with 77 additions and 77 deletions
|
|
@ -84,7 +84,7 @@ let rev s =
|
||||||
(*$Q
|
(*$Q
|
||||||
Q.printable_string (fun s -> \
|
Q.printable_string (fun s -> \
|
||||||
rev s = (to_list s |> List.rev |> of_list))
|
rev s = (to_list s |> List.rev |> of_list))
|
||||||
*)
|
*)
|
||||||
|
|
||||||
|
|
||||||
(*$=
|
(*$=
|
||||||
|
|
|
||||||
|
|
@ -237,7 +237,7 @@ let of_string s = if is_valid s then Some s else None
|
||||||
let printer s = String.escaped (to_string s)
|
let printer s = String.escaped (to_string s)
|
||||||
let pp_uchar (c:Uchar.t) = Printf.sprintf "0x%x" (Uchar.to_int c)
|
let pp_uchar (c:Uchar.t) = Printf.sprintf "0x%x" (Uchar.to_int c)
|
||||||
|
|
||||||
let uutf_is_valid s =
|
let uutf_is_valid s =
|
||||||
try
|
try
|
||||||
Uutf.String.fold_utf_8
|
Uutf.String.fold_utf_8
|
||||||
(fun () _ -> function
|
(fun () _ -> function
|
||||||
|
|
@ -248,7 +248,7 @@ let uutf_is_valid s =
|
||||||
with Exit ->
|
with Exit ->
|
||||||
false
|
false
|
||||||
|
|
||||||
let uutf_to_seq s f =
|
let uutf_to_seq s f =
|
||||||
Uutf.String.fold_utf_8
|
Uutf.String.fold_utf_8
|
||||||
(fun () _ -> function
|
(fun () _ -> function
|
||||||
| `Malformed _ -> f (Uchar.of_int 0xfffd)
|
| `Malformed _ -> f (Uchar.of_int 0xfffd)
|
||||||
|
|
@ -331,4 +331,4 @@ let uutf_to_seq s f =
|
||||||
else Q.Test.fail_reportf "uutf: '%s', containers: '%s', is_valid %B, uutf_is_valid %B"
|
else Q.Test.fail_reportf "uutf: '%s', containers: '%s', is_valid %B, uutf_is_valid %B"
|
||||||
(pp l_uutf) (pp l_co) (is_valid s) (uutf_is_valid s)
|
(pp l_uutf) (pp l_co) (is_valid s) (uutf_is_valid s)
|
||||||
)
|
)
|
||||||
*)
|
*)
|
||||||
|
|
|
||||||
|
|
@ -46,14 +46,14 @@ module Make(L : OrderedType)(R : OrderedType) = struct
|
||||||
module MapR = Map.Make(R)
|
module MapR = Map.Make(R)
|
||||||
|
|
||||||
type t = {
|
type t = {
|
||||||
left : right MapL.t;
|
left : right MapL.t;
|
||||||
right : left MapR.t;
|
right : left MapR.t;
|
||||||
}
|
}
|
||||||
|
|
||||||
let empty = {
|
let empty = {
|
||||||
left = MapL.empty;
|
left = MapL.empty;
|
||||||
right = MapR.empty;
|
right = MapR.empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
let cardinal m = MapL.cardinal m.left
|
let cardinal m = MapL.cardinal m.left
|
||||||
|
|
||||||
|
|
@ -66,17 +66,17 @@ module Make(L : OrderedType)(R : OrderedType) = struct
|
||||||
let compare a b = MapL.compare R.compare a.left b.left
|
let compare a b = MapL.compare R.compare a.left b.left
|
||||||
|
|
||||||
let add a b m = {
|
let add a b m = {
|
||||||
left =
|
left =
|
||||||
(try let found = MapR.find b m.right in
|
(try let found = MapR.find b m.right in
|
||||||
if L.compare found a <> 0 then MapL.remove found m.left else m.left
|
if L.compare found a <> 0 then MapL.remove found m.left else m.left
|
||||||
with Not_found -> m.left)
|
with Not_found -> m.left)
|
||||||
|> MapL.add a b;
|
|> MapL.add a b;
|
||||||
right =
|
right =
|
||||||
(try let found = MapL.find a m.left in
|
(try let found = MapL.find a m.left in
|
||||||
if R.compare found b <> 0 then MapR.remove found m.right else m.right
|
if R.compare found b <> 0 then MapR.remove found m.right else m.right
|
||||||
with Not_found -> m.right)
|
with Not_found -> m.right)
|
||||||
|> MapR.add b a;
|
|> MapR.add b a;
|
||||||
}
|
}
|
||||||
|
|
||||||
let find_left key m = MapL.find key m.left
|
let find_left key m = MapL.find key m.left
|
||||||
let find_right key m = MapR.find key m.right
|
let find_right key m = MapR.find key m.right
|
||||||
|
|
|
||||||
|
|
@ -28,8 +28,8 @@ module type S = sig
|
||||||
|
|
||||||
val add : left -> right -> t -> t
|
val add : left -> right -> t -> t
|
||||||
(** Add [left] and [right] correspondence to bijection such that
|
(** Add [left] and [right] correspondence to bijection such that
|
||||||
[left] and [right] are unique in their respective sets and only
|
[left] and [right] are unique in their respective sets and only
|
||||||
correspond to each other. *)
|
correspond to each other. *)
|
||||||
|
|
||||||
val cardinal : t -> int
|
val cardinal : t -> int
|
||||||
(** Number of bindings. O(n) time *)
|
(** Number of bindings. O(n) time *)
|
||||||
|
|
@ -51,7 +51,7 @@ module type S = sig
|
||||||
|
|
||||||
val remove : left -> right -> t -> t
|
val remove : left -> right -> t -> t
|
||||||
(** Removes the [left], [right] binding if it exists. Returns the
|
(** Removes the [left], [right] binding if it exists. Returns the
|
||||||
same bijection otherwise. *)
|
same bijection otherwise. *)
|
||||||
|
|
||||||
val remove_left : left -> t -> t
|
val remove_left : left -> t -> t
|
||||||
(** Remove the binding with [left] key if it exists. Returns the
|
(** Remove the binding with [left] key if it exists. Returns the
|
||||||
|
|
|
||||||
|
|
@ -19,17 +19,17 @@ type 'a printer = Format.formatter -> 'a -> unit
|
||||||
type 'a ktree = unit -> [`Nil | `Node of 'a * 'a ktree list]
|
type 'a ktree = unit -> [`Nil | `Node of 'a * 'a ktree list]
|
||||||
|
|
||||||
(* TODO
|
(* TODO
|
||||||
(** {2 Transient IDs} *)
|
(** {2 Transient IDs} *)
|
||||||
module Transient = struct
|
module Transient = struct
|
||||||
type state = { mutable frozen: bool }
|
type state = { mutable frozen: bool }
|
||||||
type t = Nil | St of state
|
type t = Nil | St of state
|
||||||
let empty = Nil
|
let empty = Nil
|
||||||
let equal a b = Pervasives.(==) a b
|
let equal a b = Pervasives.(==) a b
|
||||||
let create () = St {frozen=false}
|
let create () = St {frozen=false}
|
||||||
let active = function Nil -> false | St st -> not st.frozen
|
let active = function Nil -> false | St st -> not st.frozen
|
||||||
let frozen = function Nil -> true | St st -> st.frozen
|
let frozen = function Nil -> true | St st -> st.frozen
|
||||||
let freeze = function Nil -> () | St st -> st.frozen <- true
|
let freeze = function Nil -> () | St st -> st.frozen <- true
|
||||||
let with_ f =
|
let with_ f =
|
||||||
let r = create() in
|
let r = create() in
|
||||||
try
|
try
|
||||||
let x = f r in
|
let x = f r in
|
||||||
|
|
@ -38,9 +38,9 @@ module Transient = struct
|
||||||
with e ->
|
with e ->
|
||||||
freeze r;
|
freeze r;
|
||||||
raise e
|
raise e
|
||||||
exception Frozen
|
exception Frozen
|
||||||
end
|
end
|
||||||
*)
|
*)
|
||||||
|
|
||||||
(* function array *)
|
(* function array *)
|
||||||
module A = struct
|
module A = struct
|
||||||
|
|
@ -133,7 +133,7 @@ type 'a t = {
|
||||||
(forall j>=i, sub[j].size<32^{n+1}-1)]
|
(forall j>=i, sub[j].size<32^{n+1}-1)]
|
||||||
(prefix of subs has size of complete binary tree; suffix has
|
(prefix of subs has size of complete binary tree; suffix has
|
||||||
smaller size (actually decreasing))
|
smaller size (actually decreasing))
|
||||||
*)
|
*)
|
||||||
|
|
||||||
|
|
||||||
let empty = {size=0; leaves=A.empty; subs=A.empty}
|
let empty = {size=0; leaves=A.empty; subs=A.empty}
|
||||||
|
|
@ -290,7 +290,7 @@ let rec map f m : _ t =
|
||||||
let f = Q.Fn.apply f in
|
let f = Q.Fn.apply f in
|
||||||
(List.map f l) = (of_list l |> map f |> to_list)
|
(List.map f l) = (of_list l |> map f |> to_list)
|
||||||
)
|
)
|
||||||
*)
|
*)
|
||||||
|
|
||||||
let append a b =
|
let append a b =
|
||||||
if is_empty b then a
|
if is_empty b then a
|
||||||
|
|
@ -300,7 +300,7 @@ let append a b =
|
||||||
Q.(pair (small_list int)(small_list int)) (fun (l1,l2) ->
|
Q.(pair (small_list int)(small_list int)) (fun (l1,l2) ->
|
||||||
(l1 @ l2) = (append (of_list l1)(of_list l2) |> to_list)
|
(l1 @ l2) = (append (of_list l1)(of_list l2) |> to_list)
|
||||||
)
|
)
|
||||||
*)
|
*)
|
||||||
|
|
||||||
let add_list v l = List.fold_left (fun v x -> push x v) v l
|
let add_list v l = List.fold_left (fun v x -> push x v) v l
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,37 +16,37 @@ type 'a printer = Format.formatter -> 'a -> unit
|
||||||
type 'a ktree = unit -> [`Nil | `Node of 'a * 'a ktree list]
|
type 'a ktree = unit -> [`Nil | `Node of 'a * 'a ktree list]
|
||||||
|
|
||||||
(* TODO: restore this
|
(* TODO: restore this
|
||||||
(** {2 Transient Identifiers} *)
|
(** {2 Transient Identifiers} *)
|
||||||
module Transient : sig
|
module Transient : sig
|
||||||
type t
|
type t
|
||||||
(** Identifiers for transient modifications. A transient modification
|
(** Identifiers for transient modifications. A transient modification
|
||||||
is uniquely identified by a [Transient.t]. Once [Transient.freeze r]
|
is uniquely identified by a [Transient.t]. Once [Transient.freeze r]
|
||||||
is called, [r] cannot be used to modify the structure again. *)
|
is called, [r] cannot be used to modify the structure again. *)
|
||||||
|
|
||||||
val create : unit -> t
|
val create : unit -> t
|
||||||
(** Create a new, active ID. *)
|
(** Create a new, active ID. *)
|
||||||
|
|
||||||
val equal : t -> t -> bool
|
val equal : t -> t -> bool
|
||||||
(** Equality between IDs. *)
|
(** Equality between IDs. *)
|
||||||
|
|
||||||
val frozen : t -> bool
|
val frozen : t -> bool
|
||||||
(** [frozen i] returns [true] if [freeze i] was called before. In this case,
|
(** [frozen i] returns [true] if [freeze i] was called before. In this case,
|
||||||
the ID cannot be used for modifications again. *)
|
the ID cannot be used for modifications again. *)
|
||||||
|
|
||||||
val active : t -> bool
|
val active : t -> bool
|
||||||
(** [active i] is [not (frozen i)]. *)
|
(** [active i] is [not (frozen i)]. *)
|
||||||
|
|
||||||
val freeze : t -> unit
|
val freeze : t -> unit
|
||||||
(** [freeze i] makes [i] unusable for new modifications. The values
|
(** [freeze i] makes [i] unusable for new modifications. The values
|
||||||
created with [i] will now be immutable. *)
|
created with [i] will now be immutable. *)
|
||||||
|
|
||||||
val with_ : (t -> 'a) -> 'a
|
val with_ : (t -> 'a) -> 'a
|
||||||
(** [with_ f] creates a transient ID [i], calls [f i],
|
(** [with_ f] creates a transient ID [i], calls [f i],
|
||||||
freezes the ID [i] and returns the result of [f i]. *)
|
freezes the ID [i] and returns the result of [f i]. *)
|
||||||
|
|
||||||
exception Frozen
|
exception Frozen
|
||||||
(** Raised when a frozen ID is used. *)
|
(** Raised when a frozen ID is used. *)
|
||||||
end
|
end
|
||||||
*)
|
*)
|
||||||
|
|
||||||
(** {2 Signature} *)
|
(** {2 Signature} *)
|
||||||
|
|
@ -92,19 +92,19 @@ val choose : 'a t -> 'a option
|
||||||
|
|
||||||
(* TODO
|
(* TODO
|
||||||
|
|
||||||
val push_mut : id:Transient.t -> 'a -> 'a t -> 'a t
|
val push_mut : id:Transient.t -> 'a -> 'a t -> 'a t
|
||||||
(** [add_mut ~id k v m] behaves like [add k v m], except it will mutate
|
(** [add_mut ~id k v m] behaves like [add k v m], except it will mutate
|
||||||
in place whenever possible. Changes done with an [id] might affect all
|
in place whenever possible. Changes done with an [id] might affect all
|
||||||
versions of the structure obtained with the same [id] (but not
|
versions of the structure obtained with the same [id] (but not
|
||||||
other versions).
|
other versions).
|
||||||
@raise Transient.Frozen if [id] is frozen. *)
|
@raise Transient.Frozen if [id] is frozen. *)
|
||||||
|
|
||||||
val pop_mut : id:Transient.t -> 'a t -> 'a * 'a t
|
val pop_mut : id:Transient.t -> 'a t -> 'a * 'a t
|
||||||
(** Same as {!remove}, but modifies in place whenever possible.
|
(** Same as {!remove}, but modifies in place whenever possible.
|
||||||
@raise Transient.Frozen if [id] is frozen. *)
|
@raise Transient.Frozen if [id] is frozen. *)
|
||||||
|
|
||||||
val append_mut : id:Transient.t -> into:'a t -> 'a t -> 'a t
|
val append_mut : id:Transient.t -> into:'a t -> 'a t -> 'a t
|
||||||
*)
|
*)
|
||||||
|
|
||||||
(** {6 Conversions} *)
|
(** {6 Conversions} *)
|
||||||
|
|
||||||
|
|
@ -128,15 +128,15 @@ val to_gen : 'a t -> 'a gen
|
||||||
|
|
||||||
(* TODO
|
(* TODO
|
||||||
|
|
||||||
val add_list_mut : id:Transient.t -> 'a t -> 'a list -> 'a t
|
val add_list_mut : id:Transient.t -> 'a t -> 'a list -> 'a t
|
||||||
(** @raise Frozen if the ID is frozen. *)
|
(** @raise Frozen if the ID is frozen. *)
|
||||||
|
|
||||||
val add_seq_mut : id:Transient.t -> 'a t -> 'a sequence -> 'a t
|
val add_seq_mut : id:Transient.t -> 'a t -> 'a sequence -> 'a t
|
||||||
(** @raise Frozen if the ID is frozen. *)
|
(** @raise Frozen if the ID is frozen. *)
|
||||||
|
|
||||||
val add_gen_mut : id:Transient.t -> 'a t -> 'a gen -> 'a t
|
val add_gen_mut : id:Transient.t -> 'a t -> 'a gen -> 'a t
|
||||||
(** @raise Frozen if the ID is frozen. *)
|
(** @raise Frozen if the ID is frozen. *)
|
||||||
*)
|
*)
|
||||||
|
|
||||||
(** {6 IO} *)
|
(** {6 IO} *)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -84,10 +84,10 @@ let rec flat_map ~f l =
|
||||||
|
|
||||||
let default ~default l =
|
let default ~default l =
|
||||||
lazy (
|
lazy (
|
||||||
match l with
|
match l with
|
||||||
| lazy Nil -> Lazy.force default
|
| lazy Nil -> Lazy.force default
|
||||||
| lazy l -> l
|
| lazy l -> l
|
||||||
)
|
)
|
||||||
|
|
||||||
(*$=
|
(*$=
|
||||||
[1] (default (return 1) empty |> to_list)
|
[1] (default (return 1) empty |> to_list)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue