Skip to content

Latest commit

 

History

History
executable file
·
392 lines (215 loc) · 8.27 KB

new_sets_doc.md

File metadata and controls

executable file
·
392 lines (215 loc) · 8.27 KB

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.

sets.contains

load("@bazel_skylib//lib:new_sets.bzl", "sets")

sets.contains(a, e)

Checks for the existence of an element in a set.

PARAMETERS

Name Description Default Value
a A set, as returned by sets.make(). none
e The element to look for. none

RETURNS

True if the element exists in the set, False if the element does not.

sets.copy

load("@bazel_skylib//lib:new_sets.bzl", "sets")

sets.copy(s)

Creates a new set from another set.

PARAMETERS

Name Description Default Value
s A set, as returned by sets.make(). none

RETURNS

A new set containing the same elements as s.

sets.difference

load("@bazel_skylib//lib:new_sets.bzl", "sets")

sets.difference(a, b)

Returns the elements in a that are not in b.

PARAMETERS

Name Description Default Value
a A set, as returned by sets.make(). none
b A set, as returned by sets.make(). none

RETURNS

A set containing the elements that are in a but not in b.

sets.disjoint

load("@bazel_skylib//lib:new_sets.bzl", "sets")

sets.disjoint(a, b)

Returns whether two sets are disjoint.

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

PARAMETERS

Name Description Default Value
a A set, as returned by sets.make(). none
b A set, as returned by sets.make(). none

RETURNS

True if a and b are disjoint, False otherwise.

sets.insert

load("@bazel_skylib//lib:new_sets.bzl", "sets")

sets.insert(s, e)

Inserts an element into the set.

Element must be hashable. This mutates the original set.

PARAMETERS

Name Description Default Value
s A set, as returned by sets.make(). none
e The element to be inserted. none

RETURNS

The set s with e included.

sets.intersection

load("@bazel_skylib//lib:new_sets.bzl", "sets")

sets.intersection(a, b)

Returns the intersection of two sets.

PARAMETERS

Name Description Default Value
a A set, as returned by sets.make(). none
b A set, as returned by sets.make(). none

RETURNS

A set containing the elements that are in both a and b.

sets.is_equal

load("@bazel_skylib//lib:new_sets.bzl", "sets")

sets.is_equal(a, b)

Returns whether two sets are equal.

PARAMETERS

Name Description Default Value
a A set, as returned by sets.make(). none
b A set, as returned by sets.make(). none

RETURNS

True if a is equal to b, False otherwise.

sets.is_subset

load("@bazel_skylib//lib:new_sets.bzl", "sets")

sets.is_subset(a, b)

Returns whether a is a subset of b.

PARAMETERS

Name Description Default Value
a A set, as returned by sets.make(). none
b A set, as returned by sets.make(). none

RETURNS

True if a is a subset of b, False otherwise.

sets.length

load("@bazel_skylib//lib:new_sets.bzl", "sets")

sets.length(s)

Returns the number of elements in a set.

PARAMETERS

Name Description Default Value
s A set, as returned by sets.make(). none

RETURNS

An integer representing the number of elements in the set.

sets.make

load("@bazel_skylib//lib:new_sets.bzl", "sets")

sets.make(elements)

Creates a new set.

All elements must be hashable.

PARAMETERS

Name Description Default Value
elements Optional sequence to construct the set out of. None

RETURNS

A set containing the passed in values.

sets.remove

load("@bazel_skylib//lib:new_sets.bzl", "sets")

sets.remove(s, e)

Removes an element from the set.

Element must be hashable. This mutates the original set.

PARAMETERS

Name Description Default Value
s A set, as returned by sets.make(). none
e The element to be removed. none

RETURNS

The set s with e removed.

sets.repr

load("@bazel_skylib//lib:new_sets.bzl", "sets")

sets.repr(s)

Returns a string value representing the set.

PARAMETERS

Name Description Default Value
s A set, as returned by sets.make(). none

RETURNS

A string representing the set.

sets.str

load("@bazel_skylib//lib:new_sets.bzl", "sets")

sets.str(s)

Returns a string value representing the set.

PARAMETERS

Name Description Default Value
s A set, as returned by sets.make(). none

RETURNS

A string representing the set.

sets.to_list

load("@bazel_skylib//lib:new_sets.bzl", "sets")

sets.to_list(s)

Creates a list from the values in the set.

PARAMETERS

Name Description Default Value
s A set, as returned by sets.make(). none

RETURNS

A list of values inserted into the set.

sets.union

load("@bazel_skylib//lib:new_sets.bzl", "sets")

sets.union(*args)

Returns the union of several sets.

PARAMETERS

Name Description Default Value
args An arbitrary number of sets. none

RETURNS

The set union of all sets in *args.