Documentation
¶
Index ¶
- type ComparableHashSet
- func (s *ComparableHashSet[T, K]) Add(value T) bool
- func (s *ComparableHashSet[T, K]) Clear()
- func (s *ComparableHashSet[T, K]) Compare(lhv, rhv T) bool
- func (s *ComparableHashSet[T, K]) Contains(value T) bool
- func (s *ComparableHashSet[T, K]) Remove(value T) bool
- func (s *ComparableHashSet[T, K]) Size() int
- type ComparableSet
- type ConcurrentHashSet
- type HashSet
- type Set
- type SynchronizedHashSet
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ComparableHashSet ¶ added in v1.17.9
type ComparableHashSet[T uconst.UniqueKey[K], K comparable] struct { // contains filtered or unexported fields }
ComparableHashSet is the same as HashSet
func NewComparableHashSet ¶ added in v1.17.9
func NewComparableHashSet[T uconst.UniqueKey[K], K comparable](values ...T) *ComparableHashSet[T, K]
NewComparableHashSet creates a new instance of HashSet with the default size
func NewComparableHashSetWithSize ¶ added in v1.17.9
func NewComparableHashSetWithSize[T uconst.UniqueKey[K], K comparable](size int) *ComparableHashSet[T, K]
NewComparableHashSetWithSize creates a new instance of HashSet with a specified initial size
func (*ComparableHashSet[T, K]) Add ¶ added in v1.17.9
func (s *ComparableHashSet[T, K]) Add(value T) bool
Add inserts a value into the set and returns true if the value was not already present
func (*ComparableHashSet[T, K]) Clear ¶ added in v1.17.9
func (s *ComparableHashSet[T, K]) Clear()
Clear returns the number of elements in the set
func (*ComparableHashSet[T, K]) Compare ¶ added in v1.17.9
func (s *ComparableHashSet[T, K]) Compare(lhv, rhv T) bool
Compare compares two values of type T based on their keys and returns an integer indicating their relative order. The keys are obtained by calling the Key() method on the values of type T.
Parameters: - lhv: The left-hand value to be compared. - rhv: The right-hand value to be compared.
Returns: - true if keys are equals - false otherwise
The method assumes that T implements a Key() method that returns an integer value which can be used for comparison.
func (*ComparableHashSet[T, K]) Contains ¶ added in v1.17.9
func (s *ComparableHashSet[T, K]) Contains(value T) bool
Contains checks if a value is present in the set
func (*ComparableHashSet[T, K]) Remove ¶ added in v1.17.9
func (s *ComparableHashSet[T, K]) Remove(value T) bool
Remove deletes a value from the set and returns true if the value was present
func (*ComparableHashSet[T, K]) Size ¶ added in v1.17.9
func (s *ComparableHashSet[T, K]) Size() int
Size returns the number of elements in the set
type ComparableSet ¶ added in v1.17.9
type ConcurrentHashSet ¶
type ConcurrentHashSet[T comparable] struct { // contains filtered or unexported fields }
ConcurrentHashSet is a work-in-progress experimental thread-safe set implementation that uses atomic operations and sync.Map. !!! This implementation is not yet optimized and may contain bugs. For stable usage, prefer SynchronizedHashSet. Deprecated, use SynchronizedHashSet instead.
func NewConcurrentHashSet ¶
func NewConcurrentHashSet[T comparable]() *ConcurrentHashSet[T]
NewConcurrentHashSet creates a new instance of ConcurrentHashSet with default Farm64 hash implementation
func NewCustomConcurrentHashSet ¶
func NewCustomConcurrentHashSet[T comparable](hash func(value *T) uint64) *ConcurrentHashSet[T]
NewCustomConcurrentHashSet creates a new instance of ConcurrentHashSet with specific hashing implementation
func (*ConcurrentHashSet[T]) Add ¶
func (s *ConcurrentHashSet[T]) Add(value T) bool
Add inserts a value into the set
func (*ConcurrentHashSet[T]) Clear ¶
func (s *ConcurrentHashSet[T]) Clear()
Clear removes all elements from the set
func (*ConcurrentHashSet[T]) Contains ¶
func (s *ConcurrentHashSet[T]) Contains(value T) bool
Contains checks if a value is present in the set
func (*ConcurrentHashSet[T]) Remove ¶
func (s *ConcurrentHashSet[T]) Remove(value T) bool
Remove deletes a value from the set
func (*ConcurrentHashSet[T]) Size ¶
func (s *ConcurrentHashSet[T]) Size() int
Size returns the number of elements in the set
type HashSet ¶
type HashSet[T comparable] struct { // contains filtered or unexported fields }
HashSet is a generic set data structure that ensures all elements are unique. It uses a map to provide efficient operations for adding, removing, and checking elements.
func NewHashSet ¶
func NewHashSet[T comparable](values ...T) *HashSet[T]
NewHashSet creates a new instance of HashSet with the default size
func NewHashSetWithSize ¶
func NewHashSetWithSize[T comparable](size int) *HashSet[T]
NewHashSetWithSize creates a new instance of HashSet with a specified initial size
func (*HashSet[T]) Add ¶
Add inserts a value into the set and returns true if the value was not already present
func (*HashSet[T]) Clear ¶
func (s *HashSet[T]) Clear()
Clear returns the number of elements in the set
type Set ¶
type Set[T comparable] interface { Add(value T) bool Contains(value T) bool Remove(value T) bool Size() int Clear() }
type SynchronizedHashSet ¶
type SynchronizedHashSet[T comparable] struct { // contains filtered or unexported fields }
SynchronizedHashSet is a thread-safe wrapper around HashSet that ensures concurrent safety.
func NewSynchronizedHashSet ¶
func NewSynchronizedHashSet[T comparable](values ...T) *SynchronizedHashSet[T]
func NewSynchronizedHashSetFromSet ¶
func NewSynchronizedHashSetFromSet[T comparable](hs *HashSet[T]) *SynchronizedHashSet[T]
func (*SynchronizedHashSet[T]) Add ¶
func (s *SynchronizedHashSet[T]) Add(value T) bool
func (*SynchronizedHashSet[T]) Clear ¶
func (s *SynchronizedHashSet[T]) Clear()
func (*SynchronizedHashSet[T]) Contains ¶
func (s *SynchronizedHashSet[T]) Contains(value T) bool
func (*SynchronizedHashSet[T]) Remove ¶
func (s *SynchronizedHashSet[T]) Remove(value T) bool
func (*SynchronizedHashSet[T]) Size ¶
func (s *SynchronizedHashSet[T]) Size() int