set

package
v1.9.4 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2022 License: BSD-3-Clause Imports: 5 Imported by: 196

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Set

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

Set is a set of elements.

func NewSet

func NewSet[T comparable](size int) Set[T]

Return a new set with initial capacity [size]. More or less than [size] elements can be added to this set. Using NewSet() rather than Set[T]{} is just an optimization that can be used if you know how many elements will be put in this set.

func (*Set[T]) Add

func (s *Set[T]) Add(elts ...T)

Add all the elements to this set. If the element is already in the set, nothing happens.

func (Set[T]) CappedList

func (s Set[T]) CappedList(size int) []T

CappedList returns a list of length at most [size]. Size should be >= 0. If size < 0, returns nil.

func (*Set[_]) Clear

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

Clear empties this set

func (*Set[T]) Contains

func (s *Set[T]) Contains(elt T) bool

Contains returns true iff the set contains this element.

func (*Set[T]) Difference

func (s *Set[T]) Difference(set Set[T])

Difference removes all the elements in set from [s].

func (Set[T]) Equals

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

Equals returns true if the sets contain the same elements

func (Set[_]) Len

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

Len returns the number of elements in this set.

func (Set[T]) List

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

List converts this set into a list

func (*Set[_]) MarshalJSON

func (s *Set[_]) MarshalJSON() ([]byte, error)

func (*Set[T]) Overlaps

func (s *Set[T]) Overlaps(big Set[T]) bool

Overlaps returns true if the intersection of the set is non-empty

func (*Set[T]) Peek

func (s *Set[T]) Peek() (T, bool)

Returns an element. If the set is empty, returns false

func (*Set[T]) Pop

func (s *Set[T]) Pop() (T, bool)

Removes and returns an element. If the set is empty, does nothing and returns false.

func (*Set[T]) Remove

func (s *Set[T]) Remove(elts ...T)

Remove all the given elements from this set. If an element isn't in the set, it's ignored.

func (*Set[T]) Union

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

Union adds all the elements from the provided set to this set.

Jump to

Keyboard shortcuts

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