123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711(** Interfaces for immutable dictionary types, such as [Map.t].
We define separate interfaces for [Accessors] and [Creators], along with [S] combining
both. These interfaces are written once in their most general form, which involves
extra type definitions and type parameters that most instances do not need.
We then provide instantiations of these interfaces with 1, 2, and 3 type parameters
for [t]. These cover more common usage patterns for the interfaces. *)open!Import(** These definitions are re-exported by [Dictionary_immutable]. *)moduleDefinitions=structmoduletypeAccessors=sig(** The type of keys. This will be ['key] for polymorphic dictionaries, or some fixed
type for dictionaries with monomorphic keys. *)type'keykey(** Dictionaries. Their keys have type ['key key]. Each key's associated value has
type ['data]. The dictionary may be distinguished by a ['phantom] type. *)type('key,'data,'phantom)t(** The type of accessor functions ['fn] that operate on [('key, 'data, 'phantom) t].
May take extra arguments before ['fn], such as a comparison function. *)type('fn,'key,'data,'phantom)accessor(** Whether the dictionary is empty. *)valis_empty:(_,_,_)t->bool(** How many key/value pairs the dictionary contains. *)vallength:(_,_,_)t->int(** All key/value pairs. *)valto_alist:('key,'data,_)t->('keykey*'data)list(** All keys in the dictionary, in the same order as [to_alist]. *)valkeys:('key,_,_)t->'keykeylist(** All values in the dictionary, in the same order as [to_alist]. *)valdata:(_,'data,_)t->'datalist(** Like [to_alist]. Produces a sequence. *)valto_sequence:('key,'data,'phantom)t->('keykey*'data)Sequence.t(** Whether [key] has a value. *)valmem:(('key,_,'phantom)t->'keykey->bool,'key,'data,'phantom)accessor(** Produces the current value, or absence thereof, for a given key. *)valfind:(('key,'data,'phantom)t->'keykey->'dataoption,'key,'data,'phantom)accessor(** Like [find]. Raises if there is no value for the given key. *)valfind_exn:(('key,'data,'phantom)t->'keykey->'data,'key,'data,'phantom)accessor(** Adds a key/value pair for a key the dictionary does not contain, or reports a
duplicate. *)valadd:(('key,'data,'phantom)t->key:'keykey->data:'data->[`Okof('key,'data,'phantom)t|`Duplicate],'key,'data,'phantom)accessor(** Like [add]. Raises on duplicates. *)valadd_exn:(('key,'data,'phantom)t->key:'keykey->data:'data->('key,'data,'phantom)t,'key,'data,'phantom)accessor(** Adds or replaces a key/value pair in the dictionary. *)valset:(('key,'data,'phantom)t->key:'keykey->data:'data->('key,'data,'phantom)t,'key,'data,'phantom)accessor(** Removes any value for the given key. *)valremove:(('key,'data,'phantom)t->'keykey->('key,'data,'phantom)t,'key,'data,'phantom)accessor(** Adds, replaces, or removes the value for a given key, depending on its current
value or lack thereof. *)valchange:(('key,'data,'phantom)t->'keykey->f:('dataoption->'dataoption)->('key,'data,'phantom)t,'key,'data,'phantom)accessor(** Adds or replaces the value for a given key, depending on its current value or
lack thereof. *)valupdate:(('key,'data,'phantom)t->'keykey->f:('dataoption->'data)->('key,'data,'phantom)t,'key,'data,'phantom)accessor(** Adds [data] to the existing key/value pair for [key]. Interprets a missing key as
having an empty list. *)valadd_multi:(('key,'datalist,'phantom)t->key:'keykey->data:'data->('key,'datalist,'phantom)t,'key,'data,'phantom)accessor(** Removes one element from the existing key/value pair for [key]. Removes the key
entirely if the new list is empty. *)valremove_multi:(('key,'datalist,'phantom)t->'keykey->('key,'datalist,'phantom)t,'key,'data,'phantom)accessor(** Produces the list associated with the corresponding key. Interprets a missing
key as having an empty list. *)valfind_multi:(('key,'datalist,'phantom)t->'keykey->'datalist,'key,'data,'phantom)accessor(** Combines every value in the dictionary. *)valfold:('key,'data,_)t->init:'acc->f:(key:'keykey->data:'data->'acc->'acc)->'acc(** Like [fold]. May stop before completing the iteration. *)valfold_until:('key,'data,_)t->init:'acc->f:(key:'keykey->data:'data->'acc->('acc,'final)Container.Continue_or_stop.t)->finish:('acc->'final)->'final(** Whether every value satisfies [f]. *)valfor_all:('key,'data,_)t->f:('data->bool)->bool(** Like [for_all]. The predicate may also depend on the associated key. *)valfor_alli:('key,'data,_)t->f:(key:'keykey->data:'data->bool)->bool(** Whether at least one value satisfies [f]. *)valexists:('key,'data,_)t->f:('data->bool)->bool(** Like [exists]. The predicate may also depend on the associated key. *)valexistsi:('key,'data,_)t->f:(key:'keykey->data:'data->bool)->bool(** How many values satisfy [f]. *)valcount:('key,'data,_)t->f:('data->bool)->int(** Like [count]. The predicate may also depend on the associated key. *)valcounti:('key,'data,_)t->f:(key:'keykey->data:'data->bool)->int(** Sum up [f data] for all data in the dictionary. *)valsum:(moduleContainer.Summablewithtypet='a)->('key,'data,_)t->f:('data->'a)->'a(** Like [sum]. The function may also depend on the associated key. *)valsumi:(moduleContainer.Summablewithtypet='a)->('key,'data,_)t->f:(key:'key->data:'data->'a)->'a(** Produces the key/value pair with the smallest key if non-empty. *)valmin_elt:('key,'data,_)t->('keykey*'data)option(** Like [min_elt]. Raises if empty. *)valmin_elt_exn:('key,'data,_)t->'keykey*'data(** Produces the key/value pair with the largest key if non-empty. *)valmax_elt:('key,'data,_)t->('keykey*'data)option(** Like [max_elt]. Raises if empty. *)valmax_elt_exn:('key,'data,_)t->'keykey*'data(** Calls [f] for every key. *)valiter_keys:('key,_,_)t->f:('keykey->unit)->unit(** Calls [f] for every value. *)valiter:(_,'data,_)t->f:('data->unit)->unit(** Calls [f] for every key/value pair. *)valiteri:('key,'data,_)t->f:(key:'keykey->data:'data->unit)->unit(** Transforms every value. *)valmap:('key,'data1,'phantom)t->f:('data1->'data2)->('key,'data2,'phantom)t(** Like [map]. The transformation may also depend on the associated key. *)valmapi:('key,'data1,'phantom)t->f:(key:'keykey->data:'data1->'data2)->('key,'data2,'phantom)t(** Produces only those key/value pairs whose key satisfies [f]. *)valfilter_keys:('key,'data,'phantom)t->f:('keykey->bool)->('key,'data,'phantom)t(** Produces only those key/value pairs whose value satisfies [f]. *)valfilter:('key,'data,'phantom)t->f:('data->bool)->('key,'data,'phantom)t(** Produces only those key/value pairs which satisfy [f]. *)valfilteri:('key,'data,'phantom)t->f:(key:'keykey->data:'data->bool)->('key,'data,'phantom)t(** Produces key/value pairs for which [f] produces [Some]. *)valfilter_map:('key,'data1,'phantom)t->f:('data1->'data2option)->('key,'data2,'phantom)t(** Like [filter_map]. The new value may also depend on the associated key. *)valfilter_mapi:('key,'data1,'phantom)t->f:(key:'keykey->data:'data1->'data2option)->('key,'data2,'phantom)t(** Splits one dictionary into two. The first contains key/value pairs for which the
value satisfies [f]. The second contains the remainder. *)valpartition_tf:('key,'data,'phantom)t->f:('data->bool)->('key,'data,'phantom)t*('key,'data,'phantom)t(** Like [partition_tf]. The predicate may also depend on the associated key. *)valpartitioni_tf:('key,'data,'phantom)t->f:(key:'keykey->data:'data->bool)->('key,'data,'phantom)t*('key,'data,'phantom)t(** Splits one dictionary into two, corresponding respectively to [First _] and
[Second _] results from [f]. *)valpartition_map:('key,'data1,'phantom)t->f:('data1->('data2,'data3)Either.t)->('key,'data2,'phantom)t*('key,'data3,'phantom)t(** Like [partition_map]. The split may also depend on the associated key. *)valpartition_mapi:('key,'data1,'phantom)t->f:(key:'keykey->data:'data1->('data2,'data3)Either.t)->('key,'data2,'phantom)t*('key,'data3,'phantom)t(** Produces an error combining all error messages from key/value pairs, or a
dictionary of all [Ok] values if none are [Error]. *)valcombine_errors:(('key,'dataOr_error.t,'phantom)t->('key,'data,'phantom)tOr_error.t,'key,'data,'phantom)accessor(** Splits the [fst] and [snd] components of values associated with keys into separate
dictionaries. *)valunzip:('key,'data1*'data2,'phantom)t->('key,'data1,'phantom)t*('key,'data2,'phantom)t(** Merges two dictionaries by fully traversing both. Not suitable for efficiently
merging lists of dictionaries. See [merge_disjoint_exn] and [merge_skewed]
instead. *)valmerge:(('key,'data1,'phantom)t->('key,'data2,'phantom)t->f:(key:'keykey->[`Leftof'data1|`Rightof'data2|`Bothof'data1*'data2]->'data3option)->('key,'data3,'phantom)t,'key,'data,'phantom)accessor(** Merges two dictionaries with the same type of data and disjoint sets of keys.
Raises if any keys overlap. *)valmerge_disjoint_exn:(('key,'data,'phantom)t->('key,'data,'phantom)t->('key,'data,'phantom)t,'key,'data,'phantom)accessor(** Merges two dictionaries by traversing only the smaller of the two. Adds key/value
pairs missing from the larger dictionary, and [combine]s duplicate values. *)valmerge_skewed:(('key,'data,'phantom)t->('key,'data,'phantom)t->combine:(key:'keykey->'data->'data->'data)->('key,'data,'phantom)t,'key,'data,'phantom)accessor(** Computes a sequence of differences between two dictionaries. *)valsymmetric_diff:(('key,'data,'phantom)t->('key,'data,'phantom)t->data_equal:('data->'data->bool)->('keykey*[`Leftof'data|`Rightof'data|`Unequalof'data*'data])Sequence.t,'key,'data,'phantom)accessor(** Folds over the result of [symmetric_diff]. May be more performant. *)valfold_symmetric_diff:(('key,'data,'phantom)t->('key,'data,'phantom)t->data_equal:('data->'data->bool)->init:'acc->f:('acc->'keykey*[`Leftof'data|`Rightof'data|`Unequalof'data*'data]->'acc)->'acc,'key,'data,'phantom)accessorendmoduletypeAccessors1=sigtypekeytype'datat(** @inline *)includeAccessorswithtype(_,'data,_)t:='datatandtype_key:=keyandtype('fn,_,_,_)accessor:='fnendmoduletypeAccessors2=sigtype('key,'data)ttype('fn,'key,'data)accessor(** @inline *)includeAccessorswithtype('key,'data,_)t:=('key,'data)tandtype'keykey:='keyandtype('fn,'key,'data,_)accessor:=('fn,'key,'data)accessorendmoduletypeAccessors3=sigtype('key,'data,'phantom)ttype('fn,'key,'data,'phantom)accessor(** @inline *)includeAccessorswithtype('key,'data,'phantom)t:=('key,'data,'phantom)tandtype'keykey:='keyandtype('fn,'key,'data,'phantom)accessor:=('fn,'key,'data,'phantom)accessorendmoduletypeCreators=sig(** The type of keys. This will be ['key] for polymorphic dictionaries, or some fixed
type for dictionaries with monomorphic keys. *)type'keykey(** Dictionaries. Their keys have type ['key key]. Each key's associated value has
type ['data]. The dictionary may be distinguished by a ['phantom] type. *)type('key,'data,'phantom)t(** The type of creator functions ['fn] that operate on [('key, 'data, 'phantom) t].
May take extra arguments before ['fn], such as a comparison function. *)type('fn,'key,'data,'phantom)creator(** The empty dictionary. *)valempty:(('key,'data,'phantom)t,'key,'data,'phantom)creator(** Dictionary with a single key/value pair. *)valsingleton:('keykey->'data->('key,'data,'phantom)t,'key,'data,'phantom)creator(** Dictionary containing the given key/value pairs. Fails if there are duplicate
keys. *)valof_alist:(('keykey*'data)list->[`Okof('key,'data,'phantom)t|`Duplicate_keyof'keykey],'key,'data,'phantom)creator(** Like [of_alist]. Returns a [Result.t]. *)valof_alist_or_error:(('keykey*'data)list->('key,'data,'phantom)tOr_error.t,'key,'data,'phantom)creator(** Like [of_alist]. Raises on duplicates. *)valof_alist_exn:(('keykey*'data)list->('key,'data,'phantom)t,'key,'data,'phantom)creator(** Produces a dictionary mapping each key to a list of associated values. *)valof_alist_multi:(('keykey*'data)list->('key,'datalist,'phantom)t,'key,'data,'phantom)creator(** Produces a dictionary using each key/value pair. Combines all values for a given
key with [init] using [f]. *)valof_alist_fold:(('keykey*'data)list->init:'acc->f:('acc->'data->'acc)->('key,'acc,'phantom)t,'key,'data,'phantom)creator(** Produces a dictionary using each key/value pair. Combines multiple values for a
given key using [f]. *)valof_alist_reduce:(('keykey*'data)list->f:('data->'data->'data)->('key,'data,'phantom)t,'key,'data,'phantom)creator(** Like [of_alist]. Consumes a sequence. *)valof_sequence:(('keykey*'data)Sequence.t->[`Okof('key,'data,'phantom)t|`Duplicate_keyof'keykey],'key,'data,'phantom)creator(** Like [of_alist_or_error]. Consumes a sequence. *)valof_sequence_or_error:(('keykey*'data)Sequence.t->('key,'data,'phantom)tOr_error.t,'key,'data,'phantom)creator(** Like [of_alist_exn]. Consumes a sequence. *)valof_sequence_exn:(('keykey*'data)Sequence.t->('key,'data,'phantom)t,'key,'data,'phantom)creator(** Like [of_alist_multi]. Consumes a sequence. *)valof_sequence_multi:(('keykey*'data)Sequence.t->('key,'datalist,'phantom)t,'key,'data,'phantom)creator(** Like [of_alist_fold]. Consumes a sequence. *)valof_sequence_fold:(('keykey*'data)Sequence.t->init:'c->f:('c->'data->'c)->('key,'c,'phantom)t,'key,'data,'phantom)creator(** Like [of_alist_reduce]. Consumes a sequence. *)valof_sequence_reduce:(('keykey*'data)Sequence.t->f:('data->'data->'data)->('key,'data,'phantom)t,'key,'data,'phantom)creator(** Like [of_alist]. Consume values for which keys can be computed. *)valof_list_with_key:('datalist->get_key:('data->'keykey)->[`Okof('key,'data,'phantom)t|`Duplicate_keyof'keykey],'key,'data,'phantom)creator(** Like [of_alist_or_error]. Consume values for which keys can be computed. *)valof_list_with_key_or_error:('datalist->get_key:('data->'keykey)->('key,'data,'phantom)tOr_error.t,'key,'data,'phantom)creator(** Like [of_alist_exn]. Consume values for which keys can be computed. *)valof_list_with_key_exn:('datalist->get_key:('data->'keykey)->('key,'data,'phantom)t,'key,'data,'phantom)creator(** Like [of_alist_multi]. Consume values for which keys can be computed. *)valof_list_with_key_multi:('datalist->get_key:('data->'keykey)->('key,'datalist,'phantom)t,'key,'data,'phantom)creator(** Produces a dictionary of all key/value pairs that [iteri] passes to [~f]. Fails if
a duplicate key is found. *)valof_iteri:(iteri:(f:(key:'keykey->data:'data->unit)->unit)->[`Okof('key,'data,'phantom)t|`Duplicate_keyof'keykey],'key,'data,'phantom)creator(** Like [of_iteri]. Raises on duplicate key. *)valof_iteri_exn:(iteri:(f:(key:'keykey->data:'data->unit)->unit)->('key,'data,'phantom)t,'key,'data,'phantom)creatorendmoduletypeCreators1=sigtypekeytype'datat(** @inline *)includeCreatorswithtype(_,'data,_)t:='datatandtype_key:=keyandtype('fn,_,_,_)creator:='fnendmoduletypeCreators2=sigtype('key,'data)ttype('fn,'key,'data)creator(** @inline *)includeCreatorswithtype('key,'data,_)t:=('key,'data)tandtype'keykey:='keyandtype('fn,'key,'data,_)creator:=('fn,'key,'data)creatorendmoduletypeCreators3=sigtype('key,'data,'phantom)ttype('fn,'key,'data,'phantom)creator(** @inline *)includeCreatorswithtype('key,'data,'phantom)t:=('key,'data,'phantom)tandtype'keykey:='keyandtype('fn,'key,'data,'phantom)creator:=('fn,'key,'data,'phantom)creatorendmoduletypeS=sigtype'keykeytype('key,'data,'phantom)ttype('fn,'key,'data,'phantom)accessortype('fn,'key,'data,'phantom)creator(** @inline *)includeAccessorswithtype('key,'data,'phantom)t:=('key,'data,'phantom)tandtype'keykey:='keykeyandtype('fn,'key,'data,'phantom)accessor:=('fn,'key,'data,'phantom)accessor(** @inline *)includeCreatorswithtype('key,'data,'phantom)t:=('key,'data,'phantom)tandtype'keykey:='keykeyandtype('fn,'key,'data,'phantom)creator:=('fn,'key,'data,'phantom)creatorendmoduletypeS1=sigtypekeytype'datat(** @inline *)includeSwithtype(_,'data,_)t:='datatandtype_key:=keyandtype('fn,_,_,_)accessor:='fnandtype('fn,_,_,_)creator:='fnendmoduletypeS2=sigtype('key,'data)ttype('fn,'key,'data)accessortype('fn,'key,'data)creator(** @inline *)includeSwithtype('key,'data,_)t:=('key,'data)tandtype'keykey:='keyandtype('fn,'key,'data,_)accessor:=('fn,'key,'data)accessorandtype('fn,'key,'data,_)creator:=('fn,'key,'data)creatorendmoduletypeS3=sigtype('key,'data,'phantom)ttype('fn,'key,'data,'phantom)accessortype('fn,'key,'data,'phantom)creator(** @inline *)includeSwithtype('key,'data,'phantom)t:=('key,'data,'phantom)tandtype'keykey:='keyandtype('fn,'key,'data,'phantom)accessor:=('fn,'key,'data,'phantom)accessorandtype('fn,'key,'data,'phantom)creator:=('fn,'key,'data,'phantom)creatorendendmoduletypeDictionary_immutable=sig(** @inline *)includemoduletypeofstructincludeDefinitions(** @inline *)endend