Documentation
¶
Index ¶
- type ConcurrentSet
- func (cs ConcurrentSet[T]) Add(element T)
- func (cs ConcurrentSet[T]) AddAll(elements []T)
- func (cs ConcurrentSet[T]) Clear()
- func (cs ConcurrentSet[T]) Contains(other ds.Collection[T]) bool
- func (cs ConcurrentSet[T]) Count() int
- func (cs ConcurrentSet[T]) Difference(other ds.Set[T]) []T
- func (cs ConcurrentSet[T]) Equals(other ds.Collection[T]) bool
- func (cs ConcurrentSet[T]) ForEach(doEachFn func(element T) bool)
- func (cs ConcurrentSet[T]) Has(element T) bool
- func (cs ConcurrentSet[T]) Intersect(other ds.Set[T]) []T
- func (cs ConcurrentSet[T]) IsEmpty() bool
- func (cs ConcurrentSet[T]) IsProperSubset(other ds.Set[T]) bool
- func (cs ConcurrentSet[T]) Items() []T
- func (cs ConcurrentSet[T]) Iter() <-chan T
- func (cs ConcurrentSet[T]) MarshalJSON() ([]byte, error)
- func (cs ConcurrentSet[T]) Pop() (v T, ok bool)
- func (cs ConcurrentSet[T]) Remove(element T) bool
- func (cs ConcurrentSet[T]) RemoveAll(elements []T) bool
- func (cs ConcurrentSet[T]) RemoveIf(element T, conditionFn func() bool) bool
- func (cs ConcurrentSet[T]) String() string
- func (cs ConcurrentSet[T]) SymmetricDifference(other ds.Set[T]) []T
- func (cs ConcurrentSet[T]) Union(other ds.Set[T]) []T
- func (cs ConcurrentSet[T]) UnmarshalJSON(b []byte) error
- type HashSet
- func (hs HashSet[T]) Add(element T)
- func (hs HashSet[T]) AddAll(elements []T)
- func (hs HashSet[T]) Clear()
- func (hs HashSet[T]) Contains(other ds.Collection[T]) bool
- func (hs HashSet[T]) Count() int
- func (hs HashSet[T]) Difference(other ds.Set[T]) []T
- func (hs HashSet[T]) Equals(other ds.Collection[T]) bool
- func (hs HashSet[T]) ForEach(doEachFn func(element T) bool)
- func (hs HashSet[T]) Has(element T) bool
- func (hs HashSet[T]) Intersect(other ds.Set[T]) []T
- func (hs HashSet[T]) IsEmpty() bool
- func (hs HashSet[T]) IsProperSubset(other ds.Set[T]) bool
- func (hs HashSet[T]) Items() []T
- func (hs HashSet[T]) Iter() <-chan T
- func (hs HashSet[T]) MarshalJSON() ([]byte, error)
- func (hs HashSet[T]) Pop() (v T, ok bool)
- func (hs HashSet[T]) Remove(element T) bool
- func (hs HashSet[T]) RemoveAll(elements []T) bool
- func (hs HashSet[T]) RemoveIf(element T, conditionFn func() bool) bool
- func (hs HashSet[T]) String() string
- func (hs HashSet[T]) SymmetricDifference(other ds.Set[T]) []T
- func (hs HashSet[T]) Union(other ds.Set[T]) []T
- func (hs HashSet[T]) UnmarshalJSON(b []byte) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConcurrentSet ¶
type ConcurrentSet[T comparable] emap.ConcurrentMap[T, struct{}]
func NewConcurrentSet ¶
func NewConcurrentSet[T comparable](elements ...T) ConcurrentSet[T]
NewConcurrentSet returns a new instance of ConcurrentSet with the given elements.
func NewConcurrentSetWithConcurrencyLevel ¶
func NewConcurrentSetWithConcurrencyLevel[T comparable](concurrencyLevel int, elements ...T) ConcurrentSet[T]
NewConcurrentSetWithConcurrencyLevel returns a new instance of ConcurrentSet with the given amount of shards and contains the given elements.
func (ConcurrentSet[T]) AddAll ¶
func (cs ConcurrentSet[T]) AddAll(elements []T)
AddAll adds all elements from the given slice to this set.
func (ConcurrentSet[T]) Clear ¶
func (cs ConcurrentSet[T]) Clear()
Clear removes all elements from this set.
func (ConcurrentSet[T]) Contains ¶
func (cs ConcurrentSet[T]) Contains(other ds.Collection[T]) bool
Contains returns whether all elements in `other` are in this set.
func (ConcurrentSet[T]) Count ¶
func (cs ConcurrentSet[T]) Count() int
Count returns the size of this set.
func (ConcurrentSet[T]) Difference ¶
func (cs ConcurrentSet[T]) Difference(other ds.Set[T]) []T
Difference returns all elements of this set that are not in `other`.
func (ConcurrentSet[T]) Equals ¶
func (cs ConcurrentSet[T]) Equals(other ds.Collection[T]) bool
Equals returns whether this and `other` collections have the same size and contain the same elements.
func (ConcurrentSet[T]) ForEach ¶
func (cs ConcurrentSet[T]) ForEach(doEachFn func(element T) bool)
ForEach executes the given doEachFn on every element in this set. If `doEachFn` returns true, stop execution immediately.
Note: doEachFn is called while lock is held. Hence, it must NOT access this set as it may lead to deadlock since sync.RWLock in the underlying emap.ConcurrentMap is not reentrant.
func (ConcurrentSet[T]) Has ¶
func (cs ConcurrentSet[T]) Has(element T) bool
Has returns whether given element is in this set.
func (ConcurrentSet[T]) Intersect ¶
func (cs ConcurrentSet[T]) Intersect(other ds.Set[T]) []T
Intersect returns all elements that exist in both sets.
func (ConcurrentSet[T]) IsEmpty ¶
func (cs ConcurrentSet[T]) IsEmpty() bool
IsEmpty returns whether this set is empty.
func (ConcurrentSet[T]) IsProperSubset ¶
func (cs ConcurrentSet[T]) IsProperSubset(other ds.Set[T]) bool
IsProperSubset returns whether all elements in this set are in `other` but they are not equal.
func (ConcurrentSet[T]) Items ¶
func (cs ConcurrentSet[T]) Items() []T
Items returns all elements of this set as a slice.
func (ConcurrentSet[T]) Iter ¶
func (cs ConcurrentSet[T]) Iter() <-chan T
Iter returns a channel which could be used in a for range loop. The capacity of the returned channel is the same as the size of the set at the time Iter is called.
func (ConcurrentSet[T]) MarshalJSON ¶
func (cs ConcurrentSet[T]) MarshalJSON() ([]byte, error)
MarshalJSON returns the JSON bytes of this set.
func (ConcurrentSet[T]) Pop ¶
func (cs ConcurrentSet[T]) Pop() (v T, ok bool)
Pop removes and returns an element from this set.
func (ConcurrentSet[T]) Remove ¶
func (cs ConcurrentSet[T]) Remove(element T) bool
Remove removes an element from this set, returns whether this set changed as a result of the call.
func (ConcurrentSet[T]) RemoveAll ¶
func (cs ConcurrentSet[T]) RemoveAll(elements []T) bool
RemoveAll removes the given elements from this set, returns whether this set changed as a result of the call.
func (ConcurrentSet[T]) RemoveIf ¶
func (cs ConcurrentSet[T]) RemoveIf(element T, conditionFn func() bool) bool
RemoveIf removes the given element from this set based on some condition, then returns true if the element was removed. If the given element doesn't exist in this set or the element was not removed because of the condition func, false will be returned.
Note: Condition func is called while lock is held. Hence, it must NOT access this set as it may lead to deadlock since sync.RWLock in the underlying emap.ConcurrentMap is not reentrant.
func (ConcurrentSet[T]) String ¶
func (cs ConcurrentSet[T]) String() string
String returns a string representation of the current state of the set.
func (ConcurrentSet[T]) SymmetricDifference ¶
func (cs ConcurrentSet[T]) SymmetricDifference(other ds.Set[T]) []T
SymmetricDifference returns all elements that are in either this set or `other` but not in both.
func (ConcurrentSet[T]) Union ¶
func (cs ConcurrentSet[T]) Union(other ds.Set[T]) []T
Union returns all elements that are in both sets.
func (ConcurrentSet[T]) UnmarshalJSON ¶
func (cs ConcurrentSet[T]) UnmarshalJSON(b []byte) error
UnmarshalJSON consumes a slice of JSON bytes to populate this set.
type HashSet ¶
type HashSet[T comparable] map[T]struct{}
func NewHashSet ¶
func NewHashSet[T comparable](elements ...T) HashSet[T]
NewHashSet returns a new instance of HashSet with the given elements.
func NewHashSetWithInitialSize ¶
func NewHashSetWithInitialSize[T comparable](initialSize int) HashSet[T]
NewHashSetWithInitialSize returns a new instance of HashSet with the given initial size.
func (HashSet[T]) AddAll ¶
func (hs HashSet[T]) AddAll(elements []T)
AddAll adds all elements from the given slice to this set.
func (HashSet[T]) Contains ¶
func (hs HashSet[T]) Contains(other ds.Collection[T]) bool
Contains returns whether all elements in `other` are in this set.
func (HashSet[T]) Difference ¶
Difference returns all elements of this set that are not in `other`.
func (HashSet[T]) Equals ¶
func (hs HashSet[T]) Equals(other ds.Collection[T]) bool
Equals returns whether this and `other` collections have the same size and contain the same elements.
func (HashSet[T]) ForEach ¶
ForEach executes the given doEachFn on every element in this set. If `doEachFn` returns true, stop execution immediately.
func (HashSet[T]) IsProperSubset ¶
IsProperSubset returns whether all elements in this set are in `other` but they are not equal.
func (HashSet[T]) Items ¶
func (hs HashSet[T]) Items() []T
Items returns all elements of this set as a slice.
func (HashSet[T]) Iter ¶
func (hs HashSet[T]) Iter() <-chan T
Iter returns a channel which could be used in a for range loop. The capacity of the returned channel is the same as the size of the set at the time Iter is called.
func (HashSet[T]) MarshalJSON ¶
MarshalJSON returns the JSON bytes of this set.
func (HashSet[T]) Remove ¶
Remove removes an element from this set, returns whether this set changed as a result of the call.
func (HashSet[T]) RemoveAll ¶
RemoveAll removes the given elements from this set, returns whether this set changed as a result of the call.
func (HashSet[T]) RemoveIf ¶
RemoveIf removes the given element from this set based on some condition, then returns true if the element was removed. If the given element doesn't exist in this set or the element was not removed because of the condition func, false will be returned.
func (HashSet[T]) SymmetricDifference ¶
SymmetricDifference returns all elements that are in either this set or `other` but not in both.
func (HashSet[T]) UnmarshalJSON ¶
UnmarshalJSON consumes a slice of JSON bytes to populate this set.