maps

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: May 23, 2025 License: MIT Imports: 3 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	SHARD_COUNT         uint32 = 32               // 只能在NewConcurrentMap之前修改
	AUTO_CLEAR_INTERVAL        = 10 * time.Minute // 可修改
)

Functions

func EnableExpired

func EnableExpired(ttl time.Duration) func(option *Option)

启用过期时间

Types

type ConcurrentMap

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

分成SHARD_COUNT个分片的map

func NewConcurrentMap

func NewConcurrentMap[T any](options ...func(option *Option)) *ConcurrentMap[T]

创建并发map

func (*ConcurrentMap[T]) Delete

func (m *ConcurrentMap[T]) Delete(key string)

func (*ConcurrentMap[T]) Get

func (m *ConcurrentMap[T]) Get(key string) (value T, ok bool)

func (*ConcurrentMap[T]) GetShard

func (m *ConcurrentMap[T]) GetShard(key string) uint32

根据key计算分片索引

func (*ConcurrentMap[T]) Set

func (m *ConcurrentMap[T]) Set(key string, value T, ttl ...time.Duration)

func (*ConcurrentMap[T]) SetByFunc

func (m *ConcurrentMap[T]) SetByFunc(key string, newValueFunc func(oldValue T) (newValue T), ttl ...time.Duration) (newValue T)

type Option

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

type RWMutexMap

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

通过RWMutex保护的线程安全的分片,包含一个map

func (*RWMutexMap[T]) Clear

func (s *RWMutexMap[T]) Clear()

清理过期的值

func (*RWMutexMap[T]) Delete

func (s *RWMutexMap[T]) Delete(key string)

func (*RWMutexMap[T]) Get

func (s *RWMutexMap[T]) Get(key string) (val T, ok bool)

func (*RWMutexMap[T]) Set

func (s *RWMutexMap[T]) Set(key string, value T, ttl ...time.Duration)

func (*RWMutexMap[T]) SetByFunc

func (s *RWMutexMap[T]) SetByFunc(key string, newValueFunc func(oldValue T) (newValue T), ttl ...time.Duration) (newValue T)

Jump to

Keyboard shortcuts

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