set

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2023 License: MIT Imports: 0 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Iterator

type Iterator[T comparable] struct {
	// contains filtered or unexported fields
}

Iterator defines an iterator over a Set, its channel can be used to range over the Set's elements.

func (*Iterator[T]) Close

func (i *Iterator[T]) Close()

Close closes the Iterator, no further elements will be received on C, C will be closed.

func (*Iterator[T]) Elements

func (i *Iterator[T]) Elements() <-chan T

Elements returns a channel to be used to iterate over the elements of the set.

type Set

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

Set is used to handle use cases for the set data structure.

func New

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

New is used to create a new set.

func (Set[T]) Add

func (s Set[T]) Add(val T) bool

Add adds an element to the set. It returns whether the item was added.

func (Set[T]) Append

func (s Set[T]) Append(v ...T) int

Append multiple elements to the set. It returns the number of elements added.

func (Set[T]) Clear

func (s Set[T]) Clear()

Clear removes all elements from the set, leaving the empty set.

func (Set[T]) Clone

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

Clone returns a clone of the set using the same implementation, duplicating all keys.

func (Set[T]) Collection

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

Collection returns the elements of the set as a collection.

func (Set[T]) Contains

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

Contains returns whether the given items are all in the set.

func (Set[T]) ContainsAny

func (s Set[T]) ContainsAny(v ...T) bool

ContainsAny returns whether at least one of the given items are in the set.

func (Set[T]) Difference

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

Difference returns the difference between this set and other. The returned set will contain all elements of this set that are not also elements of the second set.

Note that the argument to Difference must be of the same type as the receiver of the method. Otherwise, Difference will panic.

func (Set[T]) Equal

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

Equal determines if two sets are equal to each other. If they have the same cardinality and contain the same elements, they are considered equal. The order in which the elements were added is irrelevant.

Note that the argument to Equal must be of the same type as the receiver of the method. Otherwise, Equal will panic.

func (Set[T]) Intersection

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

Intersection returns a new set containing only the elements that exist only in both sets.

Note that the argument to Intersect must be of the same type as the receiver of the method. Otherwise, Intersect will panic.

func (Set[T]) Iterator

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

Iterator returns an Iterator object that can be used to range over the set.

func (Set[T]) Length

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

Length is used to find the number of elements in the set.

func (Set[T]) Remove

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

Remove removes a single element from the set.

func (Set[T]) RemoveAll

func (s Set[T]) RemoveAll(i ...T)

RemoveAll removes multiple elements from the set.

func (Set[T]) Union

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

Union returns a new set with all elements in both sets.

Note that the argument to Union must be of the same type as the receiver of the method. Otherwise, Union will panic.

Jump to

Keyboard shortcuts

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