Skip to content

Commit

Permalink
Add of_list in Set.Make
Browse files Browse the repository at this point in the history
  • Loading branch information
kit-ty-kate committed Mar 3, 2014
1 parent b18ccaf commit ad55dda
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/batSet.ml
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ module Concrete = struct
let of_enum cmp e =
BatEnum.fold (fun acc elem -> add cmp elem acc) empty e

let of_list cmp l = List.fold_left (fun a x -> add cmp x a) empty l

let print ?(first="{") ?(last="}") ?(sep=",") print_elt out t =
BatEnum.print ~first ~last ~sep (fun out e -> BatPrintf.fprintf out "%a" print_elt e) out (enum t)

Expand Down Expand Up @@ -481,6 +483,7 @@ sig
val enum: t -> elt BatEnum.t
val backwards: t -> elt BatEnum.t
val of_enum: elt BatEnum.t -> t
val of_list: elt list -> t
val print : ?first:string -> ?last:string -> ?sep:string ->
('a BatInnerIO.output -> elt -> unit) ->
'a BatInnerIO.output -> t -> unit
Expand Down Expand Up @@ -597,6 +600,8 @@ struct

let compare_subset s1 s2 = compare_subset (impl_of_t s1) s2

let of_list l = t_of_impl (Concrete.of_list Ord.compare l)

let print ?first ?last ?sep print_elt out t =
Concrete.print ?first ?last ?sep print_elt out (impl_of_t t)

Expand Down Expand Up @@ -663,7 +668,7 @@ module PSet = struct (*$< PSet *)
let enum s = Concrete.enum s.set
let of_enum e = { cmp = compare; set = Concrete.of_enum compare e }
let of_enum_cmp ~cmp t = { cmp = cmp; set = Concrete.of_enum cmp t }
let of_list l = List.fold_left (fun a x -> add x a) empty l
let of_list l = { cmp = compare; set = Concrete.of_list compare l }
let print ?first ?last ?sep print_elt out s =
Concrete.print ?first ?last ?sep print_elt out s.set
let for_all f s = Concrete.for_all f s.set
Expand Down Expand Up @@ -776,7 +781,7 @@ let of_enum e = Concrete.of_enum Pervasives.compare e

let backwards s = Concrete.backwards s

let of_list l = List.fold_left (fun a x -> add x a) empty l
let of_list l = Concrete.of_list Pervasives.compare l

(*$Q of_list
(Q.list Q.small_int) (fun l -> let xs = List.map (fun i -> i mod 5, i) l in \
Expand Down
8 changes: 6 additions & 2 deletions src/batSet.mli
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,12 @@ sig

val of_enum: elt BatEnum.t -> t

val of_list: elt list -> t
(** builds a set from the given list.
@since NEXT_RELEASE
*)


(** {6 Boilerplate code}*)

Expand Down Expand Up @@ -514,7 +520,6 @@ val backwards: 'a t -> 'a BatEnum.t
the ordering [Pervasives.compare]. *)


(* of_list has no Set.Make counterpart *)
val of_list: 'a list -> 'a t
(** builds a set from the given list, using the default comparison
function *)
Expand Down Expand Up @@ -738,7 +743,6 @@ module PSet : sig

val of_enum_cmp: cmp:('a -> 'a -> int) -> 'a BatEnum.t -> 'a t

(* of_list has no Set.Make counterpart *)
val of_list: 'a list -> 'a t
(** builds a set from the given list, using the default comparison
function *)
Expand Down

0 comments on commit ad55dda

Please sign in to comment.