1Map.Make(3)                        OCamldoc                        Map.Make(3)
2
3
4

NAME

6       Map.Make  -  Functor  building  an  implementation of the map structure
7       given a totally ordered type.
8

Module

10       Module   Map.Make
11

Documentation

13       Module Make
14        : functor (Ord : OrderedType) -> sig end
15
16
17       Functor building an implementation of the map structure given a totally
18       ordered type.
19
20
21       Parameters:
22
23       "Ord"
24
25       Map.OrderedType
26
27
28
29
30
31
32
33       type key
34
35
36       The type of the map keys.
37
38
39       type +'a t
40
41
42       The type of maps from type key to type 'a .
43
44
45
46       val empty : 'a t
47
48       The empty map.
49
50
51
52       val is_empty : 'a t -> bool
53
54       Test whether a map is empty or not.
55
56
57
58       val mem : key -> 'a t -> bool
59
60
61       mem  x  m returns true if m contains a binding for x , and false other‐
62       wise.
63
64
65
66       val add : key -> 'a -> 'a t -> 'a t
67
68
69       add x y m returns a map containing the same bindings  as  m  ,  plus  a
70       binding  of  x  to  y  . If x was already bound in m to a value that is
71       physically equal to y , m is returned  unchanged  (the  result  of  the
72       function is then physically equal to m ). Otherwise, the previous bind‐
73       ing of x in m disappears.
74
75
76       Before4.03 Physical equality was not ensured.
77
78
79
80
81       val singleton : key -> 'a -> 'a t
82
83
84       singleton x y returns the one-element map that contains a binding y for
85       x .
86
87
88       Since 3.12.0
89
90
91
92       val remove : key -> 'a t -> 'a t
93
94
95       remove x m returns a map containing the same bindings as m , except for
96       x which is unbound in the returned map.  If x was  not  in  m  ,  m  is
97       returned unchanged (the result of the function is then physically equal
98       to m ).
99
100
101       Before4.03 Physical equality was not ensured.
102
103
104
105
106       val merge : (key -> 'a option -> 'b option -> 'c option) -> 'a t ->  'b
107       t -> 'c t
108
109
110       merge  f  m1 m2 computes a map whose keys is a subset of keys of m1 and
111       of m2 . The presence of each such binding, and the corresponding value,
112       is  determined  with  the function f .  In terms of the find_opt opera‐
113       tion, we have find_opt x (merge f m1 m2) = f (find_opt x m1)  (find_opt
114       x m2) for any key x , provided that f None None = None .
115
116
117       Since 3.12.0
118
119
120
121       val union : (key -> 'a -> 'a -> 'a option) -> 'a t -> 'a t -> 'a t
122
123
124       union  f m1 m2 computes a map whose keys is the union of keys of m1 and
125       of m2 .  When the same binding is defined in both arguments, the  func‐
126       tion  f  is  used  to  combine them.  This is a special case of merge :
127       union f m1 m2 is equivalent to merge f' m1 m2 , where
128
129       - f' None None = None
130
131
132       - f' (Some v) None = Some v
133
134
135       - f' None (Some v) = Some v
136
137
138       - f' (Some v1) (Some v2) = f v1 v2
139
140
141
142
143       Since 4.03.0
144
145
146
147       val compare : ('a -> 'a -> int) -> 'a t -> 'a t -> int
148
149       Total ordering between maps.  The first argument is  a  total  ordering
150       used to compare data associated with equal keys in the two maps.
151
152
153
154       val equal : ('a -> 'a -> bool) -> 'a t -> 'a t -> bool
155
156
157       equal  cmp  m1  m2 tests whether the maps m1 and m2 are equal, that is,
158       contain equal keys and associate them with  equal  data.   cmp  is  the
159       equality predicate used to compare the data associated with the keys.
160
161
162
163       val iter : (key -> 'a -> unit) -> 'a t -> unit
164
165
166       iter  f  m  applies f to all bindings in map m .  f receives the key as
167       first argument, and the associated value as second argument.  The bind‐
168       ings  are  passed to f in increasing order with respect to the ordering
169       over the type of the keys.
170
171
172
173       val fold : (key -> 'a -> 'b -> 'b) -> 'a t -> 'b -> 'b
174
175
176       fold f m a computes (f kN dN ... (f k1 d1 a)...)  , where k1 ... kN are
177       the  keys of all bindings in m (in increasing order), and d1 ... dN are
178       the associated data.
179
180
181
182       val for_all : (key -> 'a -> bool) -> 'a t -> bool
183
184
185       for_all p m checks if all the bindings of the map satisfy the predicate
186       p .
187
188
189       Since 3.12.0
190
191
192
193       val exists : (key -> 'a -> bool) -> 'a t -> bool
194
195
196       exists  p  m  checks  if  at least one binding of the map satisfies the
197       predicate p .
198
199
200       Since 3.12.0
201
202
203
204       val filter : (key -> 'a -> bool) -> 'a t -> 'a t
205
206
207       filter p m returns the map with all the  bindings  in  m  that  satisfy
208       predicate  p  .  If  p  satisfies  every  binding  in m , m is returned
209       unchanged (the result of the function is then physically equal to m )
210
211
212       Before4.03 Physical equality was not ensured.
213
214
215
216       Since 3.12.0
217
218
219
220       val partition : (key -> 'a -> bool) -> 'a t -> 'a t * 'a t
221
222
223       partition p m returns a pair of maps (m1, m2) , where m1  contains  all
224       the bindings of s that satisfy the predicate p , and m2 is the map with
225       all the bindings of s that do not satisfy p .
226
227
228       Since 3.12.0
229
230
231
232       val cardinal : 'a t -> int
233
234       Return the number of bindings of a map.
235
236
237       Since 3.12.0
238
239
240
241       val bindings : 'a t -> (key * 'a) list
242
243       Return the list of all bindings of the given map.  The returned list is
244       sorted  in  increasing order with respect to the ordering Ord.compare ,
245       where Ord is the argument given to Map.Make .
246
247
248       Since 3.12.0
249
250
251
252       val min_binding : 'a t -> key * 'a
253
254       Return the smallest binding of the  given  map  (with  respect  to  the
255       Ord.compare ordering), or raise Not_found if the map is empty.
256
257
258       Since 3.12.0
259
260
261
262       val min_binding_opt : 'a t -> (key * 'a) option
263
264       Return  the  smallest  binding  of  the  given map (with respect to the
265       Ord.compare ordering), or None if the map is empty.
266
267
268       Since 4.05
269
270
271
272       val max_binding : 'a t -> key * 'a
273
274       Same as Map.S.min_binding , but returns  the  largest  binding  of  the
275       given map.
276
277
278       Since 3.12.0
279
280
281
282       val max_binding_opt : 'a t -> (key * 'a) option
283
284       Same  as Map.S.min_binding_opt , but returns the largest binding of the
285       given map.
286
287
288       Since 4.05
289
290
291
292       val choose : 'a t -> key * 'a
293
294       Return one binding of the given map, or raise Not_found if the  map  is
295       empty.  Which binding is chosen is unspecified, but equal bindings will
296       be chosen for equal maps.
297
298
299       Since 3.12.0
300
301
302
303       val choose_opt : 'a t -> (key * 'a) option
304
305       Return one binding of the given map, or None if the map is empty. Which
306       binding is chosen is unspecified, but equal bindings will be chosen for
307       equal maps.
308
309
310       Since 4.05
311
312
313
314       val split : key -> 'a t -> 'a t * 'a option * 'a t
315
316
317       split x m returns a triple (l, data, r) , where l is the map  with  all
318       the bindings of m whose key is strictly less than x ; r is the map with
319       all the bindings of m whose key is strictly greater than x  ;  data  is
320       None if m contains no binding for x , or Some v if m binds v to x .
321
322
323       Since 3.12.0
324
325
326
327       val find : key -> 'a t -> 'a
328
329
330       find x m returns the current binding of x in m , or raises Not_found if
331       no such binding exists.
332
333
334
335       val find_opt : key -> 'a t -> 'a option
336
337
338       find_opt x m returns Some v if the current binding of x in m is v ,  or
339       None if no such binding exists.
340
341
342       Since 4.05
343
344
345
346       val find_first : (key -> bool) -> 'a t -> key * 'a
347
348
349       find_first  f  m  ,  where  f  is  a monotonically increasing function,
350       returns the binding of m with the lowest key k  such  that  f  k  ,  or
351       raises Not_found if no such key exists.
352
353       For  example,  find_first (fun k -> Ord.compare k x >= 0) m will return
354       the first binding k, v of m where Ord.compare k x >= 0 (intuitively:  k
355       >= x ), or raise Not_found if x is greater than any element of m .
356
357
358       Since 4.05
359
360
361
362       val find_first_opt : (key -> bool) -> 'a t -> (key * 'a) option
363
364
365       find_first_opt  f  m  , where f is a monotonically increasing function,
366       returns an option containing the binding of m with  the  lowest  key  k
367       such that f k , or None if no such key exists.
368
369
370       Since 4.05
371
372
373
374       val find_last : (key -> bool) -> 'a t -> key * 'a
375
376
377       find_last f m , where f is a monotonically decreasing function, returns
378       the binding of m with the highest key k such  that  f  k  ,  or  raises
379       Not_found if no such key exists.
380
381
382       Since 4.05
383
384
385
386       val find_last_opt : (key -> bool) -> 'a t -> (key * 'a) option
387
388
389       find_last_opt  f  m  ,  where f is a monotonically decreasing function,
390       returns an option containing the binding of m with the  highest  key  k
391       such that f k , or None if no such key exists.
392
393
394       Since 4.05
395
396
397
398       val map : ('a -> 'b) -> 'a t -> 'b t
399
400
401       map  f  m  returns  a  map with same domain as m , where the associated
402       value a of all bindings of m has been replaced by  the  result  of  the
403       application  of  f  to  a .  The bindings are passed to f in increasing
404       order with respect to the ordering over the type of the keys.
405
406
407
408       val mapi : (key -> 'a -> 'b) -> 'a t -> 'b t
409
410       Same as Map.S.map , but the function receives as arguments both the key
411       and the associated value for each binding of the map.
412
413
414
415
416
4172018-04-14                          source:                        Map.Make(3)
Impressum