types

package
v0.0.0-...-dd9910a Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2026 License: MIT Imports: 2 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Clonable

type Clonable[T any] interface {
	Clone() T
}

Clonable defines a constraint of types having Clone() T method.

type Entry

type Entry[K comparable, V any] struct {
	Key   K
	Value V
}

Entry defines a key/value pairs.

type Set

type Set[T comparable] struct {
	// contains filtered or unexported fields
}

Set represents a thread-safe set data structure that stores unique elements of type T. Backed by a regular map protected by sync.RWMutex, which is more efficient than sync.Map for most set workloads (frequent reads and writes on the same keys).

func NewSet

func NewSet[T comparable]() *Set[T]

NewSet creates a new instance of the Set data structure.

func (*Set[T]) Exist

func (s *Set[T]) Exist(v T) bool

Exist checks if an element exists in the set. It returns a boolean indicating whether the element exists in the set (true if exists, false if not found).

func (*Set[T]) Pop

func (s *Set[T]) Pop(v T) (T, bool)

Pop removes an element from the set. It returns the removed element and a boolean indicating whether the element existed in the set.

func (*Set[T]) Put

func (s *Set[T]) Put(v T) bool

Put adds an element to the set. It returns a boolean indicating whether the element was added successfully (true if added, false if already exists).

func (*Set[T]) Range

func (s *Set[T]) Range(f func(t T) bool)

Range iterates over all elements in the set and calls the provided function for each element. It stops iteration if the function returns false. Note: the callback is invoked under a read lock; avoid long-running or blocking operations inside it.

func (*Set[T]) Remove

func (s *Set[T]) Remove(v T) bool

Remove removes an element from the set. It returns a boolean indicating whether the element was successfully removed (true if removed, false if not found).

func (*Set[T]) Size

func (s *Set[T]) Size() int64

Size returns the current size of the set.

Jump to

Keyboard shortcuts

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