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