gomap

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DelFunc

type DelFunc[K any, V any] func(key K, v V, exist bool) bool

DelFunc 删除key执行的func,返回true证明删除成功 key: 需要删除的key v: 被删除key对应的value exist: key是否存在

type LockMap

type LockMap[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func NewLockMap

func NewLockMap[K comparable, V any]() *LockMap[K, V]

func (*LockMap[K, V]) Del

func (m *LockMap[K, V]) Del(key K)

func (*LockMap[K, V]) Get

func (m *LockMap[K, V]) Get(key K) (value V, exist bool)

func (*LockMap[K, V]) GetSet

func (m *LockMap[K, V]) GetSet(key K, value V) (oldValue V, exist bool)

func (*LockMap[K, V]) Len

func (m *LockMap[K, V]) Len() (n int)

func (*LockMap[K, V]) SafeRange

func (m *LockMap[K, V]) SafeRange(f func(key K, value V) bool)

func (*LockMap[K, V]) Set

func (m *LockMap[K, V]) Set(key K, value V)

func (*LockMap[K, V]) SetNX

func (m *LockMap[K, V]) SetNX(key K, value V)

func (*LockMap[K, V]) UnsafeDel

func (m *LockMap[K, V]) UnsafeDel(key K)

func (*LockMap[K, V]) UnsafeGet

func (m *LockMap[K, V]) UnsafeGet(key K) (value V, exist bool)

func (*LockMap[K, V]) UnsafeGetSet

func (m *LockMap[K, V]) UnsafeGetSet(key K, value V) (oldValue V, exist bool)

func (*LockMap[K, V]) UnsafeLen

func (m *LockMap[K, V]) UnsafeLen() int

func (*LockMap[K, V]) UnsafeRange

func (m *LockMap[K, V]) UnsafeRange(f func(key K, value V) bool)

func (*LockMap[K, V]) UnsafeSet

func (m *LockMap[K, V]) UnsafeSet(key K, value V)

func (*LockMap[K, V]) UnsafeSetNX

func (m *LockMap[K, V]) UnsafeSetNX(key K, value V)

type Map

type Map[K comparable, V any] struct {
	// contains filtered or unexported fields
}

func NewMap

func NewMap[K comparable, V any]() *Map[K, V]

func (*Map[K, V]) Del

func (m *Map[K, V]) Del(key K)

func (*Map[K, V]) Get

func (m *Map[K, V]) Get(key K) (value V, exist bool)

func (*Map[K, V]) GetSet

func (m *Map[K, V]) GetSet(key K, value V) (oldValue V, exist bool)

func (*Map[K, V]) Len

func (m *Map[K, V]) Len() int

func (*Map[K, V]) Range

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

func (*Map[K, V]) Set

func (m *Map[K, V]) Set(key K, value V)

func (*Map[K, V]) SetNX

func (m *Map[K, V]) SetNX(key K, value V)

type RangeFunc

type RangeFunc[K comparable, V any] func(key K, value V) bool

RangeFunc map迭代器,返回false则终止遍历

type ShardMap

type ShardMap[K comparable, V any] struct {
	// contains filtered or unexported fields
}

ShardMap 线程安全的map[comparable, any],为了避免锁带来的性能瓶颈,将map进行了分片

func NewShardMap

func NewShardMap[V any](shardSize int) *ShardMap[string, V]

func NewShardMapWithStringer

func NewShardMapWithStringer[K Stringer, V any](shardSize int) *ShardMap[K, V]

func (*ShardMap[K, V]) Clean

func (m *ShardMap[K, V]) Clean()

Clean 清除所有key&value

func (*ShardMap[K, V]) Del

func (m *ShardMap[K, V]) Del(key K)

func (*ShardMap[K, V]) DelWithFunc

func (m *ShardMap[K, V]) DelWithFunc(key K, fn DelFunc[K, V]) bool

func (*ShardMap[K, V]) Exists

func (m *ShardMap[K, V]) Exists(key K) bool

func (*ShardMap[K, V]) Get

func (m *ShardMap[K, V]) Get(key K) (V, bool)

func (*ShardMap[K, V]) GetShard

func (m *ShardMap[K, V]) GetShard(key K) *ShardUnit[K, V]

GetShard returns shard under given key

func (*ShardMap[K, V]) IterBuffered

func (m *ShardMap[K, V]) IterBuffered() <-chan Tuple[K, V]

IterBuffered returns a buffered iterator which could be used in a for range loop.

func (*ShardMap[K, V]) Keys

func (m *ShardMap[K, V]) Keys() []K

func (*ShardMap[K, V]) Len

func (m *ShardMap[K, V]) Len() int

func (*ShardMap[K, V]) MSet

func (m *ShardMap[K, V]) MSet(data map[K]V)

func (*ShardMap[K, V]) MarshalJSON

func (m *ShardMap[K, V]) MarshalJSON() ([]byte, error)

MarshalJSON JSON序列化

func (*ShardMap[K, V]) Pop

func (m *ShardMap[K, V]) Pop(key K) (v V, exists bool)

Pop removes an element from the map and returns it

func (*ShardMap[K, V]) Range

func (m *ShardMap[K, V]) Range(f RangeFunc[K, V])

func (*ShardMap[K, V]) Set

func (m *ShardMap[K, V]) Set(key K, value V)

func (*ShardMap[K, V]) SetNX

func (m *ShardMap[K, V]) SetNX(key K, value V) bool

SetNX 仅当key不存在时才set

func (*ShardMap[K, V]) UnmarshalJSON

func (m *ShardMap[K, V]) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON JSON反序列化 先反序列化进一个map中,然后一次set进ShardMap

func (*ShardMap[K, V]) Upsert

func (m *ShardMap[K, V]) Upsert(key K, value V, fn UpsertFunc[V]) (res V)

Upsert 通过UpdateCb更新既有的key或者新插入key

type ShardUnit

type ShardUnit[K comparable, V any] struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

ShardUnit 线程安全的map[string]any

type Stringer

type Stringer interface {
	fmt.Stringer
	comparable
}

type Tuple

type Tuple[K comparable, V any] struct {
	Key K
	Val V
}

Tuple Used by the Iter & IterBuffered functions to wrap two variables together over a channel,

type UpsertFunc

type UpsertFunc[V any] func(exist bool, oldValue V, updateValue V) V

UpsertFunc 更新或者插入新key的func exist: 表示需要更新或者插入的key是否存在 oldValue: 如果key存在,表示其既有的值 updateValue: 需要更新(或插入)的新值

Jump to

Keyboard shortcuts

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