dataext

package
v0.0.623 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEmptyStack = errors.New("stack is empty")

Functions

func ObjectMerge

func ObjectMerge[T1 any, T2 any](base T1, override T2) T1

func StructHash

func StructHash(dat any, opt ...StructHashOptions) (r []byte, err error)

Types

type BroadcastSubscription added in v0.0.599

type BroadcastSubscription interface {
	Unsubscribe()
}

type Broadcaster added in v0.0.599

type Broadcaster[TData any] struct {
	// contains filtered or unexported fields
}

Broadcaster is a simple Broadcaster channel This is a simpler interface over Broadcaster - which does not have distinct namespaces

func NewBroadcaster added in v0.0.600

func NewBroadcaster[TData any](capacity int) *Broadcaster[TData]

func (*Broadcaster[TData]) Publish added in v0.0.599

func (bb *Broadcaster[TData]) Publish(data TData) (subscriber int, actualReceiver int)

Publish sends `data` to all subscriber But unbuffered - if one is currently not listening, we skip (the actualReceiver < subscriber)

func (*Broadcaster[TData]) PublishWithContext added in v0.0.599

func (bb *Broadcaster[TData]) PublishWithContext(ctx context.Context, data TData) (subscriber int, actualReceiver int, err error)

PublishWithContext sends `data` to all subscriber buffered - if one is currently not listening, we wait (but error out when the context runs out)

func (*Broadcaster[TData]) PublishWithTimeout added in v0.0.599

func (bb *Broadcaster[TData]) PublishWithTimeout(data TData, timeout time.Duration) (subscriber int, actualReceiver int)

PublishWithTimeout sends `data` to all subscriber buffered - if one is currently not listening, we wait (but wait at most `timeout` - if the timeout is exceeded then actualReceiver < subscriber)

func (*Broadcaster[TData]) SubscribeByCallback added in v0.0.599

func (bb *Broadcaster[TData]) SubscribeByCallback(fn func(TData)) BroadcastSubscription

func (*Broadcaster[TData]) SubscribeByChan added in v0.0.599

func (bb *Broadcaster[TData]) SubscribeByChan(chanBufferSize int) (chan TData, BroadcastSubscription)

func (*Broadcaster[TData]) SubscribeByIter added in v0.0.599

func (bb *Broadcaster[TData]) SubscribeByIter(chanBufferSize int) (iter.Seq[TData], BroadcastSubscription)

func (*Broadcaster[TData]) SubscriberCount added in v0.0.599

func (bb *Broadcaster[TData]) SubscriberCount() int

type BufferedReadCloser

type BufferedReadCloser interface {
	io.ReadCloser
	BufferedAll() ([]byte, error)
	Reset() error
}

func NewBufferedReadCloser

func NewBufferedReadCloser(sub io.ReadCloser) BufferedReadCloser

type CASMutex

type CASMutex struct {
	// contains filtered or unexported fields
}

CASMutex is the struct implementing RWMutex with CAS mechanism.

func NewCASMutex

func NewCASMutex() *CASMutex

func (*CASMutex) Lock

func (m *CASMutex) Lock()

Lock acquires the lock. If it is currently held by others, Lock will wait until it has a chance to acquire it.

func (*CASMutex) RLock

func (m *CASMutex) RLock()

RLock acquires the read lock. If it is currently held by others writing, RLock will wait until it has a chance to acquire it.

func (*CASMutex) RLocker

func (m *CASMutex) RLocker() sync.Locker

RLocker returns a Locker interface that implements the Lock and Unlock methods by calling CASMutex.RLock and CASMutex.RUnlock.

func (*CASMutex) RTryLock

func (m *CASMutex) RTryLock() bool

RTryLock attempts to acquire the read lock without blocking. Return false if someone is writing it now.

func (*CASMutex) RTryLockWithContext

func (m *CASMutex) RTryLockWithContext(ctx context.Context) bool

RTryLockWithContext attempts to acquire the read lock, blocking until resources are available or ctx is done (timeout or cancellation).

func (*CASMutex) RTryLockWithTimeout

