concurrent

package
v1.0.14 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GenericSyncMap

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

GenericSyncMap 是一个使用 sync.Map 封装的泛型 Map

func NewGenericSyncMap

func NewGenericSyncMap[K comparable, V any]() *GenericSyncMap[K, V]

func NewGenericSyncMapFromMap

func NewGenericSyncMapFromMap[K comparable, V any](m map[K]V) *GenericSyncMap[K, V]

func (*GenericSyncMap[K, V]) Delete

func (gm *GenericSyncMap[K, V]) Delete(key K)

Delete 方法从 Map 中删除键值对

func (*GenericSyncMap[K, V]) Get

func (gm *GenericSyncMap[K, V]) Get(key K) (V, bool)

Get 方法从 Map 中检索值

func (*GenericSyncMap[K, V]) GetOr

func (gm *GenericSyncMap[K, V]) GetOr(k K, dV V) (v V)

func (*GenericSyncMap[K, V]) GetOrElse

func (gm *GenericSyncMap[K, V]) GetOrElse(k K, fn func() V) (v V)

func (*GenericSyncMap[K, V]) Keys

func (gm *GenericSyncMap[K, V]) Keys() []K

Keys 方法返回 Map 中的所有键

func (*GenericSyncMap[K, V]) Range

func (gm *GenericSyncMap[K, V]) Range(f func(key K, value V) bool)

Range 方法遍历 Map 中的所有键值对

func (*GenericSyncMap[K, V]) Set

func (gm *GenericSyncMap[K, V]) Set(key K, value V)

Set 方法将键值对添加到 Map 中

func (*GenericSyncMap[K, V]) Values

func (gm *GenericSyncMap[K, V]) Values() []V

Values 方法返回 Map 中的所有值

type SafeMap

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

SafeMap 使用分片锁的线程安全map

func NewSafeMap

func NewSafeMap[K comparable, V any](shardCount int) *SafeMap[K, V]

NewSafeMap 创建一个带有指定分片数量的线程安全map

func NewSafeMapFromMap

func NewSafeMapFromMap[K comparable, V any](m map[K]V, shardCount int) *SafeMap[K, V]

NewSafeMapFromMap 将普通map转换为ConcurrentMap

func (*SafeMap[K, V]) Clear

func (m *SafeMap[K, V]) Clear()

Clear 清空map

func (*SafeMap[K, V]) Delete

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

Delete 删除键对应的值

func (*SafeMap[K, V]) ForEach

func (m *SafeMap[K, V]) ForEach(fn func(K, V) bool)

ForEach 遍历map中的所有键值对

func (*SafeMap[K, V]) Get

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

Get 获取键对应的值,不存在时返回nil

func (*SafeMap[K, V]) GetOr

func (m *SafeMap[K, V]) GetOr(key K, dV V) V

GetOr 获取键对应的值,不存在时返回给定的默认值

func (*SafeMap[K, V]) GetOrElse

func (m *SafeMap[K, V]) GetOrElse(key K, fn func() V) V

GetOrElse 获取键对应的值,不存在时调用给定的函数并返回其结果

func (*SafeMap[K, V]) Keys

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

Keys 返回map中的所有键

func (*SafeMap[K, V]) Length

func (m *SafeMap[K, V]) Length() int

Length 返回map中的元素数量

func (*SafeMap[K, V]) Set

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

Set 设置键值对

func (*SafeMap[K, V]) Values

func (m *SafeMap[K, V]) Values() []V

Values 返回map中的所有值

Jump to

Keyboard shortcuts

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