Skylib module containing common hash-set algorithms.

An empty set can be created using: sets.make(), or it can be created with some starting values if you pass it an sequence: sets.make([1, 2, 3]). This returns a struct containing all of the values as keys in a dictionary - this means that all passed in values must be hashable. The values in the set can be retrieved using sets.to_list(my_set).

An arbitrary object can be tested whether it is a set generated by sets.make() or not with the types.is_set() method in types.bzl.

Macros and Functions

sets.make

Creates a new set.

All elements must be hashable.

elements

Optional sequence to construct the set out of.


sets.copy

Creates a new set from another set.

s

A set, as returned by sets.make().


sets.to_list

Creates a list from the values in the set.

s

A set, as returned by sets.make().


sets.insert

Inserts an element into the set.

Element must be hashable. This mutates the original set.

s

A set, as returned by sets.make().

e

The element to be inserted.


sets.contains

Checks for the existence of an element in a set.

a

A set, as returned by sets.make().

e

The element to look for.


sets.is_equal

Returns whether two sets are equal.

a

A set, as returned by sets.make().

b

A set, as returned by sets.make().


sets.is_subset

Returns whether a is a subset of b.

a

A set, as returned by sets.make().

b

A set, as returned by sets.make().


sets.disjoint

Returns whether two sets are disjoint.

Two sets are disjoint if they have no elements in common.

a

A set, as returned by sets.make().

b

A set, as returned by sets.make().


sets.intersection

Returns the intersection of two sets.

a

A set, as returned by sets.make().

b

A set, as returned by sets.make().


sets.union

Returns the union of several sets.

args

An arbitrary number of sets.


sets.difference

Returns the elements in a that are not in b.

a

A set, as returned by sets.make().

b

A set, as returned by sets.make().


sets.length

Returns the number of elements in a set.

s

A set, as returned by sets.make().


sets.remove

Removes an element from the set.

Element must be hashable. This mutates the original set.

s

A set, as returned by sets.make().

e

The element to be removed.


sets.repr

Returns a string value representing the set.

s

A set, as returned by sets.make().


sets.str

Returns a string value representing the set.

s

A set, as returned by sets.make().