func (m *CASMutex) RTryLockWithTimeout(duration time.Duration) bool

RTryLockWithTimeout attempts to acquire the read lock within a period of time. Return false if spending time is more than duration and no chance to acquire it.

func (*CASMutex) RUnlock

func (m *CASMutex) RUnlock()

RUnlock releases the read lock.

func (*CASMutex) TryLock

func (m *CASMutex) TryLock() bool

TryLock attempts to acquire the lock without blocking. Return false if someone is holding it now.

func (*CASMutex) TryLockWithContext

func (m *CASMutex) TryLockWithContext(ctx context.Context) bool

TryLockWithContext attempts to acquire the lock, blocking until resources are available or ctx is done (timeout or cancellation).

func (*CASMutex) TryLockWithTimeout

func (m *CASMutex) TryLockWithTimeout(duration time.Duration) bool

TryLockWithTimeout attempts to acquire the lock within a period of time. Return false if spending time is more than duration and no chance to acquire it.

func (*CASMutex) Unlock

func (m *CASMutex) Unlock()

Unlock releases the lock.

type DelayedCombiningInvoker added in v0.0.575

type DelayedCombiningInvoker struct {
	// contains filtered or unexported fields
}

DelayedCombiningInvoker is a utility to combine multiple consecutive requests into a single execution

Requests are made with Request(), and consecutive requests are combined during the `delay` period.

Can be used, e.g., for search-controls, where we want to init the search when teh user stops typing Or generally to queue an execution once a burst of requests is over.

func NewDelayedCombiningInvoker added in v0.0.575

func NewDelayedCombiningInvoker(action func(), delay time.Duration, maxDelay time.Duration) *DelayedCombiningInvoker

func (*DelayedCombiningInvoker) CancelPendingRequests added in v0.0.575

func (d *DelayedCombiningInvoker) CancelPendingRequests()

func (*DelayedCombiningInvoker) CountPendingRequests added in v0.0.602

func (d *DelayedCombiningInvoker) CountPendingRequests() int

func (*DelayedCombiningInvoker) ExecuteNow added in v0.0.575

func (d *DelayedCombiningInvoker) ExecuteNow() bool

func (*DelayedCombiningInvoker) HasPendingRequests added in v0.0.575

func (d *DelayedCombiningInvoker) HasPendingRequests() bool

func (*DelayedCombiningInvoker) RegisterOnExecutionDone added in v0.0.602

func (d *DelayedCombiningInvoker) RegisterOnExecutionDone(fn func())

func (*DelayedCombiningInvoker) RegisterOnExecutionStart added in v0.0.602

func (d *DelayedCombiningInvoker) RegisterOnExecutionStart(fn func(immediately bool))

func (*DelayedCombiningInvoker) RegisterOnRequest added in v0.0.602

func (d *DelayedCombiningInvoker) RegisterOnRequest(fn func(pending int, initial bool))

func (*DelayedCombiningInvoker) Request added in v0.0.575

func (d *DelayedCombiningInvoker) Request()

func (*DelayedCombiningInvoker) WaitForCompletion added in v0.0.575

func (d *DelayedCombiningInvoker) WaitForCompletion(ctx context.Context) error

type JsonOpt

type JsonOpt[T any] struct {
	// contains filtered or unexported fields
}

func EmptyJsonOpt

func EmptyJsonOpt[T any]() JsonOpt[T]

func NewJsonOpt

func NewJsonOpt[T any](v T) JsonOpt[T]

func (JsonOpt[T]) IfSet

func (m JsonOpt[T]) IfSet(fn func(v T)) bool

func (JsonOpt[T]) IsSet

func (m JsonOpt[T]) IsSet() bool

func (JsonOpt[T]) IsUnset

func (m JsonOpt[T]) IsUnset() bool

func (JsonOpt[T]) MarshalJSON

func (m JsonOpt[T]) MarshalJSON() ([]byte, error)

MarshalJSON returns m as the JSON encoding of m.

func (JsonOpt[T]) MustValue

func (m JsonOpt[T]) MustValue() T

func (*JsonOpt[T]) UnmarshalJSON

