@ -5,48 +5,40 @@
* LICENSE file in the root directory of this source tree .
* LICENSE file in the root directory of this source tree .
* )
* )
open Import0
include Set_intf
include Set_intf
module Make ( Elt : OrderedType ) : S with type elt = Elt . t = struct
module Make ( Elt : sig
module S = Caml . Set . Make ( Elt )
type t [ @@ deriving compare , sexp_of ]
end ) : S with type elt = Elt . t = struct
module EltSet = Core . Set . Make_plain ( Elt )
module Elt = EltSet . Elt
type elt = Elt . t
type elt = Elt . t
type t = S . t
let compare = S . compare
include EltSet . Tree
let equal = S . equal
let sexp_of_t s = List . sexp_of_t Elt . sexp_of_t ( S . elements s )
let t_of_sexp elt_of_sexp sexp =
let pp pp_elt fs x = List . pp " ,@ " pp_elt fs ( elements x )
S . of_list ( List . t_of_sexp elt_of_sexp sexp )
let pp pp_elt fs x = List . pp " ,@ " pp_elt fs ( S . elements x )
let pp_diff pp_elt fs ( xs , ys ) =
let pp_diff pp_elt fs ( xs , ys ) =
let lose = S . diff xs ys and gain = S . diff ys xs in
let lose = diff xs ys and gain = diff ys xs in
if not ( S . is_empty lose ) then Format . fprintf fs " -- %a " ( pp pp_elt ) lose ;
if not ( is_empty lose ) then Format . fprintf fs " -- %a " ( pp pp_elt ) lose ;
if not ( S . is_empty gain ) then Format . fprintf fs " ++ %a " ( pp pp_elt ) gain
if not ( is_empty gain ) then Format . fprintf fs " ++ %a " ( pp pp_elt ) gain
let empty = S . empty
let of_ x = add empty x
let of_ x = S . add x empty
let of_option = Option . fold ~ f : add ~ init : empty
let of_option = Option . fold ~ f : ( fun x y -> S . add y x ) ~ init : empty
let of_iarray a = of_array ( IArray . to_array a )
let of_list = S . of_list
let add_option xo s = Option . fold ~ f : add ~ init : s xo
let of_vector x = S . of_list ( IArray . to_list x )
let add_list xs s = List . fold ~ f : add ~ init : s xs
let add s e = S . add e s
let diff_inter s t = ( diff s t , inter s t )
let add_option yo x = Option . fold ~ f : ( fun x y -> S . add y x ) ~ init : x yo
let add_list ys x = List . fold ~ f : ( fun x y -> S . add y x ) ~ init : x ys
let rec disjoint s1 s2 =
let remove s e = S . remove e s
match choose s1 with
let filter s ~ f = S . filter f s
| None -> true
let union = S . union
| _ when is_empty s2 -> true
let union_list ss = List . fold ss ~ init : empty ~ f : union
| _ when s1 = = s2 -> false
let diff = S . diff
| Some x -> (
let inter = S . inter
let l1 , _ , r1 = split s1 x in
let diff_inter x y = ( S . diff x y , S . inter x y )
match split s2 x with
let is_empty = S . is_empty
| _ , Some _ , _ -> false
let mem s e = S . mem e s
| l2 , None , r2 -> disjoint l1 l2 && disjoint r1 r2 )
let is_subset x ~ of_ = S . subset x of_
let disjoint = S . disjoint
let max_elt = S . max_elt_opt
let fold s ~ init : z ~ f = S . fold ( fun z x -> f x z ) s z
end
end