Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file sized.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2022 Nomadic Labs, <contact@nomadic-labs.com> *)(* *)(* Permission is hereby granted, free of charge, to any person obtaining a *)(* copy of this software and associated documentation files (the "Software"),*)(* to deal in the Software without restriction, including without limitation *)(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *)(* and/or sell copies of the Software, and to permit persons to whom the *)(* Software is furnished to do so, subject to the following conditions: *)(* *)(* The above copyright notice and this permission notice shall be included *)(* in all copies or substantial portions of the Software. *)(* *)(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *)(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *)(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *)(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *)(* DEALINGS IN THE SOFTWARE. *)(* *)(*****************************************************************************)moduletypeSizedSet=sigincludeTzLwtreslib.Set.Stypesetvalto_set:t->setvalof_set:set->tendmoduleMakeSizedSet(S:TzLwtreslib.Set.S)=structtypeelt=S.elttypet={cardinal:int;set:S.t}letcardinalt=t.cardinalletto_sett=t.setletof_setset={cardinal=S.cardinalset;set}letempty={cardinal=0;set=S.empty}letis_emptyt=t.cardinal=0letmemxt=S.memxt.setletaddxt=letnset=S.addxt.setinifnset==t.setthentelse{cardinal=t.cardinal+1;set=nset}letsingletone={cardinal=1;set=S.singletone}letremovext=letnset=S.removext.setinifnset==t.setthentelse{cardinal=t.cardinal-1;set=nset}(** This function is less efficient than {!TzLwtreslib.Set.S.union} which should be considered instead of this function, especially in case it's called several times.
{!to_set} and {!of_set} can be used for this purpose.*)letuniont1t2=S.uniont1.sett2.set|>of_set(** This function is less efficient than {!TzLwtreslib.Set.S.inter} which should be considered instead of this function, especially in case it's called several times.
{!to_set} and {!of_set} can be used for this purpose.*)letintert1t2=S.intert1.sett2.set|>of_setletdisjointt1t2=S.disjointt1.sett2.setletdifft1t2=S.difft1.sett2.set|>of_setletcomparet1t2=S.comparet1.sett2.setletequalt1t2=t1.cardinal=t2.cardinal&&S.equalt1.sett2.setletsubsett1t2=t1.cardinal<=t2.cardinal&&S.subsett1.sett2.setletiterft=S.iterft.setletiter_eft=S.iter_eft.setletiter_sft=S.iter_sft.setletiter_pft=S.iter_pft.setletiter_esft=S.iter_esft.setletiter_epft=S.iter_epft.setletmapft=(* If [f] returns the same value for different inputs, then the cardinal
needs recomputing. We cannot detect this cheaply so we need to recompute
the cardinal on each application. *)S.mapft.set|>of_setletfoldfta=S.foldft.setaletfold_efta=S.fold_eft.setaletfold_sfta=S.fold_sft.setaletfold_esfta=S.fold_esft.setaletfor_allft=S.for_allft.setletexistsft=S.existsft.setletfilterft=S.fold(funxr->iffxthenaddxrelser)t.setemptyletfilter_mapft=S.fold(funxr->matchfxwithSomev->addvr|None->r)t.setemptyletpartitionft=lets1,s2=S.partitionft.setinletn=S.cardinals1in({cardinal=n;set=s1},{cardinal=t.cardinal-n;set=s2})letelementst=S.elementst.setletmin_eltt=S.min_eltt.setletmin_elt_optt=S.min_elt_optt.setletmax_eltt=S.max_eltt.setletmax_elt_optt=S.max_elt_optt.setletchooset=S.chooset.setletchoose_optt=S.choose_optt.setletsplitet=letl,b,r=S.splitet.setinletn=S.cardinallinifbthen({cardinal=n;set=l},b,{cardinal=t.cardinal-n-1;set=r})else({cardinal=n;set=l},b,{cardinal=t.cardinal-n;set=r})letfindet=S.findet.setletfind_optet=S.find_optet.setletfind_firstet=S.find_firstet.setletfind_first_optet=S.find_first_optet.setletfind_lastet=S.find_lastet.setletfind_last_optet=S.find_last_optet.setletof_listel=S.of_listel|>of_setletto_seq_fromet=S.to_seq_fromet.setletto_seqt=S.to_seqt.setletto_rev_seqt=S.to_seqt.setletadd_seqseqt=S.add_seqseqt.set|>of_setletof_seqseq=S.of_seqseq|>of_setendmoduletypeSizedMap=sigincludeTzLwtreslib.Map.Stype'amapvalto_map:'at->'amapvalof_map:'amap->'atendmoduleMakeSizedMap(M:TzLwtreslib.Map.S)=structtypekey=M.keytype'at={cardinal:int;map:'aM.t}letcardinalt=t.cardinalletto_mapt=t.mapletof_mapmap={cardinal=M.cardinalmap;map}letempty={cardinal=0;map=M.empty}letis_emptyt=t.cardinal=0letmemxt=M.memxt.mapletupdatekeyft=letx=M.find_optkeyt.mapinmatchxwith|None->(matchfNonewith|Somex->{cardinal=t.cardinal+1;map=M.addkeyxt.map}|None->t)|Somex->(matchf(Somex)with|Somex->{cardinal=t.cardinal;map=M.addkeyxt.map}|None->{cardinal=t.cardinal-1;map=M.removekeyt.map})letaddkeybindingt=updatekey(fun_->Somebinding)tletsingletonkeybinding={cardinal=1;map=M.singletonkeybinding}letremovekeyt=letnt=M.removekeyt.mapinifnt==t.mapthentelse{cardinal=t.cardinal-1;map=nt}(** This function is less efficient than {!TzLwtreslib.Map.S.merge} which should be considered instead of this function, especially in case it's called several times.
{!to_map} and {!of_map} can be used for this purpose.*)letmergeft1t2=M.mergeft1.mapt2.map|>of_map(** This function is less efficient than {!TzLwtreslib.Map.S.union} which should be considered instead of this function, especially in case it's called several times.
{!to_map} and {!of_map} can be used for this purpose.*)letunionft1t2=M.unionft1.mapt2.map|>of_mapletcompareft1t2=M.compareft1.mapt2.mapletequalft1t2=t1.cardinal=t2.cardinal&&M.equalft1.mapt2.mapletiterft=M.iterft.mapletiter_eft=M.iter_eft.mapletiter_sft=M.iter_sft.mapletiter_pft=M.iter_pft.mapletiter_esft=M.iter_esft.mapletiter_epft=M.iter_epft.mapletfoldfta=M.foldft.mapaletfold_efta=M.fold_eft.mapaletfold_sfta=M.fold_sft.mapaletfold_esfta=M.fold_esft.mapaletfor_allft=M.for_allft.mapletexistsft=M.existsft.mapletfilterft=M.fold(funkbr->iffkbthenaddkbrelser)t.mapemptyletfilter_mapft=M.fold(funkbr->matchfkbwithSomev->addkvr|None->r)t.mapemptyletpartitionft=letm1,m2=M.partitionft.mapinletn=M.cardinalm1in({cardinal=n;map=m1},{cardinal=t.cardinal-n;map=m2})letbindingst=M.bindingst.mapletmin_bindingt=M.min_bindingt.mapletmin_binding_optt=M.min_binding_optt.mapletmax_bindingt=M.max_bindingt.mapletmax_binding_optt=M.max_binding_optt.mapletchooset=M.chooset.mapletchoose_optt=M.choose_optt.mapletsplitkeyt=letl,data,r=M.splitkeyt.mapinletn=M.cardinallinmatchdatawith|Some_->({cardinal=n;map=l},data,{cardinal=t.cardinal-n-1;map=r})|None->({cardinal=n;map=l},data,{cardinal=t.cardinal-n;map=r})letfindkeyt=M.findkeyt.mapletfind_optkeyt=M.find_optkeyt.mapletfind_firstkeyt=M.find_firstkeyt.mapletfind_first_optkeyt=M.find_first_optkeyt.mapletfind_lastkeyt=M.find_lastkeyt.mapletfind_last_optkeyt=M.find_last_optkeyt.mapletmapft={cardinal=t.cardinal;map=M.mapft.map}letmapift={cardinal=t.cardinal;map=M.mapift.map}letto_seqt=M.to_seqt.mapletto_rev_seqt=M.to_rev_seqt.mapletto_seq_fromet=M.to_seq_fromet.mapletadd_seqseqt=M.add_seqseqt.map|>of_mapletof_seqseq=M.of_seqseq|>of_mapend