xref: /aosp_15_r20/external/bazel-skylib/docs/new_sets_doc.md (revision bcb5dc7965af6ee42bf2f21341a2ec00233a8c8a)
1<!-- Generated with Stardoc: http://skydoc.bazel.build -->
2
3Skylib module containing common hash-set algorithms.
4
5An empty set can be created using: `sets.make()`, or it can be created with some starting values
6if you pass it an sequence: `sets.make([1, 2, 3])`. This returns a struct containing all of the
7values as keys in a dictionary - this means that all passed in values must be hashable.  The
8values in the set can be retrieved using `sets.to_list(my_set)`.
9
10An arbitrary object can be tested whether it is a set generated by `sets.make()` or not with the
11`types.is_set()` method in types.bzl.
12
13<a id="sets.contains"></a>
14
15## sets.contains
16
17<pre>
18sets.contains(<a href="#sets.contains-a">a</a>, <a href="#sets.contains-e">e</a>)
19</pre>
20
21Checks for the existence of an element in a set.
22
23**PARAMETERS**
24
25
26| Name  | Description | Default Value |
27| :------------- | :------------- | :------------- |
28| <a id="sets.contains-a"></a>a |  A set, as returned by `sets.make()`.   |  none |
29| <a id="sets.contains-e"></a>e |  The element to look for.   |  none |
30
31**RETURNS**
32
33True if the element exists in the set, False if the element does not.
34
35
36<a id="sets.copy"></a>
37
38## sets.copy
39
40<pre>
41sets.copy(<a href="#sets.copy-s">s</a>)
42</pre>
43
44Creates a new set from another set.
45
46**PARAMETERS**
47
48
49| Name  | Description | Default Value |
50| :------------- | :------------- | :------------- |
51| <a id="sets.copy-s"></a>s |  A set, as returned by `sets.make()`.   |  none |
52
53**RETURNS**
54
55A new set containing the same elements as `s`.
56
57
58<a id="sets.difference"></a>
59
60## sets.difference
61
62<pre>
63sets.difference(<a href="#sets.difference-a">a</a>, <a href="#sets.difference-b">b</a>)
64</pre>
65
66Returns the elements in `a` that are not in `b`.
67
68**PARAMETERS**
69
70
71| Name  | Description | Default Value |
72| :------------- | :------------- | :------------- |
73| <a id="sets.difference-a"></a>a |  A set, as returned by `sets.make()`.   |  none |
74| <a id="sets.difference-b"></a>b |  A set, as returned by `sets.make()`.   |  none |
75
76**RETURNS**
77
78A set containing the elements that are in `a` but not in `b`.
79
80
81<a id="sets.disjoint"></a>
82
83## sets.disjoint
84
85<pre>
86sets.disjoint(<a href="#sets.disjoint-a">a</a>, <a href="#sets.disjoint-b">b</a>)
87</pre>
88
89Returns whether two sets are disjoint.
90
91Two sets are disjoint if they have no elements in common.
92
93
94**PARAMETERS**
95
96
97| Name  | Description | Default Value |
98| :------------- | :------------- | :------------- |
99| <a id="sets.disjoint-a"></a>a |  A set, as returned by `sets.make()`.   |  none |
100| <a id="sets.disjoint-b"></a>b |  A set, as returned by `sets.make()`.   |  none |
101
102**RETURNS**
103
104True if `a` and `b` are disjoint, False otherwise.
105
106
107<a id="sets.insert"></a>
108
109## sets.insert
110
111<pre>
112sets.insert(<a href="#sets.insert-s">s</a>, <a href="#sets.insert-e">e</a>)
113</pre>
114
115Inserts an element into the set.
116
117Element must be hashable.  This mutates the original set.
118
119
120**PARAMETERS**
121
122
123| Name  | Description | Default Value |
124| :------------- | :------------- | :------------- |
125| <a id="sets.insert-s"></a>s |  A set, as returned by `sets.make()`.   |  none |
126| <a id="sets.insert-e"></a>e |  The element to be inserted.   |  none |
127
128**RETURNS**
129
130The set `s` with `e` included.
131
132
133<a id="sets.intersection"></a>
134
135## sets.intersection
136
137<pre>
138sets.intersection(<a href="#sets.intersection-a">a</a>, <a href="#sets.intersection-b">b</a>)
139</pre>
140
141Returns the intersection of two sets.
142
143**PARAMETERS**
144
145
146| Name  | Description | Default Value |
147| :------------- | :------------- | :------------- |
148| <a id="sets.intersection-a"></a>a |  A set, as returned by `sets.make()`.   |  none |
149| <a id="sets.intersection-b"></a>b |  A set, as returned by `sets.make()`.   |  none |
150
151**RETURNS**
152
153A set containing the elements that are in both `a` and `b`.
154
155
156<a id="sets.is_equal"></a>
157
158## sets.is_equal
159
160<pre>
161sets.is_equal(<a href="#sets.is_equal-a">a</a>, <a href="#sets.is_equal-b">b</a>)
162</pre>
163
164Returns whether two sets are equal.
165
166**PARAMETERS**
167
168
169| Name  | Description | Default Value |
170| :------------- | :------------- | :------------- |
171| <a id="sets.is_equal-a"></a>a |  A set, as returned by `sets.make()`.   |  none |
172| <a id="sets.is_equal-b"></a>b |  A set, as returned by `sets.make()`.   |  none |
173
174**RETURNS**
175
176True if `a` is equal to `b`, False otherwise.
177
178
179<a id="sets.is_subset"></a>
180
181## sets.is_subset
182
183<pre>
184sets.is_subset(<a href="#sets.is_subset-a">a</a>, <a href="#sets.is_subset-b">b</a>)
185</pre>
186
187Returns whether `a` is a subset of `b`.
188
189**PARAMETERS**
190
191
192| Name  | Description | Default Value |
193| :------------- | :------------- | :------------- |
194| <a id="sets.is_subset-a"></a>a |  A set, as returned by `sets.make()`.   |  none |
195| <a id="sets.is_subset-b"></a>b |  A set, as returned by `sets.make()`.   |  none |
196
197**RETURNS**
198
199True if `a` is a subset of `b`, False otherwise.
200
201
202<a id="sets.length"></a>
203
204## sets.length
205
206<pre>
207sets.length(<a href="#sets.length-s">s</a>)
208</pre>
209
210Returns the number of elements in a set.
211
212**PARAMETERS**
213
214
215| Name  | Description | Default Value |
216| :------------- | :------------- | :------------- |
217| <a id="sets.length-s"></a>s |  A set, as returned by `sets.make()`.   |  none |
218
219**RETURNS**
220
221An integer representing the number of elements in the set.
222
223
224<a id="sets.make"></a>
225
226## sets.make
227
228<pre>
229sets.make(<a href="#sets.make-elements">elements</a>)
230</pre>
231
232Creates a new set.
233
234All elements must be hashable.
235
236
237**PARAMETERS**
238
239
240| Name  | Description | Default Value |
241| :------------- | :------------- | :------------- |
242| <a id="sets.make-elements"></a>elements |  Optional sequence to construct the set out of.   |  `None` |
243
244**RETURNS**
245
246A set containing the passed in values.
247
248
249<a id="sets.remove"></a>
250
251## sets.remove
252
253<pre>
254sets.remove(<a href="#sets.remove-s">s</a>, <a href="#sets.remove-e">e</a>)
255</pre>
256
257Removes an element from the set.
258
259Element must be hashable.  This mutates the original set.
260
261
262**PARAMETERS**
263
264
265| Name  | Description | Default Value |
266| :------------- | :------------- | :------------- |
267| <a id="sets.remove-s"></a>s |  A set, as returned by `sets.make()`.   |  none |
268| <a id="sets.remove-e"></a>e |  The element to be removed.   |  none |
269
270**RETURNS**
271
272The set `s` with `e` removed.
273
274
275<a id="sets.repr"></a>
276
277## sets.repr
278
279<pre>
280sets.repr(<a href="#sets.repr-s">s</a>)
281</pre>
282
283Returns a string value representing the set.
284
285**PARAMETERS**
286
287
288| Name  | Description | Default Value |
289| :------------- | :------------- | :------------- |
290| <a id="sets.repr-s"></a>s |  A set, as returned by `sets.make()`.   |  none |
291
292**RETURNS**
293
294A string representing the set.
295
296
297<a id="sets.str"></a>
298
299## sets.str
300
301<pre>
302sets.str(<a href="#sets.str-s">s</a>)
303</pre>
304
305Returns a string value representing the set.
306
307**PARAMETERS**
308
309
310| Name  | Description | Default Value |
311| :------------- | :------------- | :------------- |
312| <a id="sets.str-s"></a>s |  A set, as returned by `sets.make()`.   |  none |
313
314**RETURNS**
315
316A string representing the set.
317
318
319<a id="sets.to_list"></a>
320
321## sets.to_list
322
323<pre>
324sets.to_list(<a href="#sets.to_list-s">s</a>)
325</pre>
326
327Creates a list from the values in the set.
328
329**PARAMETERS**
330
331
332| Name  | Description | Default Value |
333| :------------- | :------------- | :------------- |
334| <a id="sets.to_list-s"></a>s |  A set, as returned by `sets.make()`.   |  none |
335
336**RETURNS**
337
338A list of values inserted into the set.
339
340
341<a id="sets.union"></a>
342
343## sets.union
344
345<pre>
346sets.union(<a href="#sets.union-args">args</a>)
347</pre>
348
349Returns the union of several sets.
350
351**PARAMETERS**
352
353
354| Name  | Description | Default Value |
355| :------------- | :------------- | :------------- |
356| <a id="sets.union-args"></a>args |  An arbitrary number of sets.   |  none |
357
358**RETURNS**
359
360The set union of all sets in `*args`.
361
362
363