man-pages/man3/Misc.Stdlib.String.Map.3o.html
2021-03-31 01:06:50 +01:00

1213 lines
13 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of Misc.Stdlib.String.Map</TITLE>
</HEAD><BODY>
<H1>Misc.Stdlib.String.Map</H1>
Section: OCaml library (3o)<BR>Updated: 2020-01-30<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
Misc.Stdlib.String.Map - no description
<A NAME="lbAC">&nbsp;</A>
<H2>Module</H2>
Module Misc.Stdlib.String.Map
<A NAME="lbAD">&nbsp;</A>
<H2>Documentation</H2>
<P>
Module
<B>Map</B>
<BR>&nbsp;:&nbsp;
<B>sig end</B>
<P>
<P>
<P>
<P>
<P>
<P>
<P>
<I>type key </I>
<P>
<P>
The type of the map keys.
<P>
<P>
<I>type </I>
<B>+'a</B>
<I>t </I>
<P>
<P>
The type of maps from type
<B>key</B>
to type
<B>'a</B>
.
<P>
<P>
<P>
<I>val empty </I>
:
<B>'a t</B>
<P>
The empty map.
<P>
<P>
<P>
<I>val is_empty </I>
:
<B>'a t -&gt; bool</B>
<P>
Test whether a map is empty or not.
<P>
<P>
<P>
<I>val mem </I>
:
<B>key -&gt; 'a t -&gt; bool</B>
<P>
<P>
<B>mem x m</B>
returns
<B>true</B>
if
<B>m</B>
contains a binding for
<B>x</B>
,
and
<B>false</B>
otherwise.
<P>
<P>
<P>
<I>val add </I>
:
<B>key -&gt; 'a -&gt; 'a t -&gt; 'a t</B>
<P>
<P>
<B>add x y m</B>
returns a map containing the same bindings as
<B>m</B>
, plus a binding of
<B>x</B>
to
<B>y</B>
. If
<B>x</B>
was already bound
in
<B>m</B>
to a value that is physically equal to
<B>y</B>
,
<B>m</B>
is returned unchanged (the result of the function is
then physically equal to
<B>m</B>
). Otherwise, the previous binding
of
<B>x</B>
in
<B>m</B>
disappears.
<P>
<P>
<B>Before4.03</B>
Physical equality was not ensured.
<P>
<P>
<P>
<P>
<I>val update </I>
:
<B>key -&gt; ('a option -&gt; 'a option) -&gt; 'a t -&gt; 'a t</B>
<P>
<P>
<B>update x f m</B>
returns a map containing the same bindings as
<B>m</B>
, except for the binding of
<B>x</B>
. Depending on the value of
<B>y</B>
where
<B>y</B>
is
<B>f (find_opt x m)</B>
, the binding of
<B>x</B>
is
added, removed or updated. If
<B>y</B>
is
<B>None</B>
, the binding is
removed if it exists; otherwise, if
<B>y</B>
is
<B>Some z</B>
then
<B>x</B>
is associated to
<B>z</B>
in the resulting map. If
<B>x</B>
was already
bound in
<B>m</B>
to a value that is physically equal to
<B>z</B>
,
<B>m</B>
is returned unchanged (the result of the function is then
physically equal to
<B>m</B>
).
<P>
<P>
<B>Since</B>
4.06.0
<P>
<P>
<P>
<I>val singleton </I>
:
<B>key -&gt; 'a -&gt; 'a t</B>
<P>
<P>
<B>singleton x y</B>
returns the one-element map that contains a binding
<B>y</B>
for
<B>x</B>
.
<P>
<P>
<B>Since</B>
3.12.0
<P>
<P>
<P>
<I>val remove </I>
:
<B>key -&gt; 'a t -&gt; 'a t</B>
<P>
<P>
<B>remove x m</B>
returns a map containing the same bindings as
<B>m</B>
, except for
<B>x</B>
which is unbound in the returned map.
If
<B>x</B>
was not in
<B>m</B>
,
<B>m</B>
is returned unchanged
(the result of the function is then physically equal to
<B>m</B>
).
<P>
<P>
<B>Before4.03</B>
Physical equality was not ensured.
<P>
<P>
<P>
<P>
<I>val merge </I>
:
<B>(key -&gt; 'a option -&gt; 'b option -&gt; 'c option) -&gt;</B>
<B>'a t -&gt; 'b t -&gt; 'c t</B>
<P>
<P>
<B>merge f m1 m2</B>
computes a map whose keys is a subset of keys of
<B>m1</B>
and of
<B>m2</B>
. The presence of each such binding, and the corresponding
value, is determined with the function
<B>f</B>
.
In terms of the
<B>find_opt</B>
operation, we have
<B>find_opt x (merge f m1 m2) = f (find_opt x m1) (find_opt x m2)</B>
for any key
<B>x</B>
, provided that
<B>f None None = None</B>
.
<P>
<P>
<B>Since</B>
3.12.0
<P>
<P>
<P>
<I>val union </I>
:
<B>(key -&gt; 'a -&gt; 'a -&gt; 'a option) -&gt;</B>
<B>'a t -&gt; 'a t -&gt; 'a t</B>
<P>
<P>
<B>union f m1 m2</B>
computes a map whose keys is the union of keys
of
<B>m1</B>
and of
<B>m2</B>
. When the same binding is defined in both
arguments, the function
<B>f</B>
is used to combine them.
This is a special case of
<B>merge</B>
:
<B>union f m1 m2</B>
is equivalent
to
<B>merge f' m1 m2</B>
, where
<P>
-
<B>f' _key None None = None</B>
<P>
<P>
-
<B>f' _key (Some v) None = Some v</B>
<P>
<P>
-
<B>f' _key None (Some v) = Some v</B>
<P>
<P>
-
<B>f' key (Some v1) (Some v2) = f key v1 v2</B>
<P>
<P>
<P>
<P>
<B>Since</B>
4.03.0
<P>
<P>
<P>
<I>val compare </I>
:
<B>('a -&gt; 'a -&gt; int) -&gt; 'a t -&gt; 'a t -&gt; int</B>
<P>
Total ordering between maps. The first argument is a total ordering
used to compare data associated with equal keys in the two maps.
<P>
<P>
<P>
<I>val equal </I>
:
<B>('a -&gt; 'a -&gt; bool) -&gt; 'a t -&gt; 'a t -&gt; bool</B>
<P>
<P>
<B>equal cmp m1 m2</B>
tests whether the maps
<B>m1</B>
and
<B>m2</B>
are
equal, that is, contain equal keys and associate them with
equal data.
<B>cmp</B>
is the equality predicate used to compare
the data associated with the keys.
<P>
<P>
<P>
<I>val iter </I>
:
<B>(key -&gt; 'a -&gt; unit) -&gt; 'a t -&gt; unit</B>
<P>
<P>
<B>iter f m</B>
applies
<B>f</B>
to all bindings in map
<B>m</B>
.
<B>f</B>
receives the key as first argument, and the associated value
as second argument. The bindings are passed to
<B>f</B>
in increasing
order with respect to the ordering over the type of the keys.
<P>
<P>
<P>
<I>val fold </I>
:
<B>(key -&gt; 'a -&gt; 'b -&gt; 'b) -&gt; 'a t -&gt; 'b -&gt; 'b</B>
<P>
<P>
<B>fold f m a</B>
computes
<B>(f kN dN ... (f k1 d1 a)...)</B>
,
where
<B>k1 ... kN</B>
are the keys of all bindings in
<B>m</B>
(in increasing order), and
<B>d1 ... dN</B>
are the associated data.
<P>
<P>
<P>
<I>val for_all </I>
:
<B>(key -&gt; 'a -&gt; bool) -&gt; 'a t -&gt; bool</B>
<P>
<P>
<B>for_all p m</B>
checks if all the bindings of the map
satisfy the predicate
<B>p</B>
.
<P>
<P>
<B>Since</B>
3.12.0
<P>
<P>
<P>
<I>val exists </I>
:
<B>(key -&gt; 'a -&gt; bool) -&gt; 'a t -&gt; bool</B>
<P>
<P>
<B>exists p m</B>
checks if at least one binding of the map
satisfies the predicate
<B>p</B>
.
<P>
<P>
<B>Since</B>
3.12.0
<P>
<P>
<P>
<I>val filter </I>
:
<B>(key -&gt; 'a -&gt; bool) -&gt; 'a t -&gt; 'a t</B>
<P>
<P>
<B>filter p m</B>
returns the map with all the bindings in
<B>m</B>
that satisfy predicate
<B>p</B>
. If
<B>p</B>
satisfies every binding in
<B>m</B>
,
<B>m</B>
is returned unchanged (the result of the function is then
physically equal to
<B>m</B>
)
<P>
<P>
<B>Before4.03</B>
Physical equality was not ensured.
<P>
<P>
<P>
<B>Since</B>
3.12.0
<P>
<P>
<P>
<I>val partition </I>
:
<B>(key -&gt; 'a -&gt; bool) -&gt; 'a t -&gt; 'a t * 'a t</B>
<P>
<P>
<B>partition p m</B>
returns a pair of maps
<B>(m1, m2)</B>
, where
<B>m1</B>
contains all the bindings of
<B>s</B>
that satisfy the
predicate
<B>p</B>
, and
<B>m2</B>
is the map with all the bindings of
<B>s</B>
that do not satisfy
<B>p</B>
.
<P>
<P>
<B>Since</B>
3.12.0
<P>
<P>
<P>
<I>val cardinal </I>
:
<B>'a t -&gt; int</B>
<P>
Return the number of bindings of a map.
<P>
<P>
<B>Since</B>
3.12.0
<P>
<P>
<P>
<I>val bindings </I>
:
<B>'a t -&gt; (key * 'a) list</B>
<P>
Return the list of all bindings of the given map.
The returned list is sorted in increasing order of keys with respect
to the ordering
<B>Ord.compare</B>
, where
<B>Ord</B>
is the argument
given to
<B>Map.Make</B>
.
<P>
<P>
<B>Since</B>
3.12.0
<P>
<P>
<P>
<I>val min_binding </I>
:
<B>'a t -&gt; key * 'a</B>
<P>
Return the binding with the smallest key in a given map
(with respect to the
<B>Ord.compare</B>
ordering), or raise
<B>Not_found</B>
if the map is empty.
<P>
<P>
<B>Since</B>
3.12.0
<P>
<P>
<P>
<I>val min_binding_opt </I>
:
<B>'a t -&gt; (key * 'a) option</B>
<P>
Return the binding with the smallest key in the given map
(with respect to the
<B>Ord.compare</B>
ordering), or
<B>None</B>
if the map is empty.
<P>
<P>
<B>Since</B>
4.05
<P>
<P>
<P>
<I>val max_binding </I>
:
<B>'a t -&gt; key * 'a</B>
<P>
Same as
<B>Map.S.min_binding</B>
, but returns the binding with
the largest key in the given map.
<P>
<P>
<B>Since</B>
3.12.0
<P>
<P>
<P>
<I>val max_binding_opt </I>
:
<B>'a t -&gt; (key * 'a) option</B>
<P>
Same as
<B>Map.S.min_binding_opt</B>
, but returns the binding with
the largest key in the given map.
<P>
<P>
<B>Since</B>
4.05
<P>
<P>
<P>
<I>val choose </I>
:
<B>'a t -&gt; key * 'a</B>
<P>
Return one binding of the given map, or raise
<B>Not_found</B>
if
the map is empty. Which binding is chosen is unspecified,
but equal bindings will be chosen for equal maps.
<P>
<P>
<B>Since</B>
3.12.0
<P>
<P>
<P>
<I>val choose_opt </I>
:
<B>'a t -&gt; (key * 'a) option</B>
<P>
Return one binding of the given map, or
<B>None</B>
if
the map is empty. Which binding is chosen is unspecified,
but equal bindings will be chosen for equal maps.
<P>
<P>
<B>Since</B>
4.05
<P>
<P>
<P>
<I>val split </I>
:
<B>key -&gt; 'a t -&gt; 'a t * 'a option * 'a t</B>
<P>
<P>
<B>split x m</B>
returns a triple
<B>(l, data, r)</B>
, where
<B>l</B>
is the map with all the bindings of
<B>m</B>
whose key
is strictly less than
<B>x</B>
;
<B>r</B>
is the map with all the bindings of
<B>m</B>
whose key
is strictly greater than
<B>x</B>
;
<B>data</B>
is
<B>None</B>
if
<B>m</B>
contains no binding for
<B>x</B>
,
or
<B>Some v</B>
if
<B>m</B>
binds
<B>v</B>
to
<B>x</B>
.
<P>
<P>
<B>Since</B>
3.12.0
<P>
<P>
<P>
<I>val find </I>
:
<B>key -&gt; 'a t -&gt; 'a</B>
<P>
<P>
<B>find x m</B>
returns the current binding of
<B>x</B>
in
<B>m</B>
,
or raises
<B>Not_found</B>
if no such binding exists.
<P>
<P>
<P>
<I>val find_opt </I>
:
<B>key -&gt; 'a t -&gt; 'a option</B>
<P>
<P>
<B>find_opt x m</B>
returns
<B>Some v</B>
if the current binding of
<B>x</B>
in
<B>m</B>
is
<B>v</B>
, or
<B>None</B>
if no such binding exists.
<P>
<P>
<B>Since</B>
4.05
<P>
<P>
<P>
<I>val find_first </I>
:
<B>(key -&gt; bool) -&gt; 'a t -&gt; key * 'a</B>
<P>
<P>
<B>find_first f m</B>
, where
<B>f</B>
is a monotonically increasing function,
returns the binding of
<B>m</B>
with the lowest key
<B>k</B>
such that
<B>f k</B>
,
or raises
<B>Not_found</B>
if no such key exists.
<P>
For example,
<B>find_first (fun k -&gt; Ord.compare k x &gt;= 0) m</B>
will return
the first binding
<B>k, v</B>
of
<B>m</B>
where
<B>Ord.compare k x &gt;= 0</B>
(intuitively:
<B>k &gt;= x</B>
), or raise
<B>Not_found</B>
if
<B>x</B>
is greater than any
element of
<B>m</B>
.
<P>
<P>
<B>Since</B>
4.05
<P>
<P>
<P>
<I>val find_first_opt </I>
:
<B>(key -&gt; bool) -&gt; 'a t -&gt; (key * 'a) option</B>
<P>
<P>
<B>find_first_opt f m</B>
, where
<B>f</B>
is a monotonically increasing function,
returns an option containing the binding of
<B>m</B>
with the lowest key
<B>k</B>
such that
<B>f k</B>
, or
<B>None</B>
if no such key exists.
<P>
<P>
<B>Since</B>
4.05
<P>
<P>
<P>
<I>val find_last </I>
:
<B>(key -&gt; bool) -&gt; 'a t -&gt; key * 'a</B>
<P>
<P>
<B>find_last f m</B>
, where
<B>f</B>
is a monotonically decreasing function,
returns the binding of
<B>m</B>
with the highest key
<B>k</B>
such that
<B>f k</B>
,
or raises
<B>Not_found</B>
if no such key exists.
<P>
<P>
<B>Since</B>
4.05
<P>
<P>
<P>
<I>val find_last_opt </I>
:
<B>(key -&gt; bool) -&gt; 'a t -&gt; (key * 'a) option</B>
<P>
<P>
<B>find_last_opt f m</B>
, where
<B>f</B>
is a monotonically decreasing function,
returns an option containing the binding of
<B>m</B>
with the highest key
<B>k</B>
such that
<B>f k</B>
, or
<B>None</B>
if no such key exists.
<P>
<P>
<B>Since</B>
4.05
<P>
<P>
<P>
<I>val map </I>
:
<B>('a -&gt; 'b) -&gt; 'a t -&gt; 'b t</B>
<P>
<P>
<B>map f m</B>
returns a map with same domain as
<B>m</B>
, where the
associated value
<B>a</B>
of all bindings of
<B>m</B>
has been
replaced by the result of the application of
<B>f</B>
to
<B>a</B>
.
The bindings are passed to
<B>f</B>
in increasing order
with respect to the ordering over the type of the keys.
<P>
<P>
<P>
<I>val mapi </I>
:
<B>(key -&gt; 'a -&gt; 'b) -&gt; 'a t -&gt; 'b t</B>
<P>
Same as
<B>Map.S.map</B>
, but the function receives as arguments both the
key and the associated value for each binding of the map.
<P>
<P>
<P>
<P>
<A NAME="lbAE">&nbsp;</A>
<H3>Iterators</H3>
<P>
<P>
<P>
<I>val to_seq </I>
:
<B>'a t -&gt; (key * 'a) Seq.t</B>
<P>
Iterate on the whole map, in ascending order of keys
<P>
<P>
<B>Since</B>
4.07
<P>
<P>
<P>
<I>val to_seq_from </I>
:
<B>key -&gt; 'a t -&gt; (key * 'a) Seq.t</B>
<P>
<P>
<B>to_seq_from k m</B>
iterates on a subset of the bindings of
<B>m</B>
,
in ascending order of keys, from key
<B>k</B>
or above.
<P>
<P>
<B>Since</B>
4.07
<P>
<P>
<P>
<I>val add_seq </I>
:
<B>(key * 'a) Seq.t -&gt; 'a t -&gt; 'a t</B>
<P>
Add the given bindings to the map, in order.
<P>
<P>
<B>Since</B>
4.07
<P>
<P>
<P>
<I>val of_seq </I>
:
<B>(key * 'a) Seq.t -&gt; 'a t</B>
<P>
Build a map from the given bindings
<P>
<P>
<B>Since</B>
4.07
<P>
<P>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="1"><A HREF="#lbAB">NAME</A><DD>
<DT id="2"><A HREF="#lbAC">Module</A><DD>
<DT id="3"><A HREF="#lbAD">Documentation</A><DD>
<DL>
<DT id="4"><A HREF="#lbAE">Iterators</A><DD>
</DL>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:48 GMT, March 31, 2021
</BODY>
</HTML>