123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208(* This file is free software, part of containers. See file "license" for more details. *)(** {1 Wrapper around Set} *)type'aiter=('a->unit)->unittype'aprinter=Format.formatter->'a->unitmoduletypeOrderedType=Set.OrderedTypemoduletypeS=sigincludeSet.Svalmin_elt_opt:t->eltoption(** Safe version of {!min_elt}.
@since 1.5 *)valmax_elt_opt:t->eltoption(** Safe version of {!max_elt}.
@since 1.5 *)valchoose_opt:t->eltoption(** Safe version of {!choose}.
@since 1.5 *)valfind_opt:elt->t->eltoption(** Safe version of {!find}.
@since 1.5 *)valfind_first:(elt->bool)->t->elt(** Find minimum element satisfying predicate.
@since 1.5 *)valfind_first_opt:(elt->bool)->t->eltoption(** Safe version of {!find_first}.
@since 1.5 *)valfind_first_map:(elt->'aoption)->t->'aoption(** [find_first_map f s] find the minimum element [x] of [s] such that [f x = Some y]
and return [Some y]. Otherwise returns [None].
@since 3.12 *)valfind_last:(elt->bool)->t->elt(** Find maximum element satisfying predicate.
@since 1.5 *)valfind_last_opt:(elt->bool)->t->eltoption(** Safe version of {!find_last}.
@since 1.5 *)valfind_last_map:(elt->'aoption)->t->'aoption(** [find_last_map f s] find the maximum element [x] of [s] such that [f x = Some y]
and return [Some y]. Otherwise returns [None].
@since 3.12 *)valof_iter:eltiter->t(** Build a set from the given [iter] of elements.
@since 2.8 *)valof_seq:eltSeq.t->t(** Build a set from the given [seq] of elements.
@since 3.0 *)valadd_iter:t->eltiter->t(** @since 2.8 *)valadd_seq:eltSeq.t->t->t(** @since 3.0 *)valto_iter:t->eltiter(** [to_iter t] converts the set [t] to a [iter] of the elements.
@since 2.8 *)valadd_list:t->eltlist->t(** @since 0.14 *)valto_list:t->eltlist(** [to_list t] converts the set [t] to a list of the elements. *)valto_string:?start:string->?stop:string->?sep:string->(elt->string)->t->string(** Print the set in a string
@since 2.7 *)valpp:?pp_start:unitprinter->?pp_stop:unitprinter->?pp_sep:unitprinter->eltprinter->tprinter(** Print the set. *)endmoduleMake(O:Map.OrderedType)=structmoduleS=Set.Make(O)(* backport functions from recent stdlib.
they will be shadowed by inclusion of [S] if present. *)[@@@ocaml.warning"-32"]letfind_optxs=trySome(S.findxs)withNot_found->Noneletchoose_opts=trySome(S.chooses)withNot_found->Noneletmin_elt_opts=trySome(S.min_elts)withNot_found->Noneletmax_elt_opts=trySome(S.max_elts)withNot_found->NoneexceptionFind_binding_exitletfind_first_optfm=letres=refNoneintryS.iter(funx->iffxthen(res:=Somex;raiseFind_binding_exit))m;NonewithFind_binding_exit->!resletfind_firstfm=matchfind_first_optfmwith|None->raiseNot_found|Somex->xletfind_first_mapfm=letres=refNoneintryS.iter(funx->matchfxwith|None->()|Somey->res:=Somey;raiseFind_binding_exit)m;NonewithFind_binding_exit->!res(* linear time, must traverse the whole set… *)letfind_last_optfm=letres=refNoneinS.iter(funx->iffxthenres:=Somex)m;!resletfind_lastfm=matchfind_last_optfmwith|None->raiseNot_found|Somex->x[@@@ocaml.warning"+32"]includeS(* Use find_last which is linear time on OCaml < 4.05 *)letfind_last_mapfm=letres=refNoneinlet_=find_last_opt(funx->matchfxwith|None->false|Somey->res:=Somey;true)min!resletadd_seqseqset=letset=refsetinSeq.iter(funx->set:=addx!set)seq;!setletof_seqs=add_seqsemptyletadd_iterseti=letset=refsetini(funx->set:=addx!set);!setletof_iters=add_iteremptysletto_itersyield=iteryieldsletadd_list=List.fold_left(funsetx->addxset)letto_list=elementsletto_string?(start="")?(stop="")?(sep=",")elt_to_stringh=to_listh|>CCList.to_string~start~stop~sepelt_to_stringletpp?(pp_start=fun_()->())?(pp_stop=fun_()->())?(pp_sep=funfmt()->Format.fprintffmt",@ ")pp_xfmtm=pp_startfmt();letfirst=reftrueiniter(funx->if!firstthenfirst:=falseelsepp_sepfmt();pp_xfmtx)m;pp_stopfmt()end