mappings

package
v0.5.7 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 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 SyncMap

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

SyncMap 是基于 sync.RWMutex 实现的线程安全的 map

  • 适用于要考虑并发读写但是并发读写的频率不高的情况

func NewSyncMap

func NewSyncMap[K comparable, V any](source ...map[K]V) *SyncMap[K, V]

NewSyncMap 创建一个 SyncMap

func (*SyncMap[K, V]) Atom

func (sm *SyncMap[K, V]) Atom(handle func(m map[K]V))

Atom 原子操作

func (*SyncMap[K, V]) Clear

func (sm *SyncMap[K, V]) Clear()

Clear 清空

func (*SyncMap[K, V]) ClearHandle

func (sm *SyncMap[K, V]) ClearHandle(handle func(key K, value V))

ClearHandle 清空并处理

func (*SyncMap[K, V]) Delete

func (sm *SyncMap[K, V]) Delete(key K)

Delete 删除一个值

func (*SyncMap[K, V]) DeleteExist

func (sm *SyncMap[K, V]) DeleteExist(key K) bool

DeleteExist 删除一个值并返回是否存在

func (*SyncMap[K, V]) DeleteGet

func (sm *SyncMap[K, V]) DeleteGet(key K) V

DeleteGet 删除一个值并返回

func (*SyncMap[K, V]) DeleteGetExist

func (sm *SyncMap[K, V]) DeleteGetExist(key K) (V, bool)

DeleteGetExist 删除一个值并返回是否存在

func (*SyncMap[K, V]) Exist

func (sm *SyncMap[K, V]) Exist(key K) bool

Exist 判断是否存在

func (*SyncMap[K, V]) Get

func (sm *SyncMap[K, V]) Get(key K) V

Get 获取一个值

func (*SyncMap[K, V]) GetExist

func (sm *SyncMap[K, V]) GetExist(key K) (V, bool)

GetExist 获取一个值并判断是否存在

func (*SyncMap[K, V]) Keys

func (sm *SyncMap[K, V]) Keys() []K

Keys 获取所有的键

func (*SyncMap[K, V]) Map

func (sm *SyncMap[K, V]) Map() map[K]V

Map 转换为普通 map

func (*SyncMap[K, V]) MarshalJSON

func (sm *SyncMap[K, V]) MarshalJSON() ([]byte, error)

func (*SyncMap[K, V]) Range

func (sm *SyncMap[K, V]) Range(handle func(key K, value V) bool)

Range 遍历所有值,如果 handle 返回 true 则停止遍历

func (*SyncMap[K, V]) Set

func (sm *SyncMap[K, V]) Set(key K, value V)

Set 设置一个值

func (*SyncMap[K, V]) Size

func (sm *SyncMap[K, V]) Size() int

Size 获取数量

func (*SyncMap[K, V]) Slice

func (sm *SyncMap[K, V]) Slice() []V

Slice 获取所有的值

func (*SyncMap[K, V]) UnmarshalJSON

func (sm *SyncMap[K, V]) UnmarshalJSON(bytes []byte) error

Jump to

Keyboard shortcuts

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