func (m *JsonOpt[T]) UnmarshalJSON(data []byte) error

UnmarshalJSON sets *m to a copy of data.

func (JsonOpt[T]) Value

func (m JsonOpt[T]) Value() (T, bool)

func (JsonOpt[T]) ValueDblPtrOrNil

func (m JsonOpt[T]) ValueDblPtrOrNil() **T

func (JsonOpt[T]) ValueOrNil

func (m JsonOpt[T]) ValueOrNil() *T

type LRUMap

type LRUMap[TKey comparable, TData any] struct {
	// contains filtered or unexported fields
}

func NewLRUMap

func NewLRUMap[TKey comparable, TData any](size int) *LRUMap[TKey, TData]

func (*LRUMap[TKey, TData]) Put

func (c *LRUMap[TKey, TData]) Put(key TKey, value TData)

func (*LRUMap[TKey, TData]) Size

func (c *LRUMap[TKey, TData]) Size() int

func (*LRUMap[TKey, TData]) TryGet

func (c *LRUMap[TKey, TData]) TryGet(key TKey) (TData, bool)

type MultiMutex added in v0.0.615

type MultiMutex[TKey comparable] struct {
	// contains filtered or unexported fields
}

MultiMutex is a simple map[key -> mutex]

func NewMultiMutex added in v0.0.615

func NewMultiMutex[TKey comparable]() *MultiMutex[TKey]

func (*MultiMutex[TKey]) Get added in v0.0.616

func (mm *MultiMutex[TKey]) Get(key TKey) sync.Locker

Get returns a Locker interface

func (*MultiMutex[TKey]) GetCAS added in v0.0.617

func (mm *MultiMutex[TKey]) GetCAS(key TKey) *CASMutex

GetCAS returns the underlying CASMutex

func (*MultiMutex[TKey]) Lock added in v0.0.615

func (mm *MultiMutex[TKey]) Lock(key TKey)

Lock acquires the lock. If it is currently held by others, Lock will wait until it has a chance to acquire it.

func (*MultiMutex[TKey]) RLock added in v0.0.615

func (mm *MultiMutex[TKey]) RLock(key TKey)

RLock acquires the read lock. If it is currently held by others writing, RLock will wait until it has a chance to acquire it.

func (*MultiMutex[TKey]) RLocker added in v0.0.615

func (mm *MultiMutex[TKey]) RLocker(key TKey) sync.Locker

RLocker returns a Locker interface that implements the Lock and Unlock methods by calling CASMutex.RLock and CASMutex.RUnlock.

func (*MultiMutex[TKey]) RTryLock added in v0.0.615

func (mm *MultiMutex[TKey]) RTryLock(key TKey) bool

RTryLock attempts to acquire the read lock without blocking. Return false if someone is writing it now.

func (*MultiMutex[TKey]) RTryLockWithContext added in v0.0.615

func (mm *MultiMutex[TKey]) RTryLockWithContext(ctx context.Context, key TKey) bool

RTryLockWithContext attempts to acquire the read lock, blocking until resources are available or ctx is done (timeout or cancellation).

func (*MultiMutex[TKey]) RTryLockWithTimeout added in v0.0.615

func (mm *MultiMutex[TKey]) RTryLockWithTimeout(duration time.Duration, key TKey) bool

RTryLockWithTimeout attempts to acquire the read lock within a period of time. Return false if spending time is more than duration and no chance to acquire it.

func (*MultiMutex[TKey]) RUnlock added in v0.0.615

func (mm *MultiMutex[TKey]) RUnlock(key TKey)

RUnlock releases the read lock.

func (*MultiMutex[TKey]) TryLock added in v0.0.615

func (mm *MultiMutex[TKey]) TryLock(key TKey) bool

TryLock attempts to acquire the lock without blocking. Return false if someone is holding it now.

func (*MultiMutex[TKey]) TryLockWithContext added in v0.0.615

func (mm *MultiMutex[TKey]) TryLockWithContext(ctx context.Context, key TKey) bool

TryLockWithContext attempts to acquire the lock, blocking until resources are available or ctx is done (timeout or cancellation).

