uset

package
v1.17.2 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2024 License: MIT Imports: 6 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 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]() *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

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

Jump to

Keyboard shortcuts

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