1Set.Make(3)                      OCaml library                     Set.Make(3)
2
3
4

NAME

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

Module

10       Module   Set.Make
11

Documentation

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       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 : (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 : (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 : (elt -> 'a -> 'a) -> t -> 'a -> 'a
176
177
178       fold  f  s  a computes (f xN ... (f x2 (f x1 a))...)  , where x1 ... xN
179       are the elements of s , in increasing order.
180
181
182
183       val for_all : (elt -> bool) -> t -> bool
184
185
186       for_all p s checks if all elements of the set satisfy the predicate p .
187
188
189
190       val exists : (elt -> bool) -> t -> bool
191
192
193       exists p s checks if at least one element  of  the  set  satisfies  the
194       predicate p .
195
196
197
198       val filter : (elt -> bool) -> t -> t
199
200
201       filter  p s returns the set of all elements in s that satisfy predicate
202       p . If p satisfies every element in s , s is  returned  unchanged  (the
203       result of the function is then physically equal to s ).
204
205
206       Before4.03 Physical equality was not ensured.
207
208
209
210
211       val filter_map : (elt -> elt option) -> t -> t
212
213
214       filter_map f s returns the set of all v such that f x = Some v for some
215       element x of s .
216
217       For example,
218       filter_map (fun n -> if n mod 2 = 0 then Some (n / 2) else None) s
219       is the set of halves of the even elements of s .
220
221       If no element of s is changed or dropped by f (if f x = Some x for each
222       element  x  ), then s is returned unchanged: the result of the function
223       is then physically equal to s .
224
225
226       Since 4.11.0
227
228
229
230       val partition : (elt -> bool) -> t -> t * t
231
232
233       partition p s returns a pair of sets (s1, s2) , where s1 is the set  of
234       all  the elements of s that satisfy the predicate p , and s2 is the set
235       of all the elements of s that do not satisfy p .
236
237
238
239       val cardinal : t -> int
240
241       Return the number of elements of a set.
242
243
244
245       val elements : t -> elt list
246
247       Return the list of all elements of the given set.  The returned list is
248       sorted  in  increasing order with respect to the ordering Ord.compare ,
249       where Ord is the argument given to Set.Make .
250
251
252
253       val min_elt : t -> elt
254
255       Return the smallest element of the  given  set  (with  respect  to  the
256       Ord.compare ordering), or raise Not_found if the set is empty.
257
258
259
260       val min_elt_opt : t -> elt option
261
262       Return  the  smallest  element  of  the  given set (with respect to the
263       Ord.compare ordering), or None if the set is empty.
264
265
266       Since 4.05
267
268
269
270       val max_elt : t -> elt
271
272       Same as Set.S.min_elt , but returns the largest element  of  the  given
273       set.
274
275
276
277       val max_elt_opt : t -> elt option
278
279       Same  as  Set.S.min_elt_opt  ,  but  returns the largest element of the
280       given set.
281
282
283       Since 4.05
284
285
286
287       val choose : t -> elt
288
289       Return one element of the given set, or raise Not_found if the  set  is
290       empty.  Which element is chosen is unspecified, but equal elements will
291       be chosen for equal sets.
292
293
294
295       val choose_opt : t -> elt option
296
297       Return one element of the given set, or None if the set is empty. Which
298       element is chosen is unspecified, but equal elements will be chosen for
299       equal sets.
300
301
302       Since 4.05
303
304
305
306       val split : elt -> t -> t * bool * t
307
308
309       split x s returns a triple (l, present, r) , where l is the set of ele‐
310       ments  of s that are strictly less than x ; r is the set of elements of
311       s that are strictly greater than x ; present is false if s contains  no
312       element equal to x , or true if s contains an element equal to x .
313
314
315
316       val find : elt -> t -> elt
317
318
319       find  x s returns the element of s equal to x (according to Ord.compare
320       ), or raise Not_found if no such element exists.
321
322
323       Since 4.01.0
324
325
326
327       val find_opt : elt -> t -> elt option
328
329
330       find_opt x s returns the element of s equal to x (according to Ord.com‐
331       pare ), or None if no such element exists.
332
333
334       Since 4.05
335
336
337
338       val find_first : (elt -> bool) -> t -> elt
339
340
341       find_first  f  s  , where f is a monotonically increasing function, re‐
342       turns the lowest element e of s such that f e , or raises Not_found  if
343       no such element exists.
344
345       For  example,  find_first (fun e -> Ord.compare e x >= 0) s will return
346       the first element e of s where Ord.compare e x >= 0 (intuitively: e  >=
347       x ), or raise Not_found if x is greater than any element of s .
348
349
350       Since 4.05
351
352
353
354       val find_first_opt : (elt -> bool) -> t -> elt option
355
356
357       find_first_opt  f  s  , where f is a monotonically increasing function,
358       returns an option containing the lowest element e of s such that f e  ,
359       or None if no such element exists.
360
361
362       Since 4.05
363
364
365
366       val find_last : (elt -> bool) -> t -> elt
367
368
369       find_last f s , where f is a monotonically decreasing function, returns
370       the highest element e of s such that f e , or raises  Not_found  if  no
371       such element exists.
372
373
374       Since 4.05
375
376
377
378       val find_last_opt : (elt -> bool) -> t -> elt option
379
380
381       find_last_opt f s , where f is a monotonically decreasing function, re‐
382       turns an option containing the highest element e of s such that f  e  ,
383       or None if no such element exists.
384
385
386       Since 4.05
387
388
389
390       val of_list : elt list -> t
391
392
393       of_list  l creates a set from a list of elements.  This is usually more
394       efficient than folding add over the list, except perhaps for lists with
395       many duplicated elements.
396
397
398       Since 4.02.0
399
400
401
402
403   Iterators
404       val to_seq_from : elt -> t -> elt Seq.t
405
406
407       to_seq_from  x s iterates on a subset of the elements of s in ascending
408       order, from x or above.
409
410
411       Since 4.07
412
413
414
415       val to_seq : t -> elt Seq.t
416
417       Iterate on the whole set, in ascending order
418
419
420       Since 4.07
421
422
423
424       val add_seq : elt Seq.t -> t -> t
425
426       Add the given elements to the set, in order.
427
428
429       Since 4.07
430
431
432
433       val of_seq : elt Seq.t -> t
434
435       Build a set from the given bindings
436
437
438       Since 4.07
439
440
441
442
443
444OCamldoc                          2021-01-26                       Set.Make(3)
Impressum