Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file hash_set.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220open!ImportincludeHash_set_intflethashable_s=Hashtbl.hashable_slethashable=Hashtbl.Private.hashableletpoly_hashable=Hashtbl.Poly.hashableletwith_return=With_return.with_returntype'at=('a,unit)Hashtbl.ttype'ahash_set='attype'aelt='amoduleAccessors=structlethashable=hashableletclear=Hashtbl.clearletlength=Hashtbl.lengthletmem=Hashtbl.memletis_emptyt=Hashtbl.is_emptytletfind_mapt~f=with_return(funr->Hashtbl.iter_keyst~f:(funelt->matchfeltwith|None->()|Some_aso->r.returno);None);;letfindt~f=find_mapt~f:(funa->iffathenSomeaelseNone)letaddtk=Hashtbl.sett~key:k~data:()letstrict_addtk=ifmemtkthenOr_error.error_string"element already exists"elsebeginHashtbl.sett~key:k~data:();Result.Ok()end;;letstrict_add_exntk=Or_error.ok_exn(strict_addtk)letremove=Hashtbl.removeletstrict_removetk=ifmemtkthenbeginremovetk;Result.Ok()endelseOr_error.error"element not in set"k(Hashtbl.sexp_of_keyt);;letstrict_remove_exntk=Or_error.ok_exn(strict_removetk)letfoldt~init~f=Hashtbl.foldt~init~f:(fun~key~data:()acc->facckey)letitert~f=Hashtbl.iter_keyst~fletcountt~f=Container.count~foldt~fletsummt~f=Container.sum~foldmt~fletmin_eltt~compare=Container.min_elt~foldt~compareletmax_eltt~compare=Container.max_elt~foldt~compareletfold_resultt~init~f=Container.fold_result~fold~init~ftletfold_untilt~init~f=Container.fold_until~fold~init~ftletto_list=Hashtbl.keysletsexp_of_tsexp_of_et=sexp_of_listsexp_of_e(to_listt|>List.sort~compare:(hashablet).compare)letto_arrayt=letlen=lengthtinletindex=ref(len-1)infoldt~init:[||]~f:(funacckey->ifArray.lengthacc=0thenArray.create~lenkeyelsebeginindex:=!index-1;Array.setacc(!index)key;accend)letexistst~f=Hashtbl.existsit~f:(fun~key~data:()->fkey)letfor_allt~f=not(Hashtbl.existsit~f:(fun~key~data:()->not(fkey)))letequalt1t2=Hashtbl.equalt1t2(fun()()->true)letcopyt=Hashtbl.copytletfiltert~f=Hashtbl.filterit~f:(fun~key~data:()->fkey)letdifft1t2=filtert1~f:(funkey->not(Hashtbl.memt2key))letintert1t2=letsmaller,larger=iflengtht1>lengtht2then(t2,t1)else(t1,t2)inHashtbl.filterismaller~f:(fun~key~data:()->Hashtbl.memlargerkey)letfilter_inplacet~f=letto_remove=foldt~init:[]~f:(funacx->iffxthenacelsex::ac)inList.iterto_remove~f:(funx->removetx);;letof_hashtbl_keyshashtbl=Hashtbl.maphashtbl~f:ignoreletto_hashtblt~f=Hashtbl.mapit~f:(fun~key~data:()->fkey)endincludeAccessorsletcreate?growth_allowed?sizem=Hashtbl.create?growth_allowed?sizem;;letof_list?growth_allowed?sizeml=letsize=matchsizewithSomex->x|None->List.lengthlinlett=Hashtbl.create?growth_allowed~sizeminList.iterl~f:(funk->addtk);t;;lett_of_sexpme_of_sexpsexp=matchsexpwith|Sexp.Atom_->raise(Of_sexp_error(Failure"Hash_set.t_of_sexp requires a list",sexp))|Sexp.Listlist->lett=createm~size:(List.lengthlist)inList.iterlist~f:(funsexp->lete=e_of_sexpsexpinmatchstrict_addtewith|Ok()->()|Error_->raise(Of_sexp_error(Error.to_exn(Error.create"Hash_set.t_of_sexp got a duplicate element"sexpFn.id),sexp)));t;;moduleCreators(Elt:sigtype'atvalhashable:'atHashable.tend):sigtype'at_='aElt.ttvalt_of_sexp:(Sexp.t->'aElt.t)->Sexp.t->'at_includeCreators_genericwithtype'at:='at_withtype'aelt:='aElt.twithtype('elt,'z)create_options:=('elt,'z)create_options_without_first_class_moduleend=structtype'at_='aElt.ttletcreate?growth_allowed?size()=create?growth_allowed?size(Hashable.to_keyElt.hashable)letof_list?growth_allowed?sizel=of_list?growth_allowed?size(Hashable.to_keyElt.hashable)llett_of_sexpe_of_sexpsexp=t_of_sexp(Hashable.to_keyElt.hashable)e_of_sexpsexpendmodulePoly=structtype'at='ahash_settype'aelt='alethashable=poly_hashableincludeCreators(structtype'at='alethashable=hashableend)includeAccessorsletsexp_of_t=sexp_of_tendmoduleM(Elt:T.T)=structtypenonrect=Elt.ttendmoduletypeSexp_of_m=sigtypet[@@deriving_inlinesexp_of]includesig[@@@ocaml.warning"-32"]valsexp_of_t:t->Ppx_sexp_conv_lib.Sexp.tend[@@ocaml.doc"@inline"][@@@end]endmoduletypeM_of_sexp=sigtypet[@@deriving_inlineof_sexp]includesig[@@@ocaml.warning"-32"]valt_of_sexp:Ppx_sexp_conv_lib.Sexp.t->tend[@@ocaml.doc"@inline"][@@@end]includeHashtbl_intf.Keywithtypet:=tendletsexp_of_m__t(typeelt)(moduleElt:Sexp_of_mwithtypet=elt)t=sexp_of_tElt.sexp_of_ttletm__t_of_sexp(typeelt)(moduleElt:M_of_sexpwithtypet=elt)sexp=t_of_sexp(moduleElt)Elt.t_of_sexpsexpmodulePrivate=structlethashable=Hashtbl.Private.hashableend