Documentation
¶
Index ¶
- type Set
- func (s *Set[T]) Clear()
- func (s *Set[T]) Clone() *Set[T]
- func (s *Set[T]) Contains(item T) bool
- func (s *Set[T]) Difference(other *Set[T]) *Set[T]
- func (s *Set[T]) Equals(other *Set[T]) bool
- func (s *Set[T]) Intersection(other *Set[T]) *Set[T]
- func (s *Set[T]) IsEmpty() bool
- func (s *Set[T]) IsSubsetOf(other *Set[T]) bool
- func (s *Set[T]) Iter() iter.Seq[T]
- func (s *Set[T]) Peek() (T, bool)
- func (s *Set[T]) Pop() (T, bool)
- func (s *Set[T]) Push(items ...T)
- func (s *Set[T]) Remove(item T) bool
- func (s *Set[T]) Size() int
- func (s *Set[T]) SymmetricDifference(other *Set[T]) *Set[T]
- func (s *Set[T]) ToSlice() []T
- func (s *Set[T]) Union(other *Set[T]) *Set[T]
- type SyncSet
- func (s *SyncSet[T]) Clear()
- func (s *SyncSet[T]) Clone() *SyncSet[T]
- func (s *SyncSet[T]) Contains(item T) bool
- func (s *SyncSet[T]) Difference(other *SyncSet[T]) *SyncSet[T]
- func (s *SyncSet[T]) Equals(other *SyncSet[T]) bool
- func (s *SyncSet[T]) Intersection(other *SyncSet[T]) *SyncSet[T]
- func (s *SyncSet[T]) IsEmpty() bool
- func (s *SyncSet[T]) IsSubsetOf(other *SyncSet[T]) bool
- func (s *SyncSet[T]) Iter() func(func(T) bool)
- func (s *SyncSet[T]) Peek() (T, bool)
- func (s *SyncSet[T]) Pop() (T, bool)
- func (s *SyncSet[T]) Push(items ...T)
- func (s *SyncSet[T]) Remove(item T) bool
- func (s *SyncSet[T]) Size() int
- func (s *SyncSet[T]) SymmetricDifference(other *SyncSet[T]) *SyncSet[T]
- func (s *SyncSet[T]) ToSlice() []T
- func (s *SyncSet[T]) Union(other *SyncSet[T]) *SyncSet[T]
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]) Difference ¶
Difference returns a new Set containing elements in s that are not in other
func (*Set[T]) Intersection ¶
Intersection returns a new Set containing elements present in both Sets
func (*Set[T]) IsSubsetOf ¶
IsSubsetOf returns true if all elements in s are also in other
func (*Set[T]) Peek ¶
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 ¶
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]) SymmetricDifference ¶
SymmetricDifference returns a new Set with elements in either Set but not in both
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]) Difference ¶
Difference returns a new SyncSet containing elements in s that are not in other
func (*SyncSet[T]) Intersection ¶
Intersection returns a new SyncSet containing elements present in both SyncSets
func (*SyncSet[T]) IsSubsetOf ¶
IsSubsetOf returns true if all elements in s are also in other
func (*SyncSet[T]) Iter ¶
Iter returns an iterator over the Set's elements
Note: Iter returns a snapshot iterator (not live-updated)
func (*SyncSet[T]) Peek ¶
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 ¶
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 ¶
Remove deletes an item from the SyncSet and returns whether it was present
func (*SyncSet[T]) SymmetricDifference ¶
SymmetricDifference returns a new SyncSet with elements in either SyncSet but not in both