func (*MultiMutex[TKey]) TryLockWithTimeout added in v0.0.615

func (mm *MultiMutex[TKey]) TryLockWithTimeout(key TKey, duration time.Duration) bool

TryLockWithTimeout attempts to acquire the lock within a period of time. Return false if spending time is more than duration and no chance to acquire it.

func (*MultiMutex[TKey]) Unlock added in v0.0.615

func (mm *MultiMutex[TKey]) Unlock(key TKey)

Unlock releases the lock.

type MutexSet added in v0.0.611

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

func NewMutexSet added in v0.0.611

func NewMutexSet[T comparable]() *MutexSet[T]

func (*MutexSet[T]) Lock added in v0.0.611

func (ms *MutexSet[T]) Lock(key T)

func (*MutexSet[T]) RLock added in v0.0.611

func (ms *MutexSet[T]) RLock(key T)

func (*MutexSet[T]) RUnlock added in v0.0.611

func (ms *MutexSet[T]) RUnlock(key T)

func (*MutexSet[T]) Unlock added in v0.0.611

func (ms *MutexSet[T]) Unlock(key T)

type Nonuple

type Nonuple[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any] struct {
	V1 T1
	V2 T2
	V3 T3
	V4 T4
	V5 T5
	V6 T6
	V7 T7
	V8 T8
	V9 T9
}

func NewNonuple

func NewNonuple[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any](v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, v7 T7, v8 T8, v9 T9) Nonuple[T1, T2, T3, T4, T5, T6, T7, T8, T9]

func NewTuple9

func NewTuple9[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any, T9 any](v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, v7 T7, v8 T8, v9 T9) Nonuple[T1, T2, T3, T4, T5, T6, T7, T8, T9]

func (Nonuple[T1, T2, T3, T4, T5, T6, T7, T8, T9]) TupleLength

func (t Nonuple[T1, T2, T3, T4, T5, T6, T7, T8, T9]) TupleLength() int

func (Nonuple[T1, T2, T3, T4, T5, T6, T7, T8, T9]) TupleValues

func (t Nonuple[T1, T2, T3, T4, T5, T6, T7, T8, T9]) TupleValues() []any

type Octuple

type Octuple[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any] struct {
	V1 T1
	V2 T2
	V3 T3
	V4 T4
	V5 T5
	V6 T6
	V7 T7
	V8 T8
}

func NewOctuple

func NewOctuple[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any](v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, v7 T7, v8 T8) Octuple[T1, T2, T3, T4, T5, T6, T7, T8]

func NewTuple8

func NewTuple8[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any, T8 any](v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, v7 T7, v8 T8) Octuple[T1, T2, T3, T4, T5, T6, T7, T8]

func (Octuple[T1, T2, T3, T4, T5, T6, T7, T8]) TupleLength

func (t Octuple[T1, T2, T3, T4, T5, T6, T7, T8]) TupleLength() int

func (Octuple[T1, T2, T3, T4, T5, T6, T7, T8]) TupleValues

func (t Octuple[T1, T2, T3, T4, T5, T6, T7, T8]) TupleValues() []any

type PubSub added in v0.0.591

type PubSub[TNamespace comparable, TData any] struct {
	// contains filtered or unexported fields
}

PubSub is a simple Pub/Sub Broker Clients can subscribe to a namespace and receive published messages on this namespace Messages are broadcast to all subscribers

func NewPubSub added in v0.0.591

func NewPubSub[TNamespace comparable, TData any](capacity int) *PubSub[TNamespace, TData]

func (*PubSub[TNamespace, TData]) Namespaces added in v0.0.591

func (ps *PubSub[TNamespace, TData]) Namespaces() []TNamespace

func (*PubSub[TNamespace, TData]) Publish added in v0.0.591

func (ps *PubSub[TNamespace, TData]) Publish(ns TNamespace, data TData) (subscriber int, actualReceiver int)

Publish sends `data` to all subscriber But unbuffered - if one is currently not listening, we skip (the actualReceiver < subscriber)

