123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666(** Interfaces for mutable dictionary types, such as [Hashtbl.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_mutable]. *)moduleDefinitions=struct(** @canonical Base.Dictionary_mutable.Merge_into_action *)moduleMerge_into_action=structtype'datat=|Remove|Set_toof'dataendmoduletypeAccessors=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:(_,_,'phantom)t->bool(** How many key/value pairs the dictionary contains. *)vallength:(_,_,'phantom)t->int(** All key/value pairs. *)valto_alist:('key,'data,'phantom)t->('keykey*'data)list(** All keys in the dictionary, in the same order as [to_alist]. *)valkeys:('key,_,'phantom)t->'keykeylist(** All values in the dictionary, in the same order as [to_alist]. *)valdata:(_,'data,'phantom)t->'datalist(** Removes all key/value pairs from the dictionary. *)valclear:(_,_,'phantom)t->unit(** A new dictionary containing the same key/value pairs. *)valcopy:('key,'data,'phantom)t->('key,'data,'phantom)t(** Whether [key] has a value. *)valmem:(('key,'data,'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(** Like [find]. Adds the value [default ()] if none exists, then returns it. *)valfind_or_add:(('key,'data,'phantom)t->'keykey->default:(unit->'data)->'data,'key,'data,'phantom)accessor(** Like [find]. Adds [default key] if no value exists. *)valfindi_or_add:(('key,'data,'phantom)t->'keykey->default:('keykey->'data)->'data,'key,'data,'phantom)accessor(** Like [find]. Calls [if_found data] if a value exists, or [if_not_found key]
otherwise. Avoids allocation [Some]. *)valfind_and_call:(('key,'data,'phantom)t->'keykey->if_found:('data->'c)->if_not_found:('keykey->'c)->'c,'key,'data,'phantom)accessor(** Like [findi]. Calls [if_found ~key ~data] if a value exists. *)valfindi_and_call:(('key,'data,'phantom)t->'keykey->if_found:(key:'keykey->data:'data->'c)->if_not_found:('keykey->'c)->'c,'key,'data,'phantom)accessor(** Like [find]. Removes the value for [key], if any, from the dictionary before
returning it. *)valfind_and_remove:(('key,'data,'phantom)t->'keykey->'dataoption,'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->[`Ok|`Duplicate],'key,'data,'phantom)accessor(** Like [add]. Raises on duplicates. *)valadd_exn:(('key,'data,'phantom)t->key:'keykey->data:'data->unit,'key,'data,'phantom)accessor(** Adds or replaces a key/value pair in the dictionary. *)valset:(('key,'data,'phantom)t->key:'keykey->data:'data->unit,'key,'data,'phantom)accessor(** Removes any value for the given key. *)valremove:(('key,'data,'phantom)t->'keykey->unit,'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)->unit,'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)->unit,'key,'data,'phantom)accessor(** Like [update]. Returns the new value. *)valupdate_and_return:('key,'data,'phantom)t->'keykey->f:('dataoption->'data)->'data(** Adds [by] to the value for [key], default 0 if [key] is absent. May remove [key]
if the result is [0], depending on [remove_if_zero]. *)valincr:(?by:int(** default: 1 *)->?remove_if_zero:bool(** default: false *)->('key,int,'phantom)t->'keykey->unit,'key,'data,'phantom)accessor(** Subtracts [by] from the value for [key], default 0 if [key] is absent. May remove
[key] if the result is [0], depending on [remove_if_zero]. *)valdecr:(?by:int(** default: 1 *)->?remove_if_zero:bool(** default: false *)->('key,int,'phantom)t->'keykey->unit,'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->unit,'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,_list,'phantom)t->'keykey->unit,'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,'phantom)t->init:'acc->f:(key:'keykey->data:'data->'acc->'acc)->'acc(** Whether every value satisfies [f]. *)valfor_all:(_,'data,'phantom)t->f:('data->bool)->bool(** Like [for_all]. The predicate may also depend on the associated key. *)valfor_alli:('key,'data,'phantom)t->f:(key:'keykey->data:'data->bool)->bool(** Whether at least one value satisfies [f]. *)valexists:(_,'data,'phantom)t->f:('data->bool)->bool(** Like [exists]. The predicate may also depend on the associated key. *)valexistsi:('key,'data,'phantom)t->f:(key:'keykey->data:'data->bool)->bool(** How many values satisfy [f]. *)valcount:(_,'data,'phantom)t->f:('data->bool)->int(** Like [count]. The predicate may also depend on the associated key. *)valcounti:('key,'data,'phantom)t->f:(key:'keykey->data:'data->bool)->int(** Arbitrary, deterministic key/value pair if non-empty. *)valchoose:('key,'data,'phantom)t->('keykey*'data)option(** Like [choose]. Raises if empty. *)valchoose_exn:('key,'data,'phantom)t->'keykey*'data(** Arbitrary, pseudo-random key/value pair if non-empty. *)valchoose_randomly:?random_state:Random.State.t->('key,'data,'phantom)t->('keykey*'data)option(** Like [choose_randomly]. Raises if empty. *)valchoose_randomly_exn:?random_state:Random.State.t->('key,'data,'phantom)t->'keykey*'data(** Calls [f] for every key. *)valiter_keys:('key,_,'phantom)t->f:('keykey->unit)->unit(** Calls [f] for every value. *)valiter:(_,'data,'phantom)t->f:('data->unit)->unit(** Calls [f] for every key/value pair. *)valiteri:('key,'data,'phantom)t->f:(key:'keykey->data:'data->unit)->unit(** Transforms every value. *)valmap:('key,'data,'phantom)t->f:('data->'c)->('key,'c,'phantom)t(** Like [map]. The transformation may also depend on the associated key. *)valmapi:('key,'data,'phantom)t->f:(key:'keykey->data:'data->'c)->('key,'c,'phantom)t(** Like [map]. Modifies the input. *)valmap_inplace:(_,'data,'phantom)t->f:('data->'data)->unit(** Like [mapi]. Modifies the input. *)valmapi_inplace:('key,'data,'phantom)t->f:(key:'keykey->data:'data->'data)->unit(** 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(** Like [filter_keys]. Modifies the input. *)valfilter_keys_inplace:('key,_,'phantom)t->f:('keykey->bool)->unit(** Like [filter]. Modifies the input. *)valfilter_inplace:(_,'data,'phantom)t->f:('data->bool)->unit(** Like [filteri]. Modifies the input. *)valfilteri_inplace:('key,'data,'phantom)t->f:(key:'keykey->data:'data->bool)->unit(** Produces key/value pairs for which [f] produces [Some]. *)valfilter_map:('key,'data,'phantom)t->f:('data->'coption)->('key,'c,'phantom)t(** Like [filter_map]. The new value may also depend on the associated key. *)valfilter_mapi:('key,'data,'phantom)t->f:(key:'keykey->data:'data->'coption)->('key,'c,'phantom)t(** Like [filter_map]. Modifies the input. *)valfilter_map_inplace:(_,'data,'phantom)t->f:('data->'dataoption)->unit(** Like [filter_mapi]. Modifies the input. *)valfilter_mapi_inplace:('key,'data,'phantom)t->f:(key:'keykey->data:'data->'dataoption)->unit(** 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,'data,'phantom)t->f:('data->('c,'d)Either.t)->('key,'c,'phantom)t*('key,'d,'phantom)t(** Like [partition_map]. The split may also depend on the associated key. *)valpartition_mapi:('key,'data,'phantom)t->f:(key:'keykey->data:'data->('c,'d)Either.t)->('key,'c,'phantom)t*('key,'d,'phantom)t(** Merges two dictionaries by fully traversing both. Not suitable for efficiently
merging lists of dictionaries. See [merge_into] 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,'data3,'phantom)accessor(** Merges two dictionaries by traversing [src] and adding to [dst]. Computes the
effect on [dst] of each key/value pair in [src] using [f]. *)valmerge_into:(src:('key,'data1,'phantom)t->dst:('key,'data2,'phantom)t->f:(key:'keykey->'data1->'data2option->'data2Merge_into_action.t)->unit,'key,'data,'phantom)accessorendmoduletypeAccessors1=sigtypekeytype'datatincludeAccessorswithtype(_,'data,_)t:='datatandtype_key:=keyandtype('fn,_,_,_)accessor:='fnendmoduletypeAccessors2=sigtype('key,'data)ttype('fn,'key,'data)accessorincludeAccessorswithtype('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)accessorincludeAccessorswithtype('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(** Creates a new empty dictionary. *)valcreate:(unit->('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]. On failure, provides all duplicate keys instead of a single
representative. *)valof_alist_report_all_dups:(('keykey*'data)list->[`Okof('key,'data,'phantom)t|`Duplicate_keysof'keykeylist],'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,'datalist,'phantom)creator(** Like [of_alist]. Consume a list of elements for which key/value pairs can be
computed. *)valcreate_mapped:(get_key:('a->'keykey)->get_data:('a->'data)->'alist->[`Okof('key,'data,'phantom)t|`Duplicate_keysof'keykeylist],'key,'data,'phantom)creator(** Like [of_alist]. Consume values for which keys can be computed. *)valcreate_with_key:(get_key:('data->'keykey)->'datalist->[`Okof('key,'data,'phantom)t|`Duplicate_keysof'keykeylist],'key,'data,'phantom)creator(** Like [of_alist_or_error]. Consume values for which keys can be computed. *)valcreate_with_key_or_error:(get_key:('data->'keykey)->'datalist->('key,'data,'phantom)tOr_error.t,'key,'data,'phantom)creator(** Like [of_alist_exn]. Consume values for which keys can be computed. *)valcreate_with_key_exn:(get_key:('data->'keykey)->'datalist->('key,'data,'phantom)t,'key,'data,'phantom)creator(** Like [create_mapped]. Multiple values for a key are [combine]d rather than
producing an error. *)valgroup:(get_key:('a->'keykey)->get_data:('a->'data)->combine:('data->'data->'data)->'alist->('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_mutable=sig(** @inline *)includemoduletypeofstructincludeDefinitions(** @inline *)endend