> For the complete documentation index, see [llms.txt](https://docs.verygoodsecurity.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.verygoodsecurity.com/vault/developer-tools/larky/library-api/sets.md).

# sets

Larky 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 larky.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.star.

## sets.ImmutableSet(iterable=None)

Immutable set class.

## sets.Set(iterable=None)

Mutable set class.

## sets.contains(a, e)

Checks for the existence of an element in a set.

**Parameters:**

* **a** – a set, as returned by sets.make().
* **e** – the element to look for.

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

## sets.copy(s)

Creates a new set from another set.

**Parameters:**

**s** – a set, as returned by sets.make().

*Returns:* a new set containing the same elements as s.

## sets.difference(a, b)

*Returns:* the elements in a that are not in b.

**Parameters:**

* **a** – a set, as returned by sets.make().
* **b** – a set, as returned by sets.make().

*Returns:* a set containing the elements that are in a but not in b.

## sets.disjoint(a, b)

*Returns:* whether two sets are disjoint.

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

**Parameters:**

* **a** – a set, as returned by sets.make().
* **b** – a set, as returned by sets.make().

*Returns:* true if a and b are disjoint, False otherwise.

## sets.insert(s, e)

Inserts an element into the set.

Element must be hashable. This mutates the original set.

**Parameters:**

* **s** – a set, as returned by sets.make().
* **e** – the element to be inserted.

*Returns:* the set s with e included.

## sets.intersection(a, b)

*Returns:* the intersection of two sets.

**Parameters:**

* **a** – a set, as returned by sets.make().
* **b** – A set, as returned by sets.make().

*Returns:* a set containing the elements that are in both a and b.

## sets.is\_equal(a, b)

*Returns:* whether two sets are equal.

**Parameters:**

* **a** – a set, as returned by sets.make().
* **b** – a set, as returned by sets.make().

*Returns:* True if a is equal to b, False otherwise.

## sets.is\_subset(a, b)

*Returns:* whether a is a subset of b.

**Parameters:**

* **a** – a set, as returned by sets.make().
* **b** – a set, as returned by sets.make().

*Returns:* True if a is a subset of b, False otherwise.

## sets.length(s)

*Returns:* the number of elements in a set.

**Parameters:**

**s** – a set, as returned by sets.make().

*Returns:* an integer representing the number of elements in the set.

## sets.make(elements=None)

Creates a new set. All elements must be hashable.

**Parameters:**

**elements** – sequence to construct the set out of.

*Returns:* a set containing the passed in values.

## sets.remove(s, e)

Removes an element from the set.

Element must be hashable. This mutates the original set.

**Parameters:**

* **s** – a set, as returned by sets.make().
* **e** – the element to be removed.

*Returns:* The set s with e removed.

## sets.repr(s)

Returns a string value representing the set.

**Parameters:**

**s** – a set, as returned by sets.make().

*Returns:* astring representing the set.

## sets.to\_list(s)

Creates a list from the values in the set.

**Parameters:**

**s** – a set, as returned by sets.make().

*Returns:* a list of values inserted into the set.

## sets.union(\*args)

Returns the union of several sets.

**Parameters:**

\***args** – an arbitrary number of sets.

*Returns:* the set union of all sets in \*args.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.verygoodsecurity.com/vault/developer-tools/larky/library-api/sets.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
