mapx

package
v0.0.0-...-d3b5644 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendValue

func AppendValue[M ~map[K]V, R ~map[K]S, S ~[]V, K comparable, V any](r R, ms ...M) R

func FromMapRange

func FromMapRange[M ~map[K]V, K comparable, V any](mi MapInterface) M

func IsEmpty

func IsEmpty[M ~map[K]V, K comparable, V any](m M) bool

func IsNotEmpty

func IsNotEmpty[M ~map[K]V, K comparable, V any](m M) bool

func KeySet

func KeySet[M ~map[K]V, R map[K]struct{}, K comparable, V any](m M) R

Types

type DeepCopyMap

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

DeepCopyMap is an implementation of mapInterface using a Mutex and atomic.Value. It makes deep copies of the map on every write to avoid acquiring the Mutex in Load.

func (*DeepCopyMap) CompareAndDelete

func (m *DeepCopyMap) CompareAndDelete(key, old any) (deleted bool)

func (*DeepCopyMap) CompareAndSwap

func (m *DeepCopyMap) CompareAndSwap(key, old, new any) (swapped bool)

func (*DeepCopyMap) Delete

func (m *DeepCopyMap) Delete(key any)

func (*DeepCopyMap) Load

func (m *DeepCopyMap) Load(key any) (value any, loaded bool)

func (*DeepCopyMap) LoadAndDelete

func (m *DeepCopyMap) LoadAndDelete(key any) (value any, loaded bool)

func (*DeepCopyMap) LoadOrStore

func (m *DeepCopyMap) LoadOrStore(key, value any) (actual any, loaded bool)

func (*DeepCopyMap) Range

func (m *DeepCopyMap) Range(f func(key, value any) (shouldContinue bool))

func (*DeepCopyMap) Store

func (m *DeepCopyMap) Store(key, value any)

func (*DeepCopyMap) Swap

func (m *DeepCopyMap) Swap(key, value any) (previous any, loaded bool)

type Entry

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

func Entries

func Entries[M ~map[K]V, K comparable, V any](m M) []Entry[K, V]

type ExpiredMap

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

func NewExpiredMap

func NewExpiredMap(options ...ExpiredMapOption) *ExpiredMap

func (*ExpiredMap) CompareAndDelete

func (c *ExpiredMap) CompareAndDelete(key, oldValue any) bool

func (*ExpiredMap) CompareAndSwap

func (c *ExpiredMap) CompareAndSwap(key, oldValue, newValue any) bool

func (*ExpiredMap) Delete

func (c *ExpiredMap) Delete(key any)

func (*ExpiredMap) Load

func (c *ExpiredMap) Load(key any) (any, bool)

func (*ExpiredMap) LoadAndDelete

func (c *ExpiredMap) LoadAndDelete(key any) (any, bool)

func (*ExpiredMap) LoadOrStore

func (c *ExpiredMap) LoadOrStore(key, value any) (any, bool)

func (*ExpiredMap) Range

func (c *ExpiredMap) Range(f func(key any, value any) bool)

func (*ExpiredMap) Store

func (c *ExpiredMap) Store(key, value any)

func (*ExpiredMap) Swap

func (c *ExpiredMap) Swap(key, value any) (any, bool)

type ExpiredMapOption

type ExpiredMapOption func(*ExpiredMap)

func CleanupInterval

func CleanupInterval(interval time.Duration) ExpiredMapOption

func ExpireAfter

func ExpireAfter(f func(key any) time.Duration) ExpiredMapOption

func OnEvicted

func OnEvicted(f func(any, any)) ExpiredMapOption

type GenericMap

type GenericMap[K comparable, V any] struct {
	MapInterface MapInterface
}

func (*GenericMap[K, V]) CompareAndDelete

func (m *GenericMap[K, V]) CompareAndDelete(key K, old V) bool

func (*GenericMap[K, V]) CompareAndSwap

func (m *GenericMap[K, V]) CompareAndSwap(key K, old, new V) bool

func (*GenericMap[K, V]) Delete

func (m *GenericMap[K, V]) Delete(key K)

func (*GenericMap[K, V]) Load

func (m *GenericMap[K, V]) Load(key K) (V, bool)

func (*GenericMap[K, V]) LoadAndDelete

func (m *GenericMap[K, V]) LoadAndDelete(key K) (V, bool)

func (*GenericMap[K, V]) LoadOrStore

func (m *GenericMap[K, V]) LoadOrStore(key K, value V) (V, bool)

func (*GenericMap[K, V]) Range

