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