set

package
v1.86.4 Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2025 License: BSD-3-Clause Imports: 10 Imported by: 38

Documentation

Overview

Package set contains set types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handle

type Handle struct {
	// contains filtered or unexported fields
}

Handle is an opaque comparable value that's used as the map key in a HandleSet. The only way to get one is to call HandleSet.Add.

type HandleSet

type HandleSet[T any] map[Handle]T

HandleSet is a set of T.

It is not safe for concurrent use.

func (*HandleSet[T]) Add

func (s *HandleSet[T]) Add(e T) Handle

Add adds the element (map value) e to the set.

It returns the handle (map key) with which e can be removed, using a map delete.

type IntSet added in v1.86.0

type IntSet[T constraints.Integer] struct {
	// contains filtered or unexported fields
}

IntSet is a set optimized for integer values close to zero or set of integers that are close in value.

func (*IntSet[T]) Add added in v1.86.0

func (s *IntSet[T]) Add(e T)

Add adds e to the set.

When storing a IntSet in a map as a value type, it is important to re-assign the map entry after calling Add or Delete, as the IntSet's representation may change.

func (*IntSet[T]) AddSeq added in v1.86.0

func (s *IntSet[T]) AddSeq(seq iter.Seq[T])

AddSeq adds the values from seq to the set.

func (IntSet[T]) Clone added in v1.86.0

func (s IntSet[T]) Clone() IntSet[T]

Clone returns a copy of s that doesn't alias the original.

func (IntSet[T]) Contains added in v1.86.0

func (s IntSet[T]) Contains(e T) bool

Contains reports whether e is in the set.

func (*IntSet[T]) Delete added in v1.86.0

func (s *IntSet[T]) Delete(e T)

Delete removes e from the set.

When storing a IntSet in a map as a value type, it is important to re-assign the map entry after calling Add or Delete, as the IntSet's representation may change.

func (IntSet[T]) Len added in v1.86.0

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

Len reports the number of elements in the set.

func (IntSet[T]) Values added in v1.86.0

func (s IntSet[T]) Values() iter.Seq[T]

Values returns an iterator over the elements of the set. The iterator will yield the elements in no particular order.

type Set added in v1.42.0

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

Set is a set of T.

func Of added in v1.66.0

func Of[T comparable](slice ...T) Set[T]

Of returns a new set constructed from the elements in slice.

func SetOf added in v1.52.0

func SetOf[T comparable](slice []T) Set[T]

SetOf returns a new set constructed from the elements in slice.

func (Set[T]) Add added in v1.42.0

func (s Set[T]) Add(e T)

Add adds e to s.

func (Set[T]) AddSet added in v1.54.0

func (s Set[T]) AddSet(es Set[T])

AddSet adds each element of es to s.

func (Set[T]) AddSlice added in v1.52.0

func (s Set[T]) AddSlice(es []T)

AddSlice adds each element of es to s.

func (Set[T]) Clone added in v1.54.0

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

Clone returns a new set cloned from the elements in s.

func (Set[T]) Contains added in v1.42.0

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

Contains reports whether s contains e.

func (Set[T]) Delete added in v1.50.0

func (s Set[T]) Delete(e T)

Delete removes e from the set.

func (Set[T]) Equal added in v1.54.0

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

Equal reports whether s is equal to other.

func (Set[T]) Len added in v1.42.0

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

Len reports the number of items in s.

func (*Set[T]) Make added in v1.66.0

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

Make lazily initializes the map pointed to by s to be non-nil.

func (Set[T]) MarshalJSON added in v1.56.0

func (s Set[T]) MarshalJSON() ([]byte, error)

func (Set[T]) Slice added in v1.52.0

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

Slice returns the elements of the set as a slice. The elements will not be in any particular order.

func (*Set[T]) UnmarshalJSON added in v1.56.0

func (s *Set[T]) UnmarshalJSON(buf []byte) error

type Slice added in v1.40.0

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

Slice is a set of elements tracked in a slice of unique elements.

func (*Slice[T]) Add added in v1.40.0

func (ss *Slice[T]) Add(vs ...T)

Add adds each element in vs to the set. The amortized cost is O(1) per element.

func (*Slice[T]) AddSlice added in v1.40.0

func (ss *Slice[T]) AddSlice(vs views.Slice[T])

AddSlice adds all elements in vs to the set.

func (*Slice[T]) Contains added in v1.40.0

func (ss *Slice[T]) Contains(v T) bool

Contains reports whether v is in the set. The amortized cost is O(1).

func (*Slice[T]) Len added in v1.50.0

func (ss *Slice[T]) Len() int

Len returns the number of elements in the set.

func (*Slice[T]) Remove added in v1.40.0

func (ss *Slice[T]) Remove(v T)

Remove removes v from the set. The cost is O(n).

func (*Slice[T]) Slice added in v1.40.0

func (ss *Slice[T]) Slice() views.Slice[T]

Slice returns a view of the underlying slice. The elements are in order of insertion. The returned value is only valid until ss is modified again.

type SmallSet added in v1.86.0

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

SmallSet is a set that is optimized for reducing memory overhead when the expected size of the set is 0 or 1 elements.

The zero value of SmallSet is a usable empty set.

When storing a SmallSet in a map as a value type, it is important to re-assign the map entry after calling Add or Delete, as the SmallSet's representation may change.

Copying a SmallSet by value may alias the previous value. Use the Clone method to create a new SmallSet with the same contents.

func (*SmallSet[T]) Add added in v1.86.0

func (s *SmallSet[T]) Add(e T)

Add adds e to the set.

When storing a SmallSet in a map as a value type, it is important to re-assign the map entry after calling Add or Delete, as the SmallSet's representation may change.

func (SmallSet[T]) Clone added in v1.86.0

func (s SmallSet[T]) Clone() SmallSet[T]

Clone returns a copy of s that doesn't alias the original.

func (SmallSet[T]) Contains added in v1.86.0

func (s SmallSet[T]) Contains(e T) bool

Contains reports whether e is in the set.

func (*SmallSet[T]) Delete added in v1.86.0

func (s *SmallSet[T]) Delete(e T)

Delete removes e from the set.

When storing a SmallSet in a map as a value type, it is important to re-assign the map entry after calling Add or Delete, as the SmallSet's representation may change.

func (SmallSet[T]) Len added in v1.86.0

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

Len reports the number of elements in the set.

func (SmallSet[T]) SoleElement added in v1.86.0

func (s SmallSet[T]) SoleElement() (e T, ok bool)

SoleElement returns the single value in the set, if the set has exactly one element.

If the set is empty or has more than one element, ok will be false and e will be the zero value of T.

func (SmallSet[T]) Values added in v1.86.0

func (s SmallSet[T]) Values() iter.Seq[T]

Values returns an iterator over the elements of the set. The iterator will yield the elements in no particular order.

Jump to

Keyboard shortcuts

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