sets

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2023 License: MIT Imports: 1 Imported by: 0

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{}

func New

func New[T comparable]() Set[T]

New creates a new empty set.

func Of added in v0.17.0

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

Of creates a new set with the given elements.

func (Set[T]) Add

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

Add adds the given element to the set.

func (Set[T]) AddAll

func (s Set[T]) AddAll(v ...T)

AddAll adds the given elements to the set.

func (Set[T]) Clear

func (s Set[T]) Clear()

Clear removes all elements from the set.

func (Set[T]) Contains

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

Contains returns true if the set contains the given element.

func (Set[T]) Copy

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

Copy returns a copy of the set.

func (Set[T]) Difference

func (s Set[T]) Difference(other Set[T]) Set[T]

Difference returns a new set with the elements that are in this set but not in the other.

func (Set[T]) Equal

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

Equal returns true if the set is equal to the other set. Two sets are equal if they have the same elements.

func (Set[T]) GoString

func (s Set[T]) GoString() string

GoString returns a Go string representation of the set.

func (Set[T]) Intersection

func (s Set[T]) Intersection(other Set[T]) Set[T]

Intersection returns a new set with the elements that are in both this set and the other set.

func (Set[T]) IsEmpty

func (s Set[T]) IsEmpty() bool

IsEmpty returns true if the set is empty. It has no elements.

func (Set[T]) IsSubset

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

IsSubset returns true if this set is a subset of the other set. A set is a subset if all elements of this set are also in the other set.

func (Set[T]) IsSuperset

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

IsSuperset returns true if this set is a superset of the other set. A set is a superset if all elements of the other set are also in this set.

func (Set[T]) Remove

func (s Set[T]) Remove(v T)

Remove removes the given element from the set.

func (Set[T]) Size

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

Size returns the number of elements in the set.

func (Set[T]) String

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

String returns a string representation of the set.

func (Set[T]) SymmetricDifference

func (s Set[T]) SymmetricDifference(other Set[T]) Set[T]

SymmetricDifference returns a new set with the elements that are in this set or the other set but not in both.

func (Set[T]) Union

func (s Set[T]) Union(other Set[T]) Set[T]

Union returns a new set with all the elements of the set and the given set. Common elements are only added once.

func (Set[T]) Values

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

Values returns the elements of the set as a slice.

Jump to

Keyboard shortcuts

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