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