set

package
v1.8.0-rc.12 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2022 License: BSD-3-Clause Imports: 2 Imported by: 180

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Set

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

Set is a set of IDs

func NewSet

func NewSet[T Settable](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 (ids *Set[T]) Add(elts ...T)

Add all the ids to this set, if the id is already in the set, nothing happens

func (Set[T]) CappedList

func (ids 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[T]) Clear

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

Clear empties this set

func (*Set[T]) Contains

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

Contains returns true if the set contains this id, false otherwise

func (*Set[T]) Difference

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

Difference removes all the ids from the provided set to this set.

func (Set[T]) Equals

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

Equals returns true if the sets contain the same elements

func (Set[T]) Len

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

Len returns the number of ids in this set

func (Set[T]) List

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

List converts this set into a list

func (*Set[T]) MarshalJSON

func (ids *Set[T]) MarshalJSON() ([]byte, error)

func (*Set[T]) Overlaps

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

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

func (*Set[T]) Peek

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

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

func (*Set[T]) Pop

func (ids *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 (ids *Set[T]) Remove(elts ...T)

Remove all the id from this set, if the id isn't in the set, nothing happens

func (Set[T]) String

func (ids Set[T]) String() string

String returns the string representation of a set

func (*Set[T]) Union

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

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

type Settable

type Settable interface {
	comparable
	String() string
}

Settable describes an element that can be in a set.

Jump to

Keyboard shortcuts

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