set

package
v0.85.0-pre.7 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2026 License: BSD-3-Clause Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Set

type Set[T comparable] struct {
	// contains filtered or unexported fields
}

Set is a generic set data structure that holds unique values of any comparable type T.

func New

func New[T comparable](from ...[]T) *Set[T]

New creates a new Set. If an optional slice of values is provided, those values are added to the set.

func (*Set[T]) Add

func (s *Set[T]) Add(val T)

Add adds the specified value to the set. If the value is already present, it has no effect.

func (*Set[T]) Clear

func (s *Set[T]) Clear()

Clear removes all elements from the set.

func (*Set[T]) Diff

func (s *Set[T]) Diff(other *Set[T]) *Set[T]

Diff returns a new Set containing elements in s that are not in other.

func (*Set[T]) Equals

func (s *Set[T]) Equals(other *Set[T]) bool

Equals returns true if s and other contain the same elements, regardless of order.

func (*Set[T]) Has

func (s *Set[T]) Has(val T) bool

Has returns true if the set contains the specified value.

func (*Set[T]) HasAll

func (s *Set[T]) HasAll(val ...T) bool

HasAll returns true if the set contains all the specified values.

func (*Set[T]) HasAny

func (s *Set[T]) HasAny(val ...T) bool

HasAny returns true if the set contains any of the specified values.

func (*Set[T]) Intersect

func (s *Set[T]) Intersect(other *Set[T]) *Set[T]

Intersect returns a new Set containing elements that are in both s and other.

func (*Set[T]) IsEmpty

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

IsEmpty returns true if the set contains no elements.

func (*Set[T]) Len

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

Len returns the number of elements in the set.

func (*Set[T]) Range

func (s *Set[T]) Range() iter.Seq[T]

Range calls the provided function for each element in the set.

func (*Set[T]) Remove

func (s *Set[T]) Remove(val T)

Remove removes the specified value from the set. If the value is not present, it has no effect.

func (*Set[T]) Replace

func (s *Set[T]) Replace(vals []T)

Replace replaces the contents of the set with the provided slice of values.

func (*Set[T]) Slice

func (s *Set[T]) Slice() []T

Slice returns a slice containing all elements in the set. The order of elements is not guaranteed.

func (*Set[T]) Union

func (s *Set[T]) Union(other *Set[T]) *Set[T]

Union returns a new Set containing all elements that are in either s or other.

Jump to

Keyboard shortcuts

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