Documentation
¶
Overview ¶
Package go_set provides a generic set implementation based on maps. It supports standard set operations like Add, Remove, Contains, and functional-style operations like Map, Filter, and FlatMap.
This package utilizes Go 1.23+ features (iter.Seq) for iteration.
Index ¶
- Variables
- func Max[T Ordered](s ISet[T]) T
- func Min[T Ordered](s ISet[T]) T
- func Sort[T Ordered](s ISet[T], sortFunc func(a, b T) bool) []T
- func Sum[T Ordered](s ISet[T]) T
- type Hashable
- type IOrderedSet
- type ISet
- type Ordered
- type OrderedSet
- func (s *OrderedSet[T]) MarshalJSON() ([]byte, error)
- func (s *OrderedSet[T]) Max() T
- func (s *OrderedSet[T]) Min() T
- func (s *OrderedSet[T]) Sort(sortFunc func(a, b T) bool) []T
- func (s *OrderedSet[T]) Sorted() []T
- func (s *OrderedSet[T]) Sum() T
- func (s *OrderedSet[T]) UnmarshalJSON(data []byte) error
- type Set
- func (s *Set[T]) Add(elements ...T)
- func (s *Set[T]) All(predicate func(T) bool) bool
- func (s *Set[T]) Any(predicate func(T) bool) bool
- func (s *Set[T]) Clear()
- func (s *Set[T]) Contains(element T) bool
- func (s *Set[T]) Copy() ISet[T]
- func (s *Set[T]) Count(predicate func(T) bool) int
- func (s *Set[T]) Difference(other ISet[T]) ISet[T]
- func (s *Set[T]) Equals(other ISet[T]) bool
- func (s *Set[T]) EqualsWith(other ISet[T], eqFunc func(T, T) bool) bool
- func (s *Set[T]) Filter(predicate func(T) bool) ISet[T]
- func (s *Set[T]) FilterIter(predicate func(T) bool) iter.Seq[T]
- func (s *Set[T]) FlatMap(mapper func(T) ISet[T]) ISet[T]
- func (s *Set[T]) FlatMapIter(mapper func(T) iter.Seq[T]) iter.Seq[T]
- func (s *Set[T]) ForEach(action func(T))
- func (s *Set[T]) Intersection(other ISet[T]) ISet[T]
- func (s *Set[T]) IsDisjoint(other ISet[T]) bool
- func (s *Set[T]) IsEmpty() bool
- func (s *Set[T]) IsSubset(other ISet[T]) bool
- func (s *Set[T]) IsSuperset(other ISet[T]) bool
- func (s *Set[T]) Iter() iter.Seq[T]
- func (s *Set[T]) Map(mapper func(T) T) ISet[T]
- func (s *Set[T]) MapIter(mapper func(T) T) iter.Seq[T]
- func (s *Set[T]) MarshalJSON() ([]byte, error)
- func (s *Set[T]) Partition(predicate func(T) bool) (ISet[T], ISet[T])
- func (s *Set[T]) Reduce(initial T, reducer func(T, T) T) T
- func (s *Set[T]) Remove(elements ...T)
- func (s *Set[T]) Retain(predicate func(T) bool)
- func (s *Set[T]) Size() int
- func (s *Set[T]) String() string
- func (s *Set[T]) SymmetricDifference(other ISet[T]) ISet[T]
- func (s *Set[T]) ToSlice() []T
- func (s *Set[T]) Union(other ISet[T]) ISet[T]
- func (s *Set[T]) UnmarshalJSON(data []byte) error
- type SyncOrderedSet
- func (s *SyncOrderedSet[T]) MarshalJSON() ([]byte, error)
- func (s *SyncOrderedSet[T]) Max() T
- func (s *SyncOrderedSet[T]) Min() T
- func (s *SyncOrderedSet[T]) Sort(sortFunc func(a, b T) bool) []T
- func (s *SyncOrderedSet[T]) Sorted() []T
- func (s *SyncOrderedSet[T]) Sum() T
- func (s *SyncOrderedSet[T]) UnmarshalJSON(data []byte) error
- type SyncSet
- func (s *SyncSet[T]) Add(elements ...T)
- func (s *SyncSet[T]) All(predicate func(T) bool) bool
- func (s *SyncSet[T]) Any(predicate func(T) bool) bool
- func (s *SyncSet[T]) Clear()
- func (s *SyncSet[T]) Contains(element T) bool
- func (s *SyncSet[T]) Copy() ISet[T]
- func (s *SyncSet[T]) Count(predicate func(T) bool) int
- func (s *SyncSet[T]) Difference(other ISet[T]) ISet[T]
- func (s *SyncSet[T]) Equals(other ISet[T]) bool
- func (s *SyncSet[T]) EqualsWith(other ISet[T], eqFunc func(T, T) bool) bool
- func (s *SyncSet[T]) Filter(predicate func(T) bool) ISet[T]
- func (s *SyncSet[T]) FilterIter(predicate func(T) bool) iter.Seq[T]
- func (s *SyncSet[T]) FlatMap(mapper func(T) ISet[T]) ISet[T]
- func (s *SyncSet[T]) FlatMapIter(mapper func(T) iter.Seq[T]) iter.Seq[T]
- func (s *SyncSet[T]) ForEach(action func(T))
- func (s *SyncSet[T]) Intersection(other ISet[T]) ISet[T]
- func (s *SyncSet[T]) IsDisjoint(other ISet[T]) bool
- func (s *SyncSet[T]) IsEmpty() bool
- func (s *SyncSet[T]) IsSubset(other ISet[T]) bool
- func (s *SyncSet[T]) IsSuperset(other ISet[T]) bool
- func (s *SyncSet[T]) Iter() iter.Seq[T]
- func (s *SyncSet[T]) Map(mapper func(T) T) ISet[T]
- func (s *SyncSet[T]) MapIter(mapper func(T) T) iter.Seq[T]
- func (s *SyncSet[T]) MarshalJSON() ([]byte, error)
- func (s *SyncSet[T]) Partition(predicate func(T) bool) (ISet[T], ISet[T])
- func (s *SyncSet[T]) Reduce(initial T, reducer func(T, T) T) T
- func (s *SyncSet[T]) Remove(elements ...T)
- func (s *SyncSet[T]) Retain(predicate func(T) bool)
- func (s *SyncSet[T]) Size() int
- func (s *SyncSet[T]) String() string
- func (s *SyncSet[T]) SymmetricDifference(other ISet[T]) ISet[T]
- func (s *SyncSet[T]) ToSlice() []T
- func (s *SyncSet[T]) Union(other ISet[T]) ISet[T]
- func (s *SyncSet[T]) UnmarshalJSON(data []byte) error
Constants ¶
This section is empty.
Variables ¶
var ErrNilSet = errors.New("go_set: cannot marshal/unmarshal nil set")
Functions ¶
func Max ¶
Max returns the maximum element in the set according to the natural ordering of the elements.
func Min ¶
Min returns the minimum element in the set according to the natural ordering of the elements.
func Sort ¶
Sort returns a slice of the set's elements sorted according to the provided sort function. The sort function takes two elements of type T and returns true if the first element should be sorted before the second. Note: The order of elements in the set is non-deterministic, so the resulting slice will be sorted based on the provided sort function.
Types ¶
type IOrderedSet ¶
type ISet ¶
type ISet[T comparable] interface { // Add inserts the provided elements into the set. // Duplicate elements are ignored. Add(elements ...T) // Remove deletes the provided elements from the set. // If an element does not exist, it is ignored. Remove(elements ...T) // Contains checks if the specified element exists in the set. // Returns true if the element is present, false otherwise. Contains(element T) bool // Size returns the number of elements currently in the set. Size() int // Clear removes all elements from the set, making it empty. Clear() // IsEmpty checks if the set contains no elements. // Returns true if the size is 0, false otherwise. IsEmpty() bool // ToSlice converts the set elements into a slice. // The order of elements in the slice is non-deterministic. ToSlice() []T // Iter returns an iterator (iter.Seq) over the elements of the set. // This allows using the set in a range loop (Go 1.23+). // // Note: Modifications to the set during iteration may cause undefined behavior. Iter() iter.Seq[T] // FilterIter returns an iterator that yields only elements satisfying the predicate. // // Note: Modifications to the set during iteration may cause undefined behavior. FilterIter(predicate func(T) bool) iter.Seq[T] // MapIter returns an iterator that yields transformed elements using the mapper function. // // Note: Modifications to the set during iteration may cause undefined behavior. MapIter(mapper func(T) T) iter.Seq[T] // FlatMapIter returns an iterator that flattens sequences produced by the mapper function. // // Note: Modifications to the set during iteration may cause undefined behavior. FlatMapIter(mapper func(T) iter.Seq[T]) iter.Seq[T] // ForEach executes the given action function for each element in the set. // // Note: Modifying the set (especially adding elements) during execution // may cause undefined behavior. Use RemoveIf for safe removal. ForEach(action func(T)) // Map creates a new set by applying the mapper function to each element. // Duplicates produced by the mapper will be collapsed in the resulting set. // The original set is not modified. Map(mapper func(T) T) ISet[T] // Any returns true if at least one element in the set satisfies the predicate. // Returns false if the set is empty or no elements match. Any(predicate func(T) bool) bool // All returns true if all elements in the set satisfy the predicate. // Returns true if the set is empty. All(predicate func(T) bool) bool // Filter creates a new set containing only the elements that satisfy the predicate. // The original set is not modified. Filter(predicate func(T) bool) ISet[T] // Reduce applies the reducer function to each element in the set, starting with the initial value. // The reducer function takes the accumulated value and the current element, and returns a new accumulated value. // The final accumulated value is returned after processing all elements in the set. // The original set is not modified. Reduce(initial T, reducer func(T, T) T) T // FlatMap creates a new set by applying the mapper function to each element // and merging the resulting sets. // The original set is not modified. FlatMap(mapper func(T) ISet[T]) ISet[T] // Copy creates a shallow copy of the set. // The new set contains the same elements as the original. Copy() ISet[T] // Union returns a new set containing all elements from both sets. // The original sets are not modified. Union(other ISet[T]) ISet[T] // Intersection returns a new set containing only elements that exist in both sets. // The original sets are not modified. Intersection(other ISet[T]) ISet[T] // Difference returns a new set containing elements that exist in this set // but not in the other set. // The original sets are not modified. Difference(other ISet[T]) ISet[T] // SymmetricDifference returns a new set containing elements that exist in either set, // but not in both (XOR operation). // The original sets are not modified. SymmetricDifference(other ISet[T]) ISet[T] // IsSubset returns true if all elements of this set are contained in the other set. IsSubset(other ISet[T]) bool // IsSuperset returns true if this set contains all elements of the other set. IsSuperset(other ISet[T]) bool // IsDisjoint returns true if this set and the other set have no elements in common. IsDisjoint(other ISet[T]) bool // Equals returns true if both sets contain the same elements. Equals(other ISet[T]) bool // String implements the fmt.Stringer interface. // Returns a string representation of the set. String() string // Count returns the number of elements in the set that satisfy the given predicate. Count(predicate func(T) bool) int // Partition splits the set into two sets based on the given predicate. // The first set contains elements that satisfy the predicate, while the second set contains the rest. // The original set is not modified. Partition(predicate func(T) bool) (ISet[T], ISet[T]) // Retain removes all elements from the set that do NOT satisfy the predicate. // Change the set to contain only elements that satisfy the predicate. Retain(predicate func(T) bool) // EqualsWith returns true if both sets contain the same elements according to the provided equality function. // The equality function takes two elements of type T and returns true if they are considered equal. // This allows for custom equality logic (e.g., comparing struct fields instead of the whole struct). EqualsWith(other ISet[T], eqFunc func(T, T) bool) bool }
ISet is the interface that defines the contract for a set data structure. It provides methods for basic set operations, functional-style transformations, and set theory operations.
func MapTo ¶
func MapTo[T comparable, U comparable](s ISet[T], mapper func(T) U) ISet[U]
MapTo creates a new set of type U by applying the mapper function to each element of the input set. This allows transforming the set into a set of a different type (e.g., Set[int] to Set[string]). Duplicates produced by the mapper will be collapsed in the resulting set.
Note: This is a standalone function because Go methods cannot have additional type parameters.
type OrderedSet ¶
OrderedSet is a set that provides additional methods for ordered types (int, float, string, etc.).
func NewOrderedSet ¶
func NewOrderedSet[T Ordered](elements ...T) *OrderedSet[T]
Create a new OrderedSet with the provided optional elements. In based on Set by default, but can be based on SyncSet if needed (see NewOrderedSyncSet).
func NewOrderedSetWithCapacity ¶
func NewOrderedSetWithCapacity[T Ordered](capacity int, elements ...T) *OrderedSet[T]
Create a new OrderedSet with the provided optional elements and initial capacity.
func (*OrderedSet[T]) MarshalJSON ¶
func (s *OrderedSet[T]) MarshalJSON() ([]byte, error)
MarshalJSON marshals OrderedSet as a JSON array in sorted order.
func (*OrderedSet[T]) Max ¶
func (s *OrderedSet[T]) Max() T
Max returns the maximum element in the set.
func (*OrderedSet[T]) Min ¶
func (s *OrderedSet[T]) Min() T
Min returns the minimum element in the set.
func (*OrderedSet[T]) Sort ¶
func (s *OrderedSet[T]) Sort(sortFunc func(a, b T) bool) []T
Sort returns a slice of the set's elements sorted according to the provided sort function.
func (*OrderedSet[T]) Sorted ¶
func (s *OrderedSet[T]) Sorted() []T
Sorted returns a sorted slice of the elements in the set. (A convenient wrapper that is not available in the base functions).
func (*OrderedSet[T]) Sum ¶
func (s *OrderedSet[T]) Sum() T
Sum returns the sum of all elements in the set.
func (*OrderedSet[T]) UnmarshalJSON ¶
func (s *OrderedSet[T]) UnmarshalJSON(data []byte) error
UnmarshalJSON unmarshals from JSON array.
type Set ¶
type Set[T comparable] struct { // contains filtered or unexported fields }
Set is a generic collection of unique elements. It is backed by a map[T]struct{} for O(1) average time complexity for lookups and insertions.
Note: This structure is NOT thread-safe.
func NewSet ¶
func NewSet[T comparable](elements ...T) *Set[T]
NewSet creates and initializes a new Set with the provided optional elements. If no elements are provided, an empty set is returned.
Example:
s := NewSet(1, 2, 3) s := NewSet[int]() // empty set
func NewSetWithCapacity ¶
func NewSetWithCapacity[T comparable](capacity int, elements ...T) *Set[T]
NewSetWithCapacity creates and initializes a new Set with the provided optional elements and initial capacity. If the number of provided elements exceeds the specified capacity, the capacity will be automatically increased to accommodate all elements.
Example:
s := NewSetWithCapacity(100, 1, 2, 3) // initial capacity 100, but only 3 elements s := NewSetWithCapacity[int](50) // empty set with initial capacity 50 s := NewSetWithCapacity(2, 1, 2, 3) // initial capacity 2, but will be increased to accommodate 3 elements
func (*Set[T]) Add ¶
func (s *Set[T]) Add(elements ...T)
Add inserts the provided elements into the set. Duplicate elements are ignored.
func (*Set[T]) All ¶
All returns true if all elements in the set satisfy the predicate. Returns false if the set is empty.
func (*Set[T]) Any ¶
Any returns true if at least one element in the set satisfies the predicate. Returns false if the set is empty or no elements match.
func (*Set[T]) Clear ¶
func (s *Set[T]) Clear()
Clear removes all elements from the set, making it empty.
func (*Set[T]) Contains ¶
Contains checks if the specified element exists in the set. Returns true if the element is present, false otherwise.
func (*Set[T]) Copy ¶
Copy creates a shallow copy of the set. The new set contains the same elements as the original.
func (*Set[T]) Count ¶
Count returns the number of elements in the set that satisfy the given predicate.
func (*Set[T]) Difference ¶
Difference returns a new set containing elements that exist in this set but not in the other set. The original sets are not modified.
func (*Set[T]) EqualsWith ¶
EqualsWith returns true if both sets contain the same elements according to the provided equality function. The equality function takes two elements of type T and returns true if they are considered equal. This allows for custom equality logic (e.g., comparing struct fields instead of the whole struct).
func (*Set[T]) Filter ¶
Filter creates a new set containing only the elements that satisfy the predicate. The original set is not modified.
func (*Set[T]) FilterIter ¶
FilterIter returns an iterator that yields only elements satisfying the predicate.
Performance Note: This method iterates directly over the underlying map without creating a snapshot. Modifying the set during iteration is not recommended.
func (*Set[T]) FlatMap ¶
FlatMap creates a new set by applying the mapper function to each element and merging the resulting sets. The mapper function should return a *Set[T] for each element. The original set is not modified.
func (*Set[T]) FlatMapIter ¶
FlatMapIter returns an iterator that flattens sequences produced by the mapper function.
Performance Note: This method iterates directly over the underlying map without creating a snapshot. Modifying the set during iteration is not recommended.
func (*Set[T]) ForEach ¶
func (s *Set[T]) ForEach(action func(T))
ForEach executes the given action function for each element in the set.
Performance Note: This method iterates directly over the underlying map without creating a snapshot. Modifying the set (especially adding elements) during execution may cause undefined behavior or panic. Use RemoveIf for safe removal.
func (*Set[T]) Intersection ¶
Intersection returns a new set containing only elements that exist in both sets. The original sets are not modified.
func (*Set[T]) IsDisjoint ¶
IsDisjoint returns true if this set and the other set have no elements in common.
func (*Set[T]) IsEmpty ¶
IsEmpty checks if the set contains no elements. Returns true if the size is 0, false otherwise.
func (*Set[T]) IsSubset ¶
IsSubset returns true if all elements of this set are contained in the other set.
func (*Set[T]) IsSuperset ¶
IsSuperset returns true if this set contains all elements of the other set.
func (*Set[T]) Iter ¶
Iter returns an iterator (iter.Seq) over the elements of the set. This allows using the set in a range loop (Go 1.23+).
Performance Note: This method iterates directly over the underlying map without creating a snapshot. Modifying the set (adding/removing elements) during iteration may cause undefined behavior or panic.
func (*Set[T]) Map ¶
Map creates a new set by applying the mapper function to each element of the current set. Duplicates produced by the mapper will be collapsed in the resulting set. The original set is not modified.
func (*Set[T]) MapIter ¶
MapIter returns an iterator that yields transformed elements using the mapper function.
Performance Note: This method iterates directly over the underlying map without creating a snapshot. Modifying the set during iteration is not recommended.
func (*Set[T]) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface. Set is marshaled as a JSON array. Order is non-deterministic.
func (*Set[T]) Partition ¶
Partition splits the set into two sets based on the given predicate. The first set contains elements that satisfy the predicate, while the second set contains the rest. The original set is not modified.
func (*Set[T]) Reduce ¶
func (s *Set[T]) Reduce(initial T, reducer func(T, T) T) T
Reduce applies the reducer function to each element in the set, starting with the initial value. The reducer function takes the accumulated value and the current element, and returns a new accumulated value. The final accumulated value is returned after processing all elements in the set.
The original set is not modified.
func (*Set[T]) Remove ¶
func (s *Set[T]) Remove(elements ...T)
Remove deletes the provided elements from the set. If an element does not exist, it is ignored.
func (*Set[T]) Retain ¶
Retain removes all elements from the set that do NOT satisfy the predicate. Change the set to contain only elements that satisfy the predicate.
func (*Set[T]) String ¶
String implements the fmt.Stringer interface. Returns a string representation of the set.
func (*Set[T]) SymmetricDifference ¶
SymmetricDifference returns a new set containing elements that exist in either set, but not in both (XOR operation). The original sets are not modified.
func (*Set[T]) ToSlice ¶
func (s *Set[T]) ToSlice() []T
ToSlice converts the set elements into a slice. The order of elements in the slice is non-deterministic.
func (*Set[T]) Union ¶
Union returns a new set containing all elements from both sets. The original sets are not modified.
func (*Set[T]) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface. Expects a JSON array. Duplicates are automatically ignored.
type SyncOrderedSet ¶
OrderedSet is a set that provides additional methods for ordered types (int, float, string, etc.).
func NewSyncOrderedSet ¶
func NewSyncOrderedSet[T Ordered](elements ...T) *SyncOrderedSet[T]
func NewSyncOrderedSetWithCapacity ¶
func NewSyncOrderedSetWithCapacity[T Ordered](capacity int, elements ...T) *SyncOrderedSet[T]
Create a new OrderedSet with the provided optional elements and initial capacity.
func (*SyncOrderedSet[T]) MarshalJSON ¶
func (s *SyncOrderedSet[T]) MarshalJSON() ([]byte, error)
MarshalJSON marshals as JSON array in sorted order (thread-safe).
func (*SyncOrderedSet[T]) Max ¶
func (s *SyncOrderedSet[T]) Max() T
Max returns the maximum element in the set.
func (*SyncOrderedSet[T]) Min ¶
func (s *SyncOrderedSet[T]) Min() T
Min returns the minimum element in the set.
func (*SyncOrderedSet[T]) Sort ¶
func (s *SyncOrderedSet[T]) Sort(sortFunc func(a, b T) bool) []T
Sort returns a slice of the set's elements sorted according to the provided sort function.
func (*SyncOrderedSet[T]) Sorted ¶
func (s *SyncOrderedSet[T]) Sorted() []T
Sorted returns a sorted slice of the elements in the set. (A convenient wrapper that is not available in the base functions).
func (*SyncOrderedSet[T]) Sum ¶
func (s *SyncOrderedSet[T]) Sum() T
Sum returns the sum of all elements in the set.
func (*SyncOrderedSet[T]) UnmarshalJSON ¶
func (s *SyncOrderedSet[T]) UnmarshalJSON(data []byte) error
UnmarshalJSON unmarshals from JSON array (thread-safe).
type SyncSet ¶
type SyncSet[T comparable] struct { // contains filtered or unexported fields }
SyncSet is a thread-safe wrapper around Set. It uses sync.RWMutex to protect concurrent access.
func NewSyncSet ¶
func NewSyncSet[T comparable](elements ...T) *SyncSet[T]
NewSyncSet creates and initializes a new SyncSet with the provided optional elements.
func NewSyncSetWithCapacity ¶
func NewSyncSetWithCapacity[T comparable](capacity int, elements ...T) *SyncSet[T]
NewSyncSetWithCapacity creates and initializes a new SyncSet with the provided optional elements.
func (*SyncSet[T]) Add ¶
func (s *SyncSet[T]) Add(elements ...T)
Add inserts the provided elements into the set. Thread-safe.
func (*SyncSet[T]) All ¶
All returns true if all elements in the set satisfy the predicate. Thread-safe.
func (*SyncSet[T]) Any ¶
Any returns true if at least one element in the set satisfies the predicate. Thread-safe.
func (*SyncSet[T]) Clear ¶
func (s *SyncSet[T]) Clear()
Clear removes all elements from the set, making it empty. Thread-safe.
func (*SyncSet[T]) Contains ¶
Contains checks if the specified element exists in the set. Thread-safe.
func (*SyncSet[T]) Copy ¶
Copy creates a shallow copy of the set. Thread-safe. Returns a new SyncSet.
func (*SyncSet[T]) Count ¶
Count returns the number of elements in the set that satisfy the given predicate. Thread-safe.
func (*SyncSet[T]) Difference ¶
Difference returns a new set containing elements that exist in this set but not in the other set. Thread-safe. Returns a non-sync Set.
func (*SyncSet[T]) Equals ¶
Equals returns true if both sets contain the same elements. Thread-safe.
func (*SyncSet[T]) EqualsWith ¶
EqualsWith checks if this set is equal to another set using a custom equality function. Thread-safe.
func (*SyncSet[T]) Filter ¶
Filter creates a new set containing only the elements that satisfy the predicate. Thread-safe. Returns a non-sync Set.
func (*SyncSet[T]) FilterIter ¶
FilterIter returns an iterator that yields only elements satisfying the predicate. Thread-safe. Holds a read lock during iteration.
func (*SyncSet[T]) FlatMap ¶
FlatMap creates a new set by applying the mapper function to each element and merging results. Thread-safe. Returns a non-sync Set.
func (*SyncSet[T]) FlatMapIter ¶
FlatMapIter returns an iterator that flattens sequences produced by the mapper function. Thread-safe. Holds a read lock during iteration.
func (*SyncSet[T]) ForEach ¶
func (s *SyncSet[T]) ForEach(action func(T))
ForEach executes the given action function for each element in the set. Thread-safe. Holds a read lock during execution. Note: Do not modify the set within the action function to avoid deadlocks.
func (*SyncSet[T]) Intersection ¶
Intersection returns a new set containing only elements that exist in both sets. Thread-safe. Returns a non-sync Set.
func (*SyncSet[T]) IsDisjoint ¶
IsDisjoint returns true if this set and the other set have no elements in common. Thread-safe.
func (*SyncSet[T]) IsSubset ¶
IsSubset returns true if all elements of this set are contained in the other set. Thread-safe.
func (*SyncSet[T]) IsSuperset ¶
IsSuperset returns true if this set contains all elements of the other set. Thread-safe.
func (*SyncSet[T]) Iter ¶
Iter returns an iterator (iter.Seq) over the elements of the set. Thread-safe. Holds a read lock during iteration.
func (*SyncSet[T]) Map ¶
Map creates a new set by applying the mapper function to each element. Thread-safe. Returns a non-sync Set.
func (*SyncSet[T]) MapIter ¶
MapIter returns an iterator that yields transformed elements using the mapper function. Thread-safe. Holds a read lock during iteration.
func (*SyncSet[T]) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface (thread-safe).
func (*SyncSet[T]) Partition ¶
Partition splits the set into two sets based on the given predicate. Thread-safe. Returns non-sync Sets.
func (*SyncSet[T]) Reduce ¶
func (s *SyncSet[T]) Reduce(initial T, reducer func(T, T) T) T
Reduce applies the reducer function to each element in the set. Thread-safe.
func (*SyncSet[T]) Remove ¶
func (s *SyncSet[T]) Remove(elements ...T)
Remove deletes the provided elements from the set. Thread-safe.
func (*SyncSet[T]) Retain ¶
Retain removes all elements from the set that do NOT satisfy the predicate. Thread-safe.
func (*SyncSet[T]) SymmetricDifference ¶
SymmetricDifference returns a new set containing elements that exist in either set, but not in both. Thread-safe. Returns a non-sync Set.
func (*SyncSet[T]) ToSlice ¶
func (s *SyncSet[T]) ToSlice() []T
ToSlice converts the set elements into a slice. Thread-safe. Returns a snapshot of the current elements.
func (*SyncSet[T]) Union ¶
Union returns a new set containing all elements from both sets. Thread-safe. Returns a non-sync Set.
func (*SyncSet[T]) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface (thread-safe).