set

package
v1.50.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2023 License: BSD-3-Clause Imports: 2 Imported by: 27

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 a 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 added in v1.42.0

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

Set is a set of T.

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

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

Add adds e to the set.

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]) Len added in v1.42.0

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

Len reports the number of items in s.

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 the a view of the underlying slice. The elements are in order of insertion. The returned value is only valid until ss is modified again.

Jump to

Keyboard shortcuts

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