func (*PubSub[TNamespace, TData]) PublishWithContext added in v0.0.591

func (ps *PubSub[TNamespace, TData]) PublishWithContext(ctx context.Context, ns TNamespace, data TData) (subscriber int, actualReceiver int, err error)

PublishWithContext sends `data` to all subscriber buffered - if one is currently not listening, we wait (but error out when the context runs out)

func (*PubSub[TNamespace, TData]) PublishWithTimeout added in v0.0.591

func (ps *PubSub[TNamespace, TData]) PublishWithTimeout(ns TNamespace, data TData, timeout time.Duration) (subscriber int, actualReceiver int)

PublishWithTimeout sends `data` to all subscriber buffered - if one is currently not listening, we wait (but wait at most `timeout` - if the timeout is exceeded then actualReceiver < subscriber)

func (*PubSub[TNamespace, TData]) SubscribeByCallback added in v0.0.591

func (ps *PubSub[TNamespace, TData]) SubscribeByCallback(ns TNamespace, fn func(TData)) PubSubSubscription

func (*PubSub[TNamespace, TData]) SubscribeByChan added in v0.0.591

func (ps *PubSub[TNamespace, TData]) SubscribeByChan(ns TNamespace, chanBufferSize int) (chan TData, PubSubSubscription)

func (*PubSub[TNamespace, TData]) SubscribeByIter added in v0.0.591

func (ps *PubSub[TNamespace, TData]) SubscribeByIter(ns TNamespace, chanBufferSize int) (iter.Seq[TData], PubSubSubscription)

func (*PubSub[TNamespace, TData]) SubscriberCount added in v0.0.591

func (ps *PubSub[TNamespace, TData]) SubscriberCount(ns TNamespace) int

type PubSubSubscription added in v0.0.591

type PubSubSubscription interface {
	Unsubscribe()
}

type Quadruple

type Quadruple[T1 any, T2 any, T3 any, T4 any] struct {
	V1 T1
	V2 T2
	V3 T3
	V4 T4
}

func NewQuadruple

func NewQuadruple[T1 any, T2 any, T3 any, T4 any](v1 T1, v2 T2, v3 T3, v4 T4) Quadruple[T1, T2, T3, T4]

func NewTuple4

func NewTuple4[T1 any, T2 any, T3 any, T4 any](v1 T1, v2 T2, v3 T3, v4 T4) Quadruple[T1, T2, T3, T4]

func (Quadruple[T1, T2, T3, T4]) TupleLength

func (t Quadruple[T1, T2, T3, T4]) TupleLength() int

func (Quadruple[T1, T2, T3, T4]) TupleValues

func (t Quadruple[T1, T2, T3, T4]) TupleValues() []any

type Quintuple

type Quintuple[T1 any, T2 any, T3 any, T4 any, T5 any] struct {
	V1 T1
	V2 T2
	V3 T3
	V4 T4
	V5 T5
}

func NewQuintuple

func NewQuintuple[T1 any, T2 any, T3 any, T4 any, T5 any](v1 T1, v2 T2, v3 T3, v4 T4, v5 T5) Quintuple[T1, T2, T3, T4, T5]

func NewTuple5

func NewTuple5[T1 any, T2 any, T3 any, T4 any, T5 any](v1 T1, v2 T2, v3 T3, v4 T4, v5 T5) Quintuple[T1, T2, T3, T4, T5]

func (Quintuple[T1, T2, T3, T4, T5]) TupleLength

func (t Quintuple[T1, T2, T3, T4, T5]) TupleLength() int

func (Quintuple[T1, T2, T3, T4, T5]) TupleValues

func (t Quintuple[T1, T2, T3, T4, T5]) TupleValues() []any

type RingBuffer

type RingBuffer[T any] struct {
	// contains filtered or unexported fields
}

func NewRingBuffer

func NewRingBuffer[T any](capacity int) *RingBuffer[T]

func (*RingBuffer[T]) At

func (rb *RingBuffer[T]) At(i int) T

func (*RingBuffer[T]) Capacity

func (rb *RingBuffer[T]) Capacity() int

