1Misc.Stdlib.String.Set(3) OCaml library Misc.Stdlib.String.Set(3)
2
3
4
6 Misc.Stdlib.String.Set - no description
7
9 Module Misc.Stdlib.String.Set
10
12 Module Set
13 : sig end
14
15
16
17
18
19
20
21 type elt
22
23
24 The type of the set elements.
25
26
27 type t
28
29
30 The type of sets.
31
32
33
34 val empty : t
35
36 The empty set.
37
38
39
40 val is_empty : t -> bool
41
42 Test whether a set is empty or not.
43
44
45
46 val mem : elt -> t -> bool
47
48
49 mem x s tests whether x belongs to the set s .
50
51
52
53 val add : elt -> t -> t
54
55
56 add x s returns a set containing all elements of s , plus x . If x was
57 already in s , s is returned unchanged (the result of the function is
58 then physically equal to s ).
59
60
61 Before4.03 Physical equality was not ensured.
62
63
64
65
66 val singleton : elt -> t
67
68
69 singleton x returns the one-element set containing only x .
70
71
72
73 val remove : elt -> t -> t
74
75
76 remove x s returns a set containing all elements of s , except x . If x
77 was not in s , s is returned unchanged (the result of the function is
78 then physically equal to s ).
79
80
81 Before4.03 Physical equality was not ensured.
82
83
84
85
86 val union : t -> t -> t
87
88 Set union.
89
90
91
92 val inter : t -> t -> t
93
94 Set intersection.
95
96
97
98 val disjoint : t -> t -> bool
99
100 Test if two sets are disjoint.
101
102
103 Since 4.08.0
104
105
106
107 val diff : t -> t -> t
108
109 Set difference: diff s1 s2 contains the elements of s1 that are not in
110 s2 .
111
112
113
114 val compare : t -> t -> int
115
116 Total ordering between sets. Can be used as the ordering function for
117 doing sets of sets.
118
119
120
121 val equal : t -> t -> bool
122
123
124 equal s1 s2 tests whether the sets s1 and s2 are equal, that is, con‐
125 tain equal elements.
126
127
128
129 val subset : t -> t -> bool
130
131
132 subset s1 s2 tests whether the set s1 is a subset of the set s2 .
133
134
135
136 val iter : (elt -> unit) -> t -> unit
137
138
139 iter f s applies f in turn to all elements of s . The elements of s
140 are presented to f in increasing order with respect to the ordering
141 over the type of the elements.
142
143
144
145 val map : (elt -> elt) -> t -> t
146
147
148 map f s is the set whose elements are f a0 , f a1 ... f
149 aN , where a0 , a1 ... aN are the elements of s .
150
151 The elements are passed to f in increasing order with respect to the
152 ordering over the type of the elements.
153
154 If no element of s is changed by f , s is returned unchanged. (If each
155 output of f is physically equal to its input, the returned set is phys‐
156 ically equal to s .)
157
158
159 Since 4.04.0
160
161
162
163 val fold : (elt -> 'a -> 'a) -> t -> 'a -> 'a
164
165
166 fold f s init computes (f xN ... (f x2 (f x1 init))...) , where x1 ...
167 xN are the elements of s , in increasing order.
168
169
170
171 val for_all : (elt -> bool) -> t -> bool
172
173
174 for_all f s checks if all elements of the set satisfy the predicate f .
175
176
177
178 val exists : (elt -> bool) -> t -> bool
179
180
181 exists f s checks if at least one element of the set satisfies the
182 predicate f .
183
184
185
186 val filter : (elt -> bool) -> t -> t
187
188
189 filter f s returns the set of all elements in s that satisfy predicate
190 f . If f satisfies every element in s , s is returned unchanged (the
191 result of the function is then physically equal to s ).
192
193
194 Before4.03 Physical equality was not ensured.
195
196
197
198
199 val filter_map : (elt -> elt option) -> t -> t
200
201
202 filter_map f s returns the set of all v such that f x = Some v for some
203 element x of s .
204
205 For example,
206 filter_map (fun n -> if n mod 2 = 0 then Some (n / 2) else None) s
207 is the set of halves of the even elements of s .
208
209 If no element of s is changed or dropped by f (if f x = Some x for each
210 element x ), then s is returned unchanged: the result of the function
211 is then physically equal to s .
212
213
214 Since 4.11.0
215
216
217
218 val partition : (elt -> bool) -> t -> t * t
219
220
221 partition f s returns a pair of sets (s1, s2) , where s1 is the set of
222 all the elements of s that satisfy the predicate f , and s2 is the set
223 of all the elements of s that do not satisfy f .
224
225
226
227 val cardinal : t -> int
228
229 Return the number of elements of a set.
230
231
232
233 val elements : t -> elt list
234
235 Return the list of all elements of the given set. The returned list is
236 sorted in increasing order with respect to the ordering Ord.compare ,
237 where Ord is the argument given to Set.Make .
238
239
240
241 val min_elt : t -> elt
242
243 Return the smallest element of the given set (with respect to the
244 Ord.compare ordering), or raise Not_found if the set is empty.
245
246
247
248 val min_elt_opt : t -> elt option
249
250 Return the smallest element of the given set (with respect to the
251 Ord.compare ordering), or None if the set is empty.
252
253
254 Since 4.05
255
256
257
258 val max_elt : t -> elt
259
260 Same as Set.S.min_elt , but returns the largest element of the given
261 set.
262
263
264
265 val max_elt_opt : t -> elt option
266
267 Same as Set.S.min_elt_opt , but returns the largest element of the
268 given set.
269
270
271 Since 4.05
272
273
274
275 val choose : t -> elt
276
277 Return one element of the given set, or raise Not_found if the set is
278 empty. Which element is chosen is unspecified, but equal elements will
279 be chosen for equal sets.
280
281
282
283 val choose_opt : t -> elt option
284
285 Return one element of the given set, or None if the set is empty. Which
286 element is chosen is unspecified, but equal elements will be chosen for
287 equal sets.
288
289
290 Since 4.05
291
292
293
294 val split : elt -> t -> t * bool * t
295
296
297 split x s returns a triple (l, present, r) , where l is the set of ele‐
298 ments of s that are strictly less than x ; r is the set of elements of
299 s that are strictly greater than x ; present is false if s contains no
300 element equal to x , or true if s contains an element equal to x .
301
302
303
304 val find : elt -> t -> elt
305
306
307 find x s returns the element of s equal to x (according to Ord.compare
308 ), or raise Not_found if no such element exists.
309
310
311 Since 4.01.0
312
313
314
315 val find_opt : elt -> t -> elt option
316
317
318 find_opt x s returns the element of s equal to x (according to Ord.com‐
319 pare ), or None if no such element exists.
320
321
322 Since 4.05
323
324
325
326 val find_first : (elt -> bool) -> t -> elt
327
328
329 find_first f s , where f is a monotonically increasing function, re‐
330 turns the lowest element e of s such that f e , or raises Not_found if
331 no such element exists.
332
333 For example, find_first (fun e -> Ord.compare e x >= 0) s will return
334 the first element e of s where Ord.compare e x >= 0 (intuitively: e >=
335 x ), or raise Not_found if x is greater than any element of s .
336
337
338 Since 4.05
339
340
341
342 val find_first_opt : (elt -> bool) -> t -> elt option
343
344
345 find_first_opt f s , where f is a monotonically increasing function,
346 returns an option containing the lowest element e of s such that f e ,
347 or None if no such element exists.
348
349
350 Since 4.05
351
352
353
354 val find_last : (elt -> bool) -> t -> elt
355
356
357 find_last f s , where f is a monotonically decreasing function, returns
358 the highest element e of s such that f e , or raises Not_found if no
359 such element exists.
360
361
362 Since 4.05
363
364
365
366 val find_last_opt : (elt -> bool) -> t -> elt option
367
368
369 find_last_opt f s , where f is a monotonically decreasing function, re‐
370 turns an option containing the highest element e of s such that f e ,
371 or None if no such element exists.
372
373
374 Since 4.05
375
376
377
378 val of_list : elt list -> t
379
380
381 of_list l creates a set from a list of elements. This is usually more
382 efficient than folding add over the list, except perhaps for lists with
383 many duplicated elements.
384
385
386 Since 4.02.0
387
388
389
390
391 Iterators
392 val to_seq_from : elt -> t -> elt Seq.t
393
394
395 to_seq_from x s iterates on a subset of the elements of s in ascending
396 order, from x or above.
397
398
399 Since 4.07
400
401
402
403 val to_seq : t -> elt Seq.t
404
405 Iterate on the whole set, in ascending order
406
407
408 Since 4.07
409
410
411
412 val to_rev_seq : t -> elt Seq.t
413
414 Iterate on the whole set, in descending order
415
416
417 Since 4.12
418
419
420
421 val add_seq : elt Seq.t -> t -> t
422
423 Add the given elements to the set, in order.
424
425
426 Since 4.07
427
428
429
430 val of_seq : elt Seq.t -> t
431
432 Build a set from the given bindings
433
434
435 Since 4.07
436
437
438
439
440
441OCamldoc 2023-07-20 Misc.Stdlib.String.Set(3)