set

package
v0.131.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 27, 2026 License: Apache-2.0 Imports: 2 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SortedSlice added in v0.118.0

func SortedSlice[T cmp.Ordered](s Set[T]) []T

SortedSlice converts the set to a slice sorted in ascending order. It is a standalone function rather than a method because sorting requires T to satisfy cmp.Ordered, a stricter constraint than Set's own comparable.

Types

type Set

type Set[T comparable] map[T]struct{}

Set represents a generic set data structure.

func New

func New[T comparable](elements ...T) Set[T]

New creates a new set and initializes it with the provided elements.

func Union

func Union[T comparable](sets ...Set[T]) Set[T]

Union merges the given sets into a new set containing all unique elements from the input sets.

func (Set[T]) Add

func (s Set[T]) Add(elements ...T)

Add inserts the specified elements into the set.

func (Set[T]) Contains

func (s Set[T]) Contains(element T) bool

Contains checks if the set contains the specified element.

func (Set[T]) Difference

func (s Set[T]) Difference(other Set[T]) Set[T]

Difference returns a new set containing the elements in s that are not in other.

func (Set[T]) Intersects added in v0.118.0

func (s Set[T]) Intersects(other Set[T]) bool

Intersects reports whether s and other share at least one common element.

func (Set[T]) IsEmpty added in v0.118.0

func (s Set[T]) IsEmpty() bool

IsEmpty reports whether the set has no elements.

func (Set[T]) Len

func (s Set[T]) Len() int

Len returns the number of elements in the set.

func (Set[T]) Remove

func (s Set[T]) Remove(element T)

Remove deletes the specified element from the set.

func (Set[T]) ToSlice

func (s Set[T]) ToSlice() []T

ToSlice converts the set to a slice of its elements. The order of elements is not guaranteed; use SortedSlice if a stable, ordered result is required.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL