set

package
v0.0.0-...-5bd4ecb Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package set implements a set of any comparable type.

A set is an unordered list of elements with no duplicates.

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 represents an unordered list of elements.

func New

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

New create and returns an initialized Set, optionally with the given elements.

func NewFromSlice

func NewFromSlice[T comparable](sl []T) Set[T]

NewFromSlice create and returns a new set from an existing slice.

func NewWithSize

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

NewWithSize create and returns an initialized and empty set with a given size.

func (Set[T]) Add

func (s Set[T]) Add(es ...T)

Add adds all the given elements to the set. If any element is already in the set, Add is a no-op for that element.

func (*Set[T]) Clear

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

Clear removes all the elements from the set.

func (Set[T]) Contains

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

Contains check if the given element exists in the set.

func (Set[T]) Difference

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

Difference returns a new set with elements in s that are not in other.

func (Set[T]) ForEach

func (s Set[T]) ForEach(f func(e T))

ForEach is used to iterate over every element of the set by calling a user-defined function with every element.

func (Set[T]) Intersection

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

Intersection returns a new set with elements common to s and other.

func (Set[T]) IsDisjoint

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

IsDisjoint returns true if s has no elements in common with other. Sets are disjoint if and only if their intersection is an empty set.

func (Set[T]) IsEqual

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

IsEqual returns true if s is equal to other. Sets are equal if their lengths are equal and every element of s is in other.

func (Set[T]) IsProperSubset

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

IsProperSubset returns true if s is a proper subset of other, that is, s is a subset of other and length of s is strictly less than other.

func (Set[T]) IsProperSuperset

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

IsProperSuperset returns true if s is a proper superset of other, that is, s is a superset of other and length of s is strictly greater than other.

func (Set[T]) IsSubset

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

IsSubset returns true if every element in s is in other, false otherwise.

func (Set[T]) IsSuperset

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

IsSuperset returns true if every element in other is in s, false otherwise.

func (Set[T]) Iter

func (s Set[T]) Iter() <-chan T

Iter is used to iterate over every element of the set. It returns a receive-only buffered channel whose size is half of set length.

func (Set[T]) Len

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

Len returns the number of elements in the set.

func (Set[T]) Pop

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

Pop removes and returns an arbitrary item from the set. If the set is empty, then it will return the zero value for the constrained type.

func (Set[T]) Remove

func (s Set[T]) Remove(es ...T)

Remove deletes all the given elements from the set. If there is no such element, Remove is a no-op.

func (Set[T]) String

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

func (Set[T]) SymmetricDifference

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

SymmetricDifference returns a new set with elements in either s or other but not in both.

func (Set[T]) ToSlice

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

ToSlice returns the members of the receiver set as a slice.

func (Set[T]) Union

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

Union returns a new set with elements from s and other.

Jump to

Keyboard shortcuts

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