tailscale.comtailscale.com/util/set Index | Files

package set

import "tailscale.com/util/set"

Package set contains set types.

Index

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 Set

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

Set is a set of T.

func Of

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

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

func SetOf

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

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

func (Set[T]) Add

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

Add adds e to s.

func (Set[T]) AddSet

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

AddSet adds each element of es to s.

func (Set[T]) AddSlice

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

AddSlice adds each element of es to s.

func (Set[T]) Clone

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

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

func (Set[T]) Contains

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

Contains reports whether s contains e.

func (Set[T]) Delete

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

Delete removes e from the set.

func (Set[T]) Equal

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

Equal reports whether s is equal to other.

func (Set[T]) Len

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

Len reports the number of items in s.

func (*Set[T]) Make

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

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

func (Set[T]) MarshalJSON

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

func (Set[T]) Slice

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

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

type Slice

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

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

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

AddSlice adds all elements in vs to the set.

func (*Slice[T]) Contains

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

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

Len returns the number of elements in the set.

func (*Slice[T]) Remove

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

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

func (*Slice[T]) Slice

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.

Source Files

handle.go set.go slice.go

Version
v1.84.0 (latest)
Published
May 21, 2025
Platform
linux/amd64
Imports
4 packages
Last checked
1 day ago

Tools for package owners.