func (*RingBuffer[T]) Clear

func (rb *RingBuffer[T]) Clear()

func (*RingBuffer[T]) Get

func (rb *RingBuffer[T]) Get(i int) (T, bool)

func (*RingBuffer[T]) IsFull

func (rb *RingBuffer[T]) IsFull() bool

func (*RingBuffer[T]) Items

func (rb *RingBuffer[T]) Items() []T

func (*RingBuffer[T]) Iter

func (rb *RingBuffer[T]) Iter() iter.Seq[T]

func (*RingBuffer[T]) Iter2

func (rb *RingBuffer[T]) Iter2() iter.Seq2[int, T]

func (*RingBuffer[T]) Peek

func (rb *RingBuffer[T]) Peek() (T, bool)

func (*RingBuffer[T]) Push

func (rb *RingBuffer[T]) Push(item T)

func (*RingBuffer[T]) PushPop

func (rb *RingBuffer[T]) PushPop(item T) *T

func (*RingBuffer[T]) Remove

func (rb *RingBuffer[T]) Remove(fnEqual func(v T) bool) int

func (*RingBuffer[T]) Size

func (rb *RingBuffer[T]) Size() int

type Septuple

type Septuple[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any] struct {
	V1 T1
	V2 T2
	V3 T3
	V4 T4
	V5 T5
	V6 T6
	V7 T7
}

func NewSeptuple

func NewSeptuple[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any](v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, v7 T7) Septuple[T1, T2, T3, T4, T5, T6, T7]

func NewTuple7

func NewTuple7[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any](v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6, v7 T7) Septuple[T1, T2, T3, T4, T5, T6, T7]

func (Septuple[T1, T2, T3, T4, T5, T6, T7]) TupleLength

func (t Septuple[T1, T2, T3, T4, T5, T6, T7]) TupleLength() int

func (Septuple[T1, T2, T3, T4, T5, T6, T7]) TupleValues

func (t Septuple[T1, T2, T3, T4, T5, T6, T7]) TupleValues() []any

type Sextuple

type Sextuple[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any] struct {
	V1 T1
	V2 T2
	V3 T3
	V4 T4
	V5 T5
	V6 T6
}

func NewSextuple

func NewSextuple[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any](v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6) Sextuple[T1, T2, T3, T4, T5, T6]

func NewTuple6

func NewTuple6[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any](v1 T1, v2 T2, v3 T3, v4 T4, v5 T5, v6 T6) Sextuple[T1, T2, T3, T4, T5, T6]

func (Sextuple[T1, T2, T3, T4, T5, T6]) TupleLength

func (t Sextuple[T1, T2, T3, T4, T5, T6]) TupleLength() int

func (Sextuple[T1, T2, T3, T4, T5, T6]) TupleValues

func (t Sextuple[T1, T2, T3, T4, T5, T6]) TupleValues() []any

type Single

type Single[T1 any] struct {
	V1 T1
}

func NewSingle

func NewSingle[T1 any](v1 T1) Single[T1]

func NewTuple1

func NewTuple1[T1 any](v1 T1) Single[T1]

func (Single[T1]) TupleLength

func (s Single[T1]) TupleLength() int

func (Single[T1]) TupleValues

func (s Single[T1]) TupleValues() []any

type Stack

type Stack[T any] struct {
	// contains filtered or unexported fields
}

func NewStack

func NewStack[T any](threadsafe bool, initialCapacity int) *Stack[T]

func (*Stack[T]) Empty

func (s *Stack[T]) Empty() bool

func (*Stack[T]) Length

func (s *Stack[T]) Length() int

func (*Stack[T]) OptPeek

func (s *Stack[T]) OptPeek() *T

func (*Stack[T]) OptPop

func (s *Stack[T]) OptPop() *T

func (*Stack[T]) Peek

func (s *Stack[T]) Peek() (T, error)

func (*Stack[T]) Pop

func (s *Stack[T]) Pop() (T, error)

func (*Stack[T]) Push

func (s *Stack[T]) Push(v T)

type StructHashOptions

