uset

package
v1.23.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 6, 2024 License: MIT Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

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, but allows for custom UniqueKey definition.

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]) 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

func (*ComparableHashSet[T, K]) Values added in v1.17.11

func (s *ComparableHashSet[T, K]) Values() []T

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

func (*ConcurrentHashSet[T]) Values added in v1.17.11

func (s *ConcurrentHashSet[T]) Values() []T

Values retrieves all the values

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

func (s *HashSet[T]) Add(value T) bool

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

func (*HashSet[T]) Contains

func (s *HashSet[T]) Contains(value T) bool

Contains checks if a value is present in the set

func (*HashSet[T]) Remove

func (s *HashSet[T]) Remove(value T) bool

Remove deletes a value from the set and returns true if the value was present

func (*HashSet[T]) Size

func (s *HashSet[T]) Size() int

Size returns the number of elements in the set

func (*HashSet[T]) Values added in v1.17.11

func (s *HashSet[T]) Values() []T

Values retrieves all the values

type OrderedHashSet added in v1.17.10

type OrderedHashSet[T uconst.UniqueKey[K], K comparable] struct {
	// contains filtered or unexported fields
}

OrderedHashSet is a set implementation that preserves the order of elements as they were added. This implementation is slower than a traditional HashSet or ComparableHashset, therefore it's recommended to use this only in cases you need to retrieve the items in their original order.

func NewOrderedHashSet added in v1.17.10

func NewOrderedHashSet[T uconst.UniqueKey[K], K comparable](values ...T) *OrderedHashSet[T, K]

NewOrderedHashSet creates a new instance of OrderedHashSet.

func (*OrderedHashSet[T, K]) Add added in v1.17.10

func (s *OrderedHashSet[T, K]) Add(value T) bool

Add inserts a value into the set and returns true if the value was not already present.

func (*OrderedHashSet[T, K]) Clear added in v1.17.10

func (s *OrderedHashSet[T, K]) Clear()

Clear removes all elements from the set.

func (*OrderedHashSet[T, K]) Contains added in v1.17.10

func (s *OrderedHashSet[T, K]) Contains(value T) bool

Contains checks if a value is present in the set.

func (*OrderedHashSet[T, K]) Delete added in v1.17.13

func (s *OrderedHashSet[T, K]) Delete(key K) bool

Delete deletes a value from the set by unique key and returns true if the value was present.

func (*OrderedHashSet[T, K]) Get added in v1.17.12

func (s *OrderedHashSet[T, K]) Get(key K) *T

Get retrieves the element by unique key

func (*OrderedHashSet[T, K]) OrderedList added in v1.17.11

func (s *OrderedHashSet[T, K]) OrderedList() []T

OrderedList returns a slice of all elements in the set, in the order they were added.

func (*OrderedHashSet[T, K]) Remove added in v1.17.10

func (s *OrderedHashSet[T, K]) Remove(value T) bool

Remove deletes a value from the set and returns true if the value was present.

func (*OrderedHashSet[T, K]) Size added in v1.17.10

func (s *OrderedHashSet[T, K]) Size() int

Size returns the number of elements in the set.

type OrderedSet added in v1.17.10

type OrderedSet[T uconst.UniqueKey[K], K comparable] interface {
	Add(value T) bool
	Contains(value T) bool
	Get(key K) *T // Retrieve value by key
	Delete(key K) bool
	Remove(value T) bool
	Size() int
	Clear()
	OrderedList() []T // OrderedList returns the slice of ordered items while preserving their natural order
}

OrderedSet is an interface that represents a set of unique items that can be retrieved in the original insertion order. It is parameterized by T, which must implement uconst.UniqueKey[K], and K, which must be comparable.

type Set

type Set[T comparable] interface {
	Add(value T) bool
	Contains(value T) bool
	Remove(value T) bool
	Size() int
	Clear()
	Values() []T
}

Set that contains unique elements.

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

func (*SynchronizedHashSet[T]) Values added in v1.17.11

func (s *SynchronizedHashSet[T]) Values() []T

Values retrieves all the values

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL