123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500(*
This file is derived from the map.mli file from the OCaml distribution.
Changes are marked with the [MOPSA] symbol.
Modifications are Copyright (C) 2017-2019 The MOPSA Project.
Original copyright follows.
*)(***********************************************************************)(* *)(* Objective Caml *)(* *)(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)(* *)(* Copyright 1996 Institut National de Recherche en Informatique et *)(* en Automatique. All rights reserved. This file is distributed *)(* under the terms of the GNU Library General Public License, with *)(* the special exception on linking described in file ../LICENSE. *)(* *)(***********************************************************************)(* $Id: mapext.mli,v 1.1 2014-02-24 16:25:06 mine Exp $ *)moduletypeOrderedType=sigtypet(** The type of the map keys. *)valcompare:t->t->int(** A total ordering function over the keys.
This is a two-argument function [f] such that
[f e1 e2] is zero if the keys [e1] and [e2] are equal,
[f e1 e2] is strictly negative if [e1] is smaller than [e2],
and [f e1 e2] is strictly positive if [e1] is greater than [e2].
Example: a suitable ordering function is the generic structural
comparison function {!Stdlib.compare}. *)end(** Input signature of the functor {!Map.Make}. *)typemap_printer={print_empty:string;(** Special text for empty maps *)print_begin:string;(** Text before the first binding *)print_arrow:string;(** Text between a key and its value *)print_sep:string;(** Text between two bindings *)print_end:string;(** Text after the last binding *)}(** [MOPSA] Tells how to print a map. *)moduletypeS=sigtypekey(** The type of the map keys. *)type(+'a)t(** The type of maps from type [key] to type ['a]. *)valempty:'at(** The empty map. *)valis_empty:'at->bool(** Test whether a map is empty or not. *)valmem:key->'at->bool(** [mem x m] returns [true] if [m] contains a binding for [x],
and [false] otherwise. *)valadd:key->'a->'at->'at(** [add x y m] returns a map containing the same bindings as
[m], plus a binding of [x] to [y]. If [x] was already bound
in [m], its previous binding disappears. *)valsingleton:key->'a->'at(** [singleton x y] returns the one-element map that contains a binding [y]
for [x].
@since 3.12.0
*)valremove:key->'at->'at(** [remove x m] returns a map containing the same bindings as
[m], except for [x] which is unbound in the returned map. *)valremove_min_binding:'at->'atvalmerge:(key->'aoption->'boption->'coption)->'at->'bt->'ct(** [merge f m1 m2] computes a map whose keys is a subset of keys of [m1]
and of [m2]. The presence of each such binding, and the corresponding
value, is determined with the function [f].
@since 3.12.0
*)valcompare:('a->'a->int)->'at->'at->int(** Total ordering between maps. The first argument is a total ordering
used to compare data associated with equal keys in the two maps.
We assume implicitly that [cmp x x] always returns 0.
*)valequal:('a->'a->bool)->'at->'at->bool(** [equal cmp m1 m2] tests whether the maps [m1] and [m2] are
equal, that is, contain equal keys and associate them with
equal data. [cmp] is the equality predicate used to compare
the data associated with the keys.
We assume implicitly that [cmp x x] always returns [true].
*)valiter:(key->'a->unit)->'at->unit(** [iter f m] applies [f] to all bindings in map [m].
[f] receives the key as first argument, and the associated value
as second argument. The bindings are passed to [f] in increasing
order with respect to the ordering over the type of the keys. *)valfold:(key->'a->'b->'b)->'at->'b->'b(** [fold f m a] computes [(f kN dN ... (f k1 d1 a)...)],
where [k1 ... kN] are the keys of all bindings in [m]
(in increasing order), and [d1 ... dN] are the associated data. *)valfor_all:(key->'a->bool)->'at->bool(* [MOPSA] now guarantees the evaluation order *)(** [for_all p m] checks if all the bindings of the map
satisfy the predicate [p].
The predicate [p] is tested on bindings according to the key order.
@since 3.12.0
*)valexists:(key->'a->bool)->'at->bool(* [MOPSA] now guarantees the evaluation order *)(** [exists p m] checks if at least one binding of the map
satisfy the predicate [p].
The predicate [p] is tested on bindings according to the key order.
@since 3.12.0
*)valfilter:(key->'a->bool)->'at->'at(* [MOPSA] now guarantees the evaluation order *)(** [filter p m] returns the map with all the bindings in [m]
that satisfy predicate [p].
The predicate [p] is tested on bindings according to the key order.
@since 3.12.0
*)valpartition:(key->'a->bool)->'at->'at*'at(** [partition p m] returns a pair of maps [(m1, m2)], where
[m1] contains all the bindings of [s] that satisfy the
predicate [p], and [m2] is the map with all the bindings of
[s] that do not satisfy [p].
@since 3.12.0
*)valcardinal:'at->int(** Return the number of bindings of a map.
@since 3.12.0
*)valbindings:'at->(key*'a)list(** Return the list of all bindings of the given map.
The returned list is sorted in increasing order with respect
to the ordering [Ord.compare], where [Ord] is the argument
given to {!Map.Make}.
@since 3.12.0
*)valmin_binding:'at->(key*'a)(** Return the smallest binding of the given map
(with respect to the [Ord.compare] ordering), or raise
[Not_found] if the map is empty.
@since 3.12.0
*)valmax_binding:'at->(key*'a)(** Same as {!Map.S.min_binding}, but returns the largest binding
of the given map.
@since 3.12.0
*)valchoose:'at->(key*'a)(** Return one binding of the given map, or raise [Not_found] if
the map is empty. Which binding is chosen is unspecified,
but equal bindings will be chosen for equal maps.
@since 3.12.0
*)valsplit:key->'at->'at*'aoption*'at(** [split x m] returns a triple [(l, data, r)], where
[l] is the map with all the bindings of [m] whose key
is strictly less than [x];
[r] is the map with all the bindings of [m] whose key
is strictly greater than [x];
[data] is [None] if [m] contains no binding for [x],
or [Some v] if [m] binds [v] to [x].
@since 3.12.0
*)valfind:key->'at->'a(** [find x m] returns the current binding of [x] in [m],
or raises [Not_found] if no such binding exists. *)valfind_opt:key->'at->'aoption(** [find_opt x m] returns [Some v] if the current binding of [x] in [m]
is [v], or [None] if no such binding exists.
@since 4.05
*)valmap:('a->'b)->'at->'bt(** [map f m] returns a map with same domain as [m], where the
associated value [a] of all bindings of [m] has been
replaced by the result of the application of [f] to [a].
The bindings are passed to [f] in increasing order
with respect to the ordering over the type of the keys. *)valmapi:(key->'a->'b)->'at->'bt(** Same as {!Map.S.map}, but the function receives as arguments both the
key and the associated value for each binding of the map. *)(* [MOPSA] additions *)(** {2 Additional functions} *)valis_singleton:'at->bool(** [is_singleton m] checks whether a map contains only one binding *)valof_list:(key*'a)list->'at(** [of_list l] converts an association list to a map. *)valmap2:(key->'a->'b->'c)->'at->'bt->'ct(** [map2 f m1 m2] is similar to [map] but applies [f] to pairs
of bindings [a1] from [m1] and [a2] from [m2] corresponding to
the same key to construct a new map with the same key set.
[m1] and [m2] must have the same key sets.
The bindings are passed to [f] in increasing order of key. *)valiter2:(key->'a->'b->unit)->'at->'bt->unit(** [iter2 f m1 m2] is similar to [map] but applies [f] to pairs
of bindings [a1] from [m1] and [a2] from [m2] corresponding to
the same key.
[m1] and [m2] must have the same key sets.
The bindings are passed to [f] in increasing order of key. *)valfold2:(key->'a->'b->'c->'c)->'at->'bt->'c->'c(** [fold2 f m1 m2 x] is similar to [fold] but applies [f] to pairs
of bindings [a1] from [m1] and [a2] from [m2] corresponding to
the same key.
[m1] and [m2] must have the same key sets.
The bindings are passed to [f] in increasing order of keys. *)valfor_all2:(key->'a->'b->bool)->'at->'bt->bool(** [for_all2 f m1 m2] is similar to [for_all] but applies [f] to pairs
of bindings [a1] from [m1] and [a2] from [m2] corresponding to
the same key.
[m1] and [m2] must have the same key sets.
The bindings are passed to [f] in increasing order of keys. *)valexists2:(key->'a->'b->bool)->'at->'bt->bool(** [exists2 f m1 m2] is similar to [exists] but applies [f] to pairs
of bindings [a1] from [m1] and [a2] from [m2] corresponding to
the same key.
[m1] and [m2] must have the same key sets.
The bindings are passed to [f] in increasing order of keys. *)valmap2z:(key->'a->'a->'a)->'at->'at->'at(** [map2z f m1 m2] is similar to [map2 f m1 m2], but physically
equal subtrees are put unchanged into the result instead of
being traversed.
This is more efficient than [map2], and equivalent if [f] is
side-effect free and idem-potent ([f k a a = a]).
[m1] and [m2] must have the same key sets.
The bindings are passed to [f] in increasing order of keys. *)valiter2z:(key->'a->'a->unit)->'at->'at->unit(** [iter2z f m1 m2] is similar to [iter2 f m1 m2], but physically
equal subtrees are ignored.
This is more efficient than [iter2], and equivalent if
[f k a a] has no effect.
[m1] and [m2] must have the same key sets.
The bindings are passed to [f] in increasing order of keys. *)valfold2z:(key->'a->'a->'b->'b)->'at->'at->'b->'b(** [fold2z f m1 m2 a] is similar to [fold2 f m1 m2 a], but physically
equal subtrees are ignored.
This is more efficient than [fold2], and equivalent if
[f k a a x = x] and has no effect.
[m1] and [m2] must have the same key sets.
The bindings are passed to [f] in increasing order of keys. *)valfor_all2z:(key->'a->'a->bool)->'at->'at->bool(** [for_all2z f m1 m2] is similar to [for_all2 f m1 m2], but returns
[true] for physically equal subtrees without traversing them.
This is more efficient than [for_all2z], and equivalent if
[f k a a = true] and has no effect.
[m1] and [m2] must have the same key sets.
The bindings are passed to [f] in increasing order of keys. *)valexists2z:(key->'a->'a->bool)->'at->'at->bool(** [exists2z f m1 m2] is similar to [exists2 f m1 m2], but returns
[false] for physically equal subtrees without traversing them.
This is more efficient than [exists2z], and equivalent if
[f k a a = false] and has no effect.
[m1] and [m2] must have the same key sets.
The bindings are passed to [f] in increasing order of keys. *)valmap2o:(key->'a->'c)->(key->'b->'c)->(key->'a->'b->'c)->'at->'bt->'ct(** [map2o f1 f2 f m1 m2] is similar to [map2 f m1 m2], but
accepts maps defined over different sets of keys.
To get a new binding, [f1] is used for keys appearing only
in [m1], [f2] for keys appearing only in [m2], and [f] for
keys appearing in both maps.
The returned map has bindings for all keys appearing in either
[m1] or [m2].
The bindings are passed to [f], [f1], [f2] in increasing order of keys. *)valiter2o:(key->'a->unit)->(key->'b->unit)->(key->'a->'b->unit)->'at->'bt->unit(** [iter2o f1 f2 f m1 m2] is similar to [iter2 f m1 m2], but
accepts maps defined over different sets of keys.
[f1] is called for keys appearing only in [m1],
[f2] for keys appearing only in [m2],
and [f] for keys appearing in both maps.
The bindings are passed to [f], [f1], [f2] in increasing order of keys. *)valfold2o:(key->'a->'c->'c)->(key->'b->'c->'c)->(key->'a->'b->'c->'c)->'at->'bt->'c->'c(** [fold2o f1 f2 f m1 m2 a] is similar to [fold2 f m1 m2 a], but
accepts maps defined over different sets of keys.
[f1] is called for keys appearing only in [m1],
[f2] for keys appearing only in [m2],
and [f] for keys appearing in both maps.
The bindings are passed to [f], [f1], [f2] in increasing order of keys. *)valfor_all2o:(key->'a->bool)->(key->'b->bool)->(key->'a->'b->bool)->'at->'bt->bool(** [for_all2o f1 f2 f m1 m2] is similar to [for_all2 f m1 m2], but
accepts maps defined over different sets of keys.
[f1] is called for keys appearing only in [m1],
[f2] for keys appearing only in [m2],
and [f] for keys appearing in both maps.
The bindings are passed to [f], [f1], [f2] in increasing order of keys. *)valexists2o:(key->'a->bool)->(key->'b->bool)->(key->'a->'b->bool)->'at->'bt->bool(** [fexists2o f1 f2 f m1 m2] is similar to [fexists2 f m1 m2], but
accepts maps defined over different sets of keys.
[f1] is called for keys appearing only in [m1],
[f2] for keys appearing only in [m2],
and [f] for keys appearing in both maps.
The bindings are passed to [f], [f1], [f2] in increasing order of keys. *)valmap2zo:(key->'a->'a)->(key->'a->'a)->(key->'a->'a->'a)->'at->'at->'at(** [map2zo f1 f2 f m1 m2] is similar to [map2o f1 f2 f m1 m2] but,
similary to [map2z], [f] is not called on physically equal
subtrees.
This is more efficient than [map2o], and equivalent if [f] is
side-effect free and idem-potent ([f k a a = a]).
The returned map has bindings for all keys appearing in either
[m1] or [m2].
The bindings are passed to [f], [f1], [f2] in increasing order of keys. *)valiter2zo:(key->'a->unit)->(key->'a->unit)->(key->'a->'a->unit)->'at->'at->unit(** [iter2zo f1 f2 f m1 m2] is similar to [iter2o f1 f2 f m1 m2] but,
similary to [iter2z], [f] is not called on physically equal
subtrees.
This is more efficient than [iter2o], and equivalent if [f] is
side-effect free.
The bindings are passed to [f], [f1], [f2] in increasing order of keys. *)valfold2zo:(key->'a->'b->'b)->(key->'a->'b->'b)->(key->'a->'a->'b->'b)->'at->'at->'b->'b(** [fold2zo f1 f2 f m1 m2 a] is similar to [fold2o f1 f2 f m1 m2 a] but,
similary to [fold2z], [f] is not called on physically equal
subtrees.
This is more efficient than [fold2o], and equivalent if
[f k a a x = x] and has no side-effect.
The bindings are passed to [f], [f1], [f2] in increasing order of keys. *)valfor_all2zo:(key->'a->bool)->(key->'a->bool)->(key->'a->'a->bool)->'at->'at->bool(** [for_all2zo f1 f2 f m1 m2] is similar to [for_all2o f1 f2 f m1 m2] but,
similary to [for_all2z], [f] is not called on physically equal
subtrees.
This is more efficient than [for_all2o], and equivalent if
[f k a a = true] and has no side-effect.
The bindings are passed to [f], [f1], [f2] in increasing order of keys. *)valexists2zo:(key->'a->bool)->(key->'a->bool)->(key->'a->'a->bool)->'at->'at->bool(** [exists2zo f1 f2 f m1 m2] is similar to [exists2o f1 f2 f m1 m2] but,
similary to [exists2z], [f] is not called on physically equal
subtrees.
This is more efficient than [exists2o], and equivalent if
[f k a a = false] and has no side-effect.
The bindings are passed to [f], [f1], [f2] in increasing order of keys. *)valmap_slice:(key->'a->'a)->'at->key->key->'at(** [map_slice f m k1 k2] is similar to [map f m], but only applies
[f] to bindings with key greater or equal to [k1] and smaller
or equal to [k2] to construct the returned map. Bindings with
keys outside this range in [m] are put unchanged in the result.
It is as if, outside this range, [f k a = a] and has no effect.
The result has the same key set as [m].
The bindings are passed to [f] in increasing order of keys,
between [k1] and [k2]. *)valiter_slice:(key->'a->unit)->'at->key->key->unit(** [iter_slice f m k1 k2] is similar to [iter f m], but only calls
[f] on bindings with key greater or equal to [k1] and smaller
or equal to [k2].
It is as if, outside this range, [f k a] has no effect.
The bindings are passed to [f] in increasing order of keys,
between [k1] and [k2]. *)valfold_slice:(key->'a->'b->'b)->'at->key->key->'b->'b(** [fold_slice f m k1 k2 a] is similar to [fold f m], but only calls
[f] on bindings with key greater or equal to [k1] and smaller
or equal to [k2].
It is as if, outside this range, [f k a x = x] and has no effect.
The bindings are passed to [f] in increasing order of keys,
between [k1] and [k2]. *)valfor_all_slice:(key->'a->bool)->'at->key->key->bool(** [for_all_slice f m k1 k2 a] is similar to [for_all f m], but only calls
[f] on bindings with key greater or equal to [k1] and smaller
or equal to [k2].
It is as if, outside this range, [f k a = true] and has no effect.
The bindings are passed to [f] in increasing order of keys,
between [k1] and [k2]. *)valexists_slice:(key->'a->bool)->'at->key->key->bool(** [exists_slice f m k1 k2 a] is similar to [exists f m], but only calls
[f] on bindings with key greater or equal to [k1] and smaller
or equal to [k2].
It is as if, outside this range, [f k a = false] and has no effect.
The bindings are passed to [f] in increasing order of keys,
between [k1] and [k2]. *)valkey_equal:'at->'at->bool(** [key_equal m1 m2] returns true if [m1] and [m2] are defined
over exactly the same set of keys (but with possibly different
values).
*)valkey_subset:'at->'at->bool(** [key_equal m1 m2] returns true if [m1] is defined on a subset of
the keys of [m2] (but with possibly different values).
*)valfind_greater:key->'at->key*'a(** [find_greater k m] returns the binding (key and value) in [m]
with key strictly greater than [k] and as small as possible.
Raises [Not_found] if [m] has no binding for a key strictly greater
than [k].
*)valfind_less:key->'at->key*'a(** [find_less k m] returns the binding (key and value) in [m]
with key strictly less than [k] and as large as possible.
Raises [Not_found] if [m] has no binding for a key strictly less
than [k].
*)valfind_greater_equal:key->'at->key*'a(** [find_greater_euql k m] returns the binding (key and value) in [m]
with key greater or equal to [k] and as small as possible.
Raises [Not_found] if [m] has no binding for a key greater or equal
to [k].
*)valfind_less_equal:key->'at->key*'a(** [find_less_equal k m] returns the binding (key and value) in [m]
with key less or equal to [k] and as large as possible.
Raises [Not_found] if [m] has no binding for a key less or equal
to [k].
*)(** {2 Printing} *)valto_string:map_printer->(key->string)->('a->string)->'at->string(** String representation. *)valprint:map_printer->(out_channel->key->unit)->(out_channel->'a->unit)->out_channel->'at->unit(** Prints to an output_channel (for Printf.(f)printf). *)valfprint:map_printer->(Format.formatter->key->unit)->(Format.formatter->'a->unit)->Format.formatter->'at->unit(** Prints to a formatter (for Format.(f)printf). *)valbprint:map_printer->(Buffer.t->key->unit)->(Buffer.t->'a->unit)->Buffer.t->'at->unit(** Prints to a string buffer (for Printf.bprintf). *)(** {2 Translation to polymorphic maps} *)valto_poly_map:'at->(key,'a)MapExtPoly.tend(** Output signature of the functor {!MapExt.Make}. *)