type StructHashOptions struct {
	HashAlgo    hash.Hash
	Tag         *string
	SkipChannel bool
	SkipFunc    bool
}

type SyncMap

type SyncMap[TKey comparable, TData any] struct {
	// contains filtered or unexported fields
}

SyncMap is a thread-safe map implementation for generic key-value pairs. All functions aresafe to be called in parallel.

func NewSyncMap

func NewSyncMap[TKey comparable, TData any]() *SyncMap[TKey, TData]

func (*SyncMap[TKey, TData]) Clear added in v0.0.574

func (s *SyncMap[TKey, TData]) Clear()

Clear removes all entries from the map.

func (*SyncMap[TKey, TData]) Contains

func (s *SyncMap[TKey, TData]) Contains(key TKey) bool

Contains checks if the map contains the provided key.

func (*SyncMap[TKey, TData]) Count added in v0.0.575

func (s *SyncMap[TKey, TData]) Count() int

Count returns the number of entries in the map.

func (*SyncMap[TKey, TData]) Delete

func (s *SyncMap[TKey, TData]) Delete(key TKey) bool

Delete removes the entry with the provided key and returns true if the key existed before.

func (*SyncMap[TKey, TData]) DeleteIf added in v0.0.575

func (s *SyncMap[TKey, TData]) DeleteIf(fn func(key TKey, data TData) bool) int

DeleteIf deletes all entries that match the provided function and returns the number of removed entries.

func (*SyncMap[TKey, TData]) Get

func (s *SyncMap[TKey, TData]) Get(key TKey) (TData, bool)

Get retrieves the value for the provided key

func (*SyncMap[TKey, TData]) GetAllKeys

func (s *SyncMap[TKey, TData]) GetAllKeys() []TKey

GetAllKeys returns a copy (!) of all keys in the map.

func (*SyncMap[TKey, TData]) GetAllValues

func (s *SyncMap[TKey, TData]) GetAllValues() []TData

GetAllValues returns a copy (!) of all values in the map.

func (*SyncMap[TKey, TData]) GetAndSetIfNotContains

func (s *SyncMap[TKey, TData]) GetAndSetIfNotContains(key TKey, data TData) TData

GetAndSetIfNotContains returns the existing value if the key exists. Otherwise, it sets the provided value and returns it.

func (*SyncMap[TKey, TData]) GetAndSetIfNotContainsFunc

func (s *SyncMap[TKey, TData]) GetAndSetIfNotContainsFunc(key TKey, data func() TData) TData

GetAndSetIfNotContainsFunc returns the existing value if the key exists. Otherwise, it calls the provided function to generate the value, sets it, and returns it.

func (*SyncMap[TKey, TData]) Set

func (s *SyncMap[TKey, TData]) Set(key TKey, data TData)

Set sets the value for the provided key

func (*SyncMap[TKey, TData]) SetIfNotContains

func (s *SyncMap[TKey, TData]) SetIfNotContains(key TKey, data TData) bool

SetIfNotContains sets the value for the provided key if it does not already exist

func (*SyncMap[TKey, TData]) SetIfNotContainsFunc

func (s *SyncMap[TKey, TData]) SetIfNotContainsFunc(key TKey, data func() TData) bool

SetIfNotContainsFunc sets the value for the provided key using the provided function

func (*SyncMap[TKey, TData]) UpdateIfExists added in v0.0.597

func (s *SyncMap[TKey, TData]) UpdateIfExists(key TKey, fn func(data TData) TData) bool

UpdateIfExists updates the value if the key exists, otherwise it does nothing.

func (*SyncMap[TKey, TData]) UpdateOrInsert added in v0.0.597

func (s *SyncMap[TKey, TData]) UpdateOrInsert(key TKey, fn func(data TData) TData, insertValue TData) bool

UpdateOrInsert updates the value if the key exists, otherwise it inserts the provided `insertValue`.

type SyncRingSet

type SyncRingSet[TData comparable] struct {
	// contains filtered or unexported fields
}

func NewSyncRingSet

func NewSyncRingSet[TData comparable](capacity int) *SyncRingSet[TData]

