Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file CCMap.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265(* This file is free software, part of containers. See file "license" for more details. *)(** {1 Extensions of Standard Map} *)type'aiter=('a->unit)->unittype'asequence=('a->unit)->unittype'aprinter=Format.formatter->'a->unitmoduletypeOrderedType=Map.OrderedTypemoduletypeS=sigincludeMap.Svalget:key->'at->'aoption(** Safe version of {!find}. *)valget_or:key->'at->default:'a->'a(** [get_or k m ~default] returns the value associated to [k] if present,
and returns [default] otherwise (if [k] doesn't belong in [m]).
@since 0.16 *)valupdate:key->('aoption->'aoption)->'at->'at(** [update k f m] calls [f (Some v)] if [find k m = v],
otherwise it calls [f None]. In any case, if the result is [None]
[k] is removed from [m], and if the result is [Some v'] then
[add k v' m] is returned. *)valchoose_opt:'at->(key*'a)option(** Safe version of {!choose}.
@since 1.5 *)valmin_binding_opt:'at->(key*'a)option(** Safe version of {!min_binding}.
@since 1.5 *)valmax_binding_opt:'at->(key*'a)option(** Safe version of {!max_binding}.
@since 1.5 *)valfind_opt:key->'at->'aoption(** Safe version of {!find}.
@since 1.5 *)valfind_first:(key->bool)->'at->key*'a(** Find smallest binding satisfying the monotonic predicate.
See {!Map.S.find_first}.
@since 1.5 *)valfind_first_opt:(key->bool)->'at->(key*'a)option(** Safe version of {!find_first}.
@since 1.5 *)valmerge_safe:f:(key->[`Leftof'a|`Rightof'b|`Bothof'a*'b]->'coption)->'at->'bt->'ct(** [merge_safe ~f a b] merges the maps [a] and [b] together.
@since 0.17 *)valunion:(key->'a->'a->'aoption)->'at->'at->'at(** Union of both maps, using the function to combine bindings
that belong to both inputs.
@since 1.4 *)valof_iter:(key*'a)iter->'at(** Like {!of_list}.
@since 2.8 *)valadd_std_seq:'at->(key*'a)Seq.t->'at(** Like {!add_list}.
@since 2.8 *)valof_std_seq:(key*'a)Seq.t->'at(** Like {!of_list}.
@since 2.8 *)valadd_iter:'at->(key*'a)iter->'at(** Like {!add_list}.
@since 2.8 *)valof_iter:(key*'a)iter->'at(** Like {!of_list}.
@since 2.8 *)valto_iter:'at->(key*'a)iter(** Like {!to_list}.
@since 2.8 *)valof_seq:(key*'a)sequence->'at(** Like {!of_list}.
@deprecated use {!of_iter} instead. *)[@@ocaml.deprecated"use of_iter instead"]valadd_seq:'at->(key*'a)sequence->'at(** @since 0.14
@deprecated use {!add_iter} instead. *)[@@ocaml.deprecated"use add_iter instead"]valto_seq:'at->(key*'a)sequence(** @deprecated use {!to_iter} instead. *)[@@ocaml.deprecated"use to_iter instead"]valof_list:(key*'a)list->'at(** Build a map from the given list of bindings [k_i -> v_i],
added in order using {!add}.
If a key occurs several times, only its last binding
will be present in the result. *)valadd_list:'at->(key*'a)list->'at(** @since 0.14 *)valkeys:_t->keyiter(** Iterate on keys only.
@since 0.15 *)valvalues:'at->'aiter(** Iterate on values only.
@since 0.15 *)valto_list:'at->(key*'a)listvalpp:?start:string->?stop:string->?arrow:string->?sep:string->keyprinter->'aprinter->'atprinterendmoduleMake(O:Map.OrderedType)=structmoduleM=Map.Make(O)(* backport functions from recent stdlib.
they will be shadowed by inclusion of [S] if present. *)letunionfab=M.merge(funkv1v2->matchv1,v2with|None,None->assertfalse|None,(Some_asr)->r|Some_asr,None->r|Somev1,Somev2->fkv1v2)abletchoose_optm=trySome(M.choosem)withNot_found->Noneletfind_optkm=trySome(M.findkm)withNot_found->Noneletmax_binding_optm=trySome(M.max_bindingm)withNot_found->Noneletmin_binding_optm=trySome(M.min_bindingm)withNot_found->NoneexceptionFind_binding_exitletfind_first_optfm=letres=refNoneintryM.iter(funkv->iffkthen(res:=Some(k,v);raiseFind_binding_exit))m;NonewithFind_binding_exit->!resletfind_firstfm=matchfind_first_optfmwith|None->raiseNot_found|Some(k,v)->k,v(* linear time, must traverse the whole map… *)letfind_last_optfm=letres=refNoneinM.iter(funkv->iffkthenres:=Some(k,v))m;!resletfind_lastfm=matchfind_last_optfmwith|None->raiseNot_found|Some(k,v)->k,vincludeMletget=find_optletget_orkm~default=tryfindkmwithNot_found->defaultletupdatekfm=letx=tryf(Some(findkm))withNot_found->fNoneinmatchxwith|None->removekm|Somev'->addkv'mletmerge_safe~fab=merge(funkv1v2->matchv1,v2with|None,None->assertfalse|Somev1,None->fk(`Leftv1)|None,Somev2->fk(`Rightv2)|Somev1,Somev2->fk(`Both(v1,v2)))abletadd_std_seqms=letm=refminSeq.iter(fun(k,v)->m:=addkv!m)s;!mletof_std_seqs=add_std_seqemptysletadd_iterms=letm=refmins(fun(k,v)->m:=addkv!m);!mletof_iters=add_iteremptysletto_itermyield=iter(funkv->yield(k,v))mletadd_seq=add_iterletof_seq=of_iterletto_seq=to_iterletkeysmyield=iter(funk_->yieldk)mletvaluesmyield=iter(fun_v->yieldv)mletadd_listml=List.fold_left(funm(k,v)->addkvm)mlletof_listl=add_listemptylletto_listm=fold(funkvacc->(k,v)::acc)m[]letpp?(start="")?(stop="")?(arrow="->")?(sep=", ")pp_kpp_vfmtm=Format.pp_print_stringfmtstart;letfirst=reftrueiniter(funkv->if!firstthenfirst:=falseelse(Format.pp_print_stringfmtsep;Format.pp_print_cutfmt());pp_kfmtk;Format.pp_print_stringfmtarrow;pp_vfmtv)m;Format.pp_print_stringfmtstopend