set

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 30, 2025 License: MIT Imports: 3 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] struct {
	// contains filtered or unexported fields
}

Set implements a generic set data structure

func FromSlice

func FromSlice[T comparable](data []T) *Set[T]

FromSlice creates a new Set from a slice of items

func FromSyncSet

func FromSyncSet[T comparable](set *SyncSet[T]) *Set[T]

FromSyncSet creates a new Set from a SyncSet.

func New

func New[T comparable](size ...int) *Set[T]

New creates a new empty Set with an optional initial capacity

func (*Set[T]) Clear

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

Clear removes all elements from the Set

func (*Set[T]) Clone

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

Clone creates a new Set with the same elements

func (*Set[T]) Contains

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

Contains checks if the Set contains the specified item

func (*Set[T]) Difference

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

Difference returns a new Set containing elements in s that are not in other

func (*Set[T]) Equals

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

Equals returns true if both Sets contain exactly the same elements

func (*Set[T]) Intersection

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

Intersection returns a new Set containing elements present in both Sets

func (*Set[T]) IsEmpty

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

IsEmpty returns true if the Set contains no elements

func (*Set[T]) IsSubsetOf

func (s *Set[T]) IsSubsetOf(other *Set[T]) bool

IsSubsetOf returns true if all elements in s are also in other

func (*Set[T]) Iter

func (s *Set[T]) Iter() iter.Seq[T]

Iter returns an iterator over the Set's elements

func (*Set[T]) Peek

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

Peek returns an arbitrary element from the Set without removing it

Note: The selection of which element to peek is non-deterministic due to Go's map iteration order

func (*Set[T]) Pop

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

Pop removes and returns an arbitrary element from the Set

Note: The selection of which element to pop is non-deterministic due to Go's map iteration order

func (*Set[T]) Push

func (s *Set[T]) Push(items ...T)

Push adds one or more items to the Set

func (*Set[T]) Remove

func (s *Set[T]) Remove(item T) bool

Remove deletes an item from the Set and returns whether it was present

func (*Set[T]) Size

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

Size returns the number of elements in the Set

func (*Set[T]) SymmetricDifference

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

SymmetricDifference returns a new Set with elements in either Set but not in both

func (*Set[T]) ToSlice

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

ToSlice returns all elements of the Set as a slice

func (*Set[T]) Union

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

Union returns a new Set containing all elements from both Sets

type SyncSet

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

SyncSet implements a generic set data structure with thread-safety

func FromSet

func FromSet[T comparable](set *Set[T]) *SyncSet[T]

FromSet creates a new SyncSet from a Set

func NewSync

func NewSync[T comparable](size ...int) *SyncSet[T]

NewSync creates a new empty SyncSet with an optional initial capacity

func SyncFromSlice

func SyncFromSlice[T comparable](data []T) *SyncSet[T]

SyncFromSlice creates a new SyncSet from a slice of items

func (*SyncSet[T]) Clear

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

Clear removes all elements from the SyncSet

func (*SyncSet[T]) Clone

func (s *SyncSet[T]) Clone() *SyncSet[T]

Clone creates a new Set with the same elements

func (*SyncSet[T]) Contains

func (s *SyncSet[T]) Contains(item T) bool

Contains checks if the SyncSet contains the specific item

func (*SyncSet[T]) Difference

func (s *SyncSet[T]) Difference(other *SyncSet[T]) *SyncSet[T]

Difference returns a new SyncSet containing elements in s that are not in other

func (*SyncSet[T]) Equals

func (s *SyncSet[T]) Equals(other *SyncSet[T]) bool

Equals returns true if both sets contain exactly the same elements

func (*SyncSet[T]) Intersection

func (s *SyncSet[T]) Intersection(other *SyncSet[T]) *SyncSet[T]

Intersection returns a new SyncSet containing elements present in both SyncSets

func (*SyncSet[T]) IsEmpty

func (s *SyncSet[T]) IsEmpty() bool

IsEmpty returns true if the SyncSet contains no elements

func (*SyncSet[T]) IsSubsetOf

func (s *SyncSet[T]) IsSubsetOf(other *SyncSet[T]) bool

IsSubsetOf returns true if all elements in s are also in other

func (*SyncSet[T]) Iter

func (s *SyncSet[T]) Iter() func(func(T) bool)

Iter returns an iterator over the Set's elements

Note: Iter returns a snapshot iterator (not live-updated)

func (*SyncSet[T]) Peek

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

Peek returns an arbitrary element from the SyncSet without removing it

Note: The selection of which element to peek is non-deterministic due to Go's map iteration order

func (*SyncSet[T]) Pop

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

Pop removes and returns an arbitrary element from the SyncSet

Note: The selection of which element to pop is non-deterministic due to Go's map iteration order

func (*SyncSet[T]) Push

func (s *SyncSet[T]) Push(items ...T)

Push adds one or more items to the SyncSet

func (*SyncSet[T]) Remove

func (s *SyncSet[T]) Remove(item T) bool

Remove deletes an item from the SyncSet and returns whether it was present

func (*SyncSet[T]) Size

func (s *SyncSet[T]) Size() int

Size returns the number of elements in the SyncSet

func (*SyncSet[T]) SymmetricDifference

func (s *SyncSet[T]) SymmetricDifference(other *SyncSet[T]) *SyncSet[T]

SymmetricDifference returns a new SyncSet with elements in either SyncSet but not in both

func (*SyncSet[T]) ToSlice

func (s *SyncSet[T]) ToSlice() []T

ToSlice returns all elements of the Set as a slice

func (*SyncSet[T]) Union

func (s *SyncSet[T]) Union(other *SyncSet[T]) *SyncSet[T]

Union returns a new SyncSet containing all elements from both SyncSets

Jump to

Keyboard shortcuts

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