func (*SyncRingSet[TData]) Add

func (s *SyncRingSet[TData]) Add(value TData) bool

Add adds `value` to the set returns true if the value was actually inserted (value did not exist beforehand) returns false if the value already existed

func (*SyncRingSet[TData]) AddAll

func (s *SyncRingSet[TData]) AddAll(values []TData)

func (*SyncRingSet[TData]) AddIfNotContains

func (s *SyncRingSet[TData]) AddIfNotContains(key TData) bool

AddIfNotContains returns true if the value was actually added (value did not exist beforehand) returns false if the value already existed

func (*SyncRingSet[TData]) Contains

func (s *SyncRingSet[TData]) Contains(value TData) bool

func (*SyncRingSet[TData]) Get

func (s *SyncRingSet[TData]) Get() []TData

func (*SyncRingSet[TData]) Remove

func (s *SyncRingSet[TData]) Remove(value TData) bool

func (*SyncRingSet[TData]) RemoveAll

func (s *SyncRingSet[TData]) RemoveAll(values []TData)

func (*SyncRingSet[TData]) RemoveIfContains

func (s *SyncRingSet[TData]) RemoveIfContains(key TData) bool

RemoveIfContains returns true if the value was actually removed (value did exist beforehand) returns false if the value did not exist in the set

type SyncSet

type SyncSet[TData comparable] struct {
	// contains filtered or unexported fields
}

func NewSyncSet

func NewSyncSet[TData comparable]() *SyncSet[TData]

func (*SyncSet[TData]) Add

func (s *SyncSet[TData]) Add(value TData) bool

Add adds `value` to the set returns true if the value was actually inserted (value did not exist beforehand) returns false if the value already existed

func (*SyncSet[TData]) AddAll

func (s *SyncSet[TData]) AddAll(values []TData)

func (*SyncSet[TData]) AddIfNotContains

func (s *SyncSet[TData]) AddIfNotContains(key TData) bool

AddIfNotContains returns true if the value was actually added (value did not exist beforehand) returns false if the value already existed

func (*SyncSet[TData]) Contains

func (s *SyncSet[TData]) Contains(value TData) bool

func (*SyncSet[TData]) Get

func (s *SyncSet[TData]) Get() []TData

func (*SyncSet[TData]) Remove

func (s *SyncSet[TData]) Remove(value TData) bool

func (*SyncSet[TData]) RemoveAll

func (s *SyncSet[TData]) RemoveAll(values []TData)

func (*SyncSet[TData]) RemoveIfContains

func (s *SyncSet[TData]) RemoveIfContains(key TData) bool

RemoveIfContains returns true if the value was actually removed (value did exist beforehand) returns false if the value did not exist in the set

type Triple

type Triple[T1 any, T2 any, T3 any] struct {
	V1 T1
	V2 T2
	V3 T3
}

func NewTriple

func NewTriple[T1 any, T2 any, T3 any](v1 T1, v2 T2, v3 T3) Triple[T1, T2, T3]

func NewTuple3

func NewTuple3[T1 any, T2 any, T3 any](v1 T1, v2 T2, v3 T3) Triple[T1, T2, T3]

func (Triple[T1, T2, T3]) TupleLength

func (t Triple[T1, T2, T3]) TupleLength() int

func (Triple[T1, T2, T3]) TupleValues

func (t Triple[T1, T2, T3]) TupleValues() []any

type Tuple

type Tuple[T1 any, T2 any] struct {
	V1 T1
	V2 T2
}

func NewTuple

func NewTuple[T1 any, T2 any](v1 T1, v2 T2) Tuple[T1, T2]

func NewTuple2

func NewTuple2[T1 any, T2 any](v1 T1, v2 T2) Tuple[T1, T2]

func (Tuple[T1, T2]) TupleLength

func (t Tuple[T1, T2]) TupleLength() int

func (Tuple[T1, T2]) TupleValues

func (t Tuple[T1, T2]) TupleValues() []any

type ValueGroup

type ValueGroup interface {
	TupleLength() int
	TupleValues() []any
}

Jump to

Keyboard shortcuts

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