func (m *GenericMap[K, V]) Range(f func(key K, value V) bool)

func (*GenericMap[K, V]) Store

func (m *GenericMap[K, V]) Store(key K, value V)

func (*GenericMap[K, V]) Swap

func (m *GenericMap[K, V]) Swap(key K, value V) (V, bool)

type MapInterface

type MapInterface interface {
	Load(key any) (value any, loaded bool)
	Store(key, value any)
	LoadOrStore(key, value any) (actual any, loaded bool)
	LoadAndDelete(key any) (value any, loaded bool)
	Delete(key any)
	Swap(key, value any) (previous any, loaded bool)
	CompareAndSwap(key, old, new any) (swapped bool)
	CompareAndDelete(key, old any) (deleted bool)
	Range(func(key, value any) (shouldContinue bool))
}

MapInterface is the interface map implements. copy from sync/map_reference_test.go

type OrderedMap

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

func NewOrderedMap

func NewOrderedMap() *OrderedMap

func (*OrderedMap) Back

func (m *OrderedMap) Back() *list.Element

func (*OrderedMap) CompareAndDelete

func (m *OrderedMap) CompareAndDelete(key, old any) (deleted bool)

func (*OrderedMap) CompareAndSwap

func (m *OrderedMap) CompareAndSwap(key, old, new any) (swapped bool)

func (*OrderedMap) Delete

func (m *OrderedMap) Delete(key any)

func (*OrderedMap) Front

func (m *OrderedMap) Front() *list.Element

func (*OrderedMap) Load

func (m *OrderedMap) Load(key any) (value any, loaded bool)

func (*OrderedMap) LoadAndDelete

func (m *OrderedMap) LoadAndDelete(key any) (value any, loaded bool)

func (*OrderedMap) LoadOrStore

func (m *OrderedMap) LoadOrStore(key, value any) (actual any, loaded bool)

func (*OrderedMap) Range

func (m *OrderedMap) Range(f func(key any, value any) (shouldContinue bool))

func (*OrderedMap) Store

func (m *OrderedMap) Store(key, value any)

func (*OrderedMap) Swap

func (m *OrderedMap) Swap(key, value any) (previous any, loaded bool)

type RWMutexMap

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

RWMutexMap is an implementation of mapInterface using a sync.RWMutex.

func (*RWMutexMap) CompareAndDelete

func (m *RWMutexMap) CompareAndDelete(key, old any) (deleted bool)

func (*RWMutexMap) CompareAndSwap

func (m *RWMutexMap) CompareAndSwap(key, old, new any) (swapped bool)

func (*RWMutexMap) Delete

func (m *RWMutexMap) Delete(key any)

func (*RWMutexMap) Load

func (m *RWMutexMap) Load(key any) (value any, loaded bool)

func (*RWMutexMap) LoadAndDelete

func (m *RWMutexMap) LoadAndDelete(key any) (value any, loaded bool)

func (*RWMutexMap) LoadOrStore

func (m *RWMutexMap) LoadOrStore(key, value any) (actual any, loaded bool)

func (*RWMutexMap) Range

func (m *RWMutexMap) Range(f func(key, value any) (shouldContinue bool))

func (*RWMutexMap) Store

func (m *RWMutexMap) Store(key, value any)

func (*RWMutexMap) Swap

func (m *RWMutexMap) Swap(key, value any) (previous any, loaded bool)

type ShardedMap

type ShardedMap struct {
	Segments []MapInterface
	Hash     func(key any) int
}

func (*ShardedMap) CompareAndDelete

func (m *ShardedMap) CompareAndDelete(key, old any) (deleted bool)

func (*ShardedMap) CompareAndSwap

func (m *ShardedMap) CompareAndSwap(key, old, new any) (swapped bool)

func (*ShardedMap) Delete

func (m *ShardedMap) Delete(key any)

func (*ShardedMap) Load

func (m *ShardedMap) Load(key any) (value any, loaded bool)

func (*ShardedMap) LoadAndDelete

func (m *ShardedMap) LoadAndDelete(key any) (value any, loaded bool)

func (*ShardedMap) LoadOrStore

func (m *ShardedMap) LoadOrStore(key, value any) (actual any, loaded bool)

func (*ShardedMap) Range

func (m *ShardedMap) Range(f func(key any, value any) (shouldContinue bool))

func (*ShardedMap) Store

func (m *ShardedMap) Store(key, value any)

func (*ShardedMap) Swap

func (m *ShardedMap) Swap(key, value any) (previous any, loaded bool)

Jump to

Keyboard shortcuts

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