Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file CCMultiMap.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343(* https://github.com/c-cube/ocaml-containers/blob/3b49ad2a4e8cfe366d0588e1940d626f0e1b8a2d/LICENSE
Copyright (c) 2013, Simon Cruanes
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer. Redistributions in binary
form must reproduce the above copyright notice, this list of conditions and
the following disclaimer in the documentation and/or other materials
provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*)(* This file is free software, part of containers. See file "license" for more details. *)(** {1 Multimap} *)type'aiter=('a->unit)->unitmoduletypeS=sigtypekeytypevaluetypetvalempty:t(** Empty multimap *)valis_empty:t->bool(** Empty multimap? *)valadd:t->key->value->t(** Add a key/value binding *)valremove:t->key->value->t(** Remove the binding *)valremove_all:t->key->t(** Remove the key from the map *)valmem:t->key->bool(** Is there a binding for this key? *)valfind:t->key->valuelist(** List of values for this key *)valfind_iter:t->key->valueiter(** Iterate on bindings for this key *)valcount:t->key->int(** Number of bindings for this key *)valiter:t->(key->value->unit)->unit(** Iterate on all key/value *)valfold:t->'a->('a->key->value->'a)->'a(** Fold on all key/value *)valsize:t->int(** Number of keys *)valunion:t->t->t(** Union of multimaps *)valinter:t->t->t(** Intersection of multimaps *)valdiff:t->t->t(** Difference of maps, ie bindings of the first that are not
in the second *)valequal:t->t->bool(** Same multimap *)valcompare:t->t->int(** Total order on multimaps *)valsubmap:t->t->bool(** [submap m1 m2] is true iff all bindings of [m1] are also in [m2] *)valto_iter:t->(key*value)itervalof_iter:?init:t->(key*value)iter->tvalkeys:t->keyitervalvalues:t->valueiter(** Some values may occur several times *)endmoduletypeOrderedType=sigtypetvalcompare:t->t->intendmoduleMake(K:OrderedType)(V:OrderedType)=structtypekey=K.ttypevalue=V.tmoduleM=Map.Make(K)moduleS=Set.Make(V)typet=S.tM.t(** Map of sets *)letempty=M.emptyletis_empty=M.is_emptyletaddmkv=letset=tryM.findkmwithNot_found->S.emptyinM.addk(S.addvset)mletremovemkv=tryletset=M.findkminletset'=S.removevsetinifS.is_emptyset'thenM.removekmelseM.addkset'mwithNot_found->mletremove_allmk=M.removekmletmemmk=M.memkmletfindmk=tryletset=M.findkminS.elementssetwithNot_found->[]letfind_itermkf=tryletset=M.findkminS.iterfsetwithNot_found->()letcountmk=tryletset=M.findkminS.cardinalsetwithNot_found->0letitermf=M.iter(funkset->S.iter(funv->fkv)set)mletfoldmaccf=M.fold(funksetacc->S.fold(funvacc->facckv)setacc)maccletsizem=M.cardinalmletunionm1m2=M.merge(fun_kv1v2->matchv1,v2with|None,None->None|Someset1,Someset2->Some(S.unionset1set2)|Someset,None|None,Someset->Someset)m1m2letinterm1m2=M.merge(fun_kv1v2->matchv1,v2with|None,_|_,None->None|Someset1,Someset2->letset=S.interset1set2inifS.is_emptysetthenNoneelseSomeset)m1m2letdiffm1m2=M.merge(fun_kv1v2->matchv1,v2with|None,_->None|Someset,None->Someset|Someset1,Someset2->letset'=S.diffset1set2inifS.is_emptyset'thenNoneelseSomeset')m1m2letequalm1m2=M.equalS.equalm1m2letcomparem1m2=M.compareS.comparem1m2letsubmapm1m2=M.for_all(funkset1->tryletset2=M.findkm2inS.subsetset1set2withNot_found->false)m1letto_itermk=iterm(funxy->k(x,y))letof_iter?(init=empty)seq=letm=refinitinseq(fun(k,v)->m:=add!mkv);!mletkeysmk=M.iter(funx_->kx)mletvaluesmk=iterm(fun_v->kv)endmoduletypeBIDIR=sigtypettypelefttyperightvalempty:tvalis_empty:t->boolvaladd:t->left->right->t(** Add a binding (left,right) *)valremove:t->left->right->t(** Remove a specific binding *)valcardinal_left:t->int(** number of distinct left keys *)valcardinal_right:t->int(** number of distinct right keys *)valremove_left:t->left->t(** Remove all bindings for the left key *)valremove_right:t->right->t(** Remove all bindings for the right key *)valmem_left:t->left->bool(** Is the left key present in at least one pair? *)valmem_right:t->right->bool(** Is the right key present in at least one pair? *)valfind_left:t->left->rightlist(** List of values for this given left-key.
This used to return an iter, but returns a list since 3.13. *)valfind_left_iter:t->left->rightiter(** Iterate on bindings for this given left-key
@since 3.13 *)valfind_right:t->right->leftlist(** List of values for this given right-key.
This used to return an iter, but returns a list since 3.13. *)valfind_right_iter:t->right->leftiter(** Iterate on bindings for this given left-key
@since 3.13 *)valfind1_left:t->left->rightoption(** like {!find_left} but returns at most one value *)valfind1_right:t->right->leftoption(** like {!find_right} but returns at most one value *)valfold:('a->left->right->'a)->'a->t->'a(** Fold on pairs *)valpairs:t->(left*right)iter(** Iterate on pairs *)valadd_pairs:t->(left*right)iter->t(** Add pairs *)valiter_left:t->leftitervaliter_right:t->rightiterendlet_fold_iterfaccseq=letacc=refaccinseq(funx->acc:=f!accx);!acclet_head_iterseq=letr=refNonein(tryseq(funx->r:=Somex;raiseExit)withExit->());!rmoduleMakeBidir(L:OrderedType)(R:OrderedType)=structtypeleft=L.ttyperight=R.tmoduleMapL=Make(L)(R)moduleMapR=Make(R)(L)typet={left:MapL.t;right:MapR.t;}letempty={left=MapL.empty;right=MapR.empty}letis_emptym=MapL.is_emptym.leftletaddmab={left=MapL.addm.leftab;right=MapR.addm.rightba}letremovemab={left=MapL.removem.leftab;right=MapR.removem.rightba}letcardinal_leftm=MapL.sizem.leftletcardinal_rightm=MapR.sizem.rightletfind_leftma=MapL.findm.leftaletfind_left_iterma=MapL.find_iterm.leftaletfind_rightmb=MapR.findm.rightbletfind_right_itermb=MapR.find_iterm.rightbletremove_leftma=_fold_iter(funmb->removemab)m(find_left_iterma)letremove_rightmb=_fold_iter(funma->removemab)m(find_right_itermb)letmem_leftma=MapL.memm.leftaletmem_rightmb=MapR.memm.rightbletfind1_leftma=_head_iter(find_left_iterma)letfind1_rightmb=_head_iter(find_right_itermb)letfoldfaccm=MapL.foldm.leftaccfletpairsm=MapL.to_iterm.leftletadd_pairsmseq=_fold_iter(funm(a,b)->addmab)mseqletiter_leftm=MapL.keysm.leftletiter_rightm=MapR.keysm.rightend