Documentation
¶
Index ¶
- func AddedOrRemovedSlice[T comparable](before, after Set[T]) []T
- type ConcurrencySafeSet
- func (s *ConcurrencySafeSet[T]) Add(ss ...T) Set[T]
- func (s *ConcurrencySafeSet[T]) Copy() Set[T]
- func (s *ConcurrencySafeSet[T]) Equals(comp Set[T]) bool
- func (s *ConcurrencySafeSet[T]) Has(e T) bool
- func (s *ConcurrencySafeSet[T]) Iter() iter.Seq[T]
- func (s *ConcurrencySafeSet[T]) Join(ss Set[T]) Set[T]
- func (s *ConcurrencySafeSet[T]) NewOfSameType(ss ...T) Set[T]
- func (s *ConcurrencySafeSet[T]) Remove(ss ...T) Set[T]
- func (s *ConcurrencySafeSet[T]) Size() int
- func (s *ConcurrencySafeSet[T]) Slice() []T
- type Set
- func AddedOrRemoved[T comparable](before, after Set[T]) Set[T]
- func Complement[T comparable](a, b Set[T]) Set[T]
- func Difference[T comparable](a, b Set[T]) Set[T]
- func Intersection[T comparable](a, b Set[T]) Set[T]
- func SymmetricDifference[T comparable](a, b Set[T]) Set[T]
- func Union[T comparable](a, b Set[T]) Set[T]
- type SimpleSet
- func (s SimpleSet[T]) Add(ss ...T) Set[T]
- func (s SimpleSet[T]) Copy() Set[T]
- func (s SimpleSet[T]) Equals(comp Set[T]) bool
- func (s SimpleSet[T]) Has(e T) bool
- func (s SimpleSet[T]) Iter() iter.Seq[T]
- func (s SimpleSet[T]) Join(ss Set[T]) Set[T]
- func (s SimpleSet[T]) NewOfSameType(ss ...T) Set[T]
- func (s SimpleSet[T]) Remove(ss ...T) Set[T]
- func (s SimpleSet[T]) Size() int
- func (s SimpleSet[T]) Slice() []T
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddedOrRemovedSlice ¶ added in v1.4.97
func AddedOrRemovedSlice[T comparable](before, after Set[T]) []T
AddedOrRemovedSlice returns the items that were added or removed (symmetric difference) between the before and after sets, as a slice. It avoids extra allocations.
Types ¶
type ConcurrencySafeSet ¶ added in v1.3.6
type ConcurrencySafeSet[T comparable] struct { sync.RWMutex // contains filtered or unexported fields }
ConcurrencySafeSet represents a set of unique elements.
func NewConcurrencySafe ¶ added in v1.3.6
func NewConcurrencySafe[T comparable](ss ...T) *ConcurrencySafeSet[T]
NewConcurrencySafe returns a new concurrency-safe set.
func (*ConcurrencySafeSet[T]) Add ¶ added in v1.3.6
func (s *ConcurrencySafeSet[T]) Add(ss ...T) Set[T]
Add adds a list of elements to a set.
func (*ConcurrencySafeSet[T]) Copy ¶ added in v1.3.6
func (s *ConcurrencySafeSet[T]) Copy() Set[T]
Copy returns a copy of a set.
func (*ConcurrencySafeSet[T]) Equals ¶ added in v1.4.22
func (s *ConcurrencySafeSet[T]) Equals(comp Set[T]) bool
Equals returns true if a given set is equal (has the same elements).
func (*ConcurrencySafeSet[T]) Has ¶ added in v1.3.6
func (s *ConcurrencySafeSet[T]) Has(e T) bool
Has returns true if an element is in a set.
func (*ConcurrencySafeSet[T]) Iter ¶ added in v1.4.87
func (s *ConcurrencySafeSet[T]) Iter() iter.Seq[T]
Iter returns an iterator for a copy of the set. Note that elements are iterated through in no particular order.
func (*ConcurrencySafeSet[T]) Join ¶ added in v1.3.6
func (s *ConcurrencySafeSet[T]) Join(ss Set[T]) Set[T]
Join joins two sets.
func (*ConcurrencySafeSet[T]) NewOfSameType ¶ added in v1.4.97
func (s *ConcurrencySafeSet[T]) NewOfSameType(ss ...T) Set[T]
NewOfSameType returns a new empty set of the same type as the parent set.
func (*ConcurrencySafeSet[T]) Remove ¶ added in v1.3.6
func (s *ConcurrencySafeSet[T]) Remove(ss ...T) Set[T]
Remove removes a list of elements from a set.
func (*ConcurrencySafeSet[T]) Size ¶ added in v1.3.7
func (s *ConcurrencySafeSet[T]) Size() int
Size returns the number of elements in the set.
func (*ConcurrencySafeSet[T]) Slice ¶ added in v1.3.6
func (s *ConcurrencySafeSet[T]) Slice() []T
Slice returns the set as a slice.
type Set ¶
type Set[T comparable] interface { Has(T) bool Add(...T) Set[T] Remove(...T) Set[T] Join(Set[T]) Set[T] Iter() iter.Seq[T] Copy() Set[T] Slice() []T Size() int Equals(Set[T]) bool NewOfSameType(...T) Set[T] }
Set represents a set of unique elements.
func AddedOrRemoved ¶ added in v1.4.97
func AddedOrRemoved[T comparable](before, after Set[T]) Set[T]
AddedOrRemoved returns the set of items that were added or removed between the before and after sets. This is equivalent to the symmetric difference: (after ∖ before) ∪ (before ∖ after).
func Complement ¶ added in v1.4.97
func Complement[T comparable](a, b Set[T]) Set[T]
Complement returns the relative complement of b in a i.e. all the elements that are in a but not in b.
func Difference ¶ added in v1.4.97
func Difference[T comparable](a, b Set[T]) Set[T]
Difference returns elements in a that are not in b.
func Intersection ¶ added in v1.4.97
func Intersection[T comparable](a, b Set[T]) Set[T]
Intersection returns elements in either a or b.
func SymmetricDifference ¶ added in v1.4.97
func SymmetricDifference[T comparable](a, b Set[T]) Set[T]
SymmetricDifference returns elements in either a or b, but not in both.
func Union ¶ added in v1.4.97
func Union[T comparable](a, b Set[T]) Set[T]
Union returns elements in either a or b.
type SimpleSet ¶ added in v1.3.6
type SimpleSet[T comparable] map[T]struct{}
SimpleSet represents a set of unique elements.
func (SimpleSet[T]) Equals ¶ added in v1.4.22
Equals returns true if a given set is equal (has the same elements).
func (SimpleSet[T]) Iter ¶ added in v1.4.87
Iter returns an iterator for the set. Note that elements are iterated through in no particular order.
func (SimpleSet[T]) NewOfSameType ¶ added in v1.4.97
NewOfSameType returns a new empty set of the same type as the parent set.