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