Documentation ¶
Overview ¶
Package set provides both threadsafe and non-threadsafe implementations of a generic set data structure. In the threadsafe set, safety encompasses all operations on one set. Operations on multiple sets are consistent in that the elements of each set used was valid at exactly one point in time between the start and the end of the operation.
Index ¶
- type Hashable
- type Set
- func Difference[T any](set1, set2 Set[T], sets ...Set[T]) Set[T]
- func Intersection[T any](set1, set2 Set[T], sets ...Set[T]) Set[T]
- func New[T comparable]() Set[T]
- func NewAny[T Hashable]() Set[T]
- func NewAnyNonTS[T Hashable]() Set[T]
- func NewNonTS[T comparable]() Set[T]
- func SymmetricDifference[T any](s, t Set[T]) Set[T]
- func Union[T any](set1, set2 Set[T], sets ...Set[T]) Set[T]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Set ¶
type Set[T any] interface { Add(items ...T) Set[T] Remove(items ...T) Set[T] Pop() (T, bool) Has(items ...T) bool // Size returns the number of items in a set. Size() int // Clear removes all items from the set. Clear() // IsEmpty reports whether the Set is empty. IsEmpty() bool // IsEqual test whether s and t are the same in size and have the same // items. IsEqual(s Set[T]) bool IsSubset(s Set[T]) bool IsSuperset(s Set[T]) bool // Each traverses the items in the Set, calling the provided function for // each set member. Traversal will continue until all items in the Set have // been visited, or if the closure returns false. Each(func(T) bool) bool String() string List() []T // Copy returns a new Set with a copy of s. Copy() Set[T] // Merge is like Union, however it modifies the current set it's applied on // with the given t set. Merge(s Set[T]) Set[T] Separate(s Set[T]) Set[T] }
Set is describing a Set. Sets are an unordered, unique list of values.
func Difference ¶
Difference returns a new set which contains items which are in in the first set but not in the others. Unlike the Difference() method you can use this function separately with multiple sets.
func Intersection ¶
Intersection returns a new set which contains items that only exist in all given sets.
func New ¶
func New[T comparable]() Set[T]
New creates and initalizes a new Set interface. Its single parameter denotes the type of set to create. Either ThreadSafe or NonThreadSafe. The default is ThreadSafe.
func NewAnyNonTS ¶
func NewNonTS ¶
func NewNonTS[T comparable]() Set[T]
func SymmetricDifference ¶
SymmetricDifference returns a new set which s is the difference of items which are in one of either, but not in both.