Documentation
¶
Overview ¶
* @Author: kamalyes 501893067@qq.com * @Date: 2025-01-05 15:27:15 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2025-01-05 15:27:15 * @FilePath: \go-toolbox\pkg\syncx\clone.go * @Description: * * Copyright (c) 2025 by kamalyes, All Rights Reserved.
* @Author: kamalyes 501893067@qq.com * @Date: 2024-12-13 13:05:03 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2025-01-08 15:15:59 * @FilePath: \go-toolbox\pkg\syncx\lock.go * @Description: * * Copyright (c) 2024 by kamalyes, All Rights Reserved.
* @Author: kamalyes 501893067@qq.com * @Date: 2023-07-28 00:50:58 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2024-11-11 13:08:58 * @FilePath: \go-toolbox\pkg\syncx\map.go * @Description: * * Copyright (c) 2024 by kamalyes, All Rights Reserved.
* @Author: kamalyes 501893067@qq.com * @Date: 2024-11-09 01:15:05 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2024-11-11 13:08:58 * @FilePath: \go-toolbox\pkg\syncx\set.go * @Description: * * Copyright (c) 2024 by kamalyes, All Rights Reserved.
* @Author: kamalyes 501893067@qq.com * @Date: 2025-01-08 13:55:22 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2025-01-08 13:55:22 * @FilePath: \go-toolbox\pkg\syncx\wg.go * @Description: 自定义的 WaitGroup 结构体,封装了 sync.WaitGroup,用于管理并发操作的等待。 * * Copyright (c) 2024 by kamalyes, All Rights Reserved.
Index ¶
- func CopyMeta(src, dst map[string]string)
- func DeepCopy(dst, src interface{}) error
- func MetaMapToString(meta map[string]string) string
- func MetaStringToMap(meta string) map[string]string
- func WithLock(lock Locker, operation func())
- func WithLockReturn[T any](lock Locker, operation func() (T, error)) (T, error)
- func WithRLock(lock RLocker, operation func())
- func WithRLockReturn[T any](lock RLocker, operation func() (T, error)) (T, error)
- type Locker
- type Map
- func (m *Map[K, V]) Clear()
- func (m *Map[K, V]) Clone() *Map[K, V]
- func (m *Map[K, V]) CompareAndDelete(key K, value V) bool
- func (m *Map[K, V]) CompareAndSwap(key K, old, new V) bool
- func (m *Map[K, V]) Delete(key K)
- func (m *Map[K, V]) Equals(key K, value V, cmpFunc func(existing V) bool) bool
- func (m *Map[K, V]) Keys() []K
- func (m *Map[K, V]) Load(key K) (V, bool)
- func (m *Map[K, V]) LoadAndDelete(key K) (V, bool)
- func (m *Map[K, V]) LoadOrStore(key K, new V) (V, bool)
- func (m *Map[K, V]) Range(run func(key K, value V) bool)
- func (m *Map[K, V]) Size() int
- func (m *Map[K, V]) Store(key K, value V)
- func (m *Map[K, V]) Swap(key K, value V) (pre V, ok bool)
- func (m *Map[K, V]) Values() []V
- type RLocker
- type Set
- func (s *Set[K]) Add(key K)
- func (s *Set[K]) AddAll(keys ...K)
- func (s *Set[K]) Clear()
- func (s *Set[K]) Delete(key K)
- func (s *Set[K]) DeleteAll(keys ...K)
- func (s *Set[K]) Elements() []K
- func (s *Set[K]) Has(key K) bool
- func (s *Set[K]) HasAll(keys ...K) (existing []K, all bool)
- func (s *Set[K]) IsEmpty() bool
- func (s *Set[K]) Size() int
- type WaitGroupWithMutex
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeepCopy ¶ added in v0.11.27
func DeepCopy(dst, src interface{}) error
DeepCopy 复制源值到目标值
@params dst: 目标值的指针,表示要将源值复制到的位置。必须是一个指向某种类型的指针。 @params src: 源值的指针,表示要复制的原始数据。也必须是一个指向某种类型的指针。
@return:
如果成功,返回 nil;如果源值为 nil,返回一个错误。
func MetaMapToString ¶
MetaMapToString 将 map 转换为 meta 字符串
func MetaStringToMap ¶
MetaStringToMap 将 meta 字符串转换为键值对的 map
func WithLock ¶ added in v0.11.20
func WithLock(lock Locker, operation func())
WithLock 是一个通用的函数,用于在给定的锁上执行操作
func WithLockReturn ¶ added in v0.11.23
WithLockReturn 是一个支持返回值的函数,用于在给定的锁上执行操作
Types ¶
type Map ¶
type Map[K comparable, V any] struct { // contains filtered or unexported fields }
Map 是一个线程安全的映射,使用泛型 K 和 V。
func (*Map[K, V]) CompareAndDelete ¶
CompareAndDelete 比较指定键的值,如果相等则删除该键的值。
func (*Map[K, V]) CompareAndSwap ¶
CompareAndSwap 比较指定键的现有值,如果相等则将其替换为新值。
func (*Map[K, V]) LoadAndDelete ¶
LoadAndDelete 方法从 Map 中加载并删除指定键的值
func (*Map[K, V]) LoadOrStore ¶
LoadOrStore 获取指定键的值,如果不存在则存储新值。
type RLocker ¶ added in v0.11.28
type RLocker interface { RLock() RUnlock() }
RLocker 是一个接口,定义了读锁和解锁的方法
type Set ¶ added in v0.11.6
type Set[K comparable] struct { // contains filtered or unexported fields }
Set 是一个线程安全的集合,使用 Map 实现。
func (*Set[K]) DeleteAll ¶ added in v0.11.6
func (s *Set[K]) DeleteAll(keys ...K)
DeleteAll 从集合中删除多个元素。
type WaitGroupWithMutex ¶ added in v0.11.28
type WaitGroupWithMutex struct {
// contains filtered or unexported fields
}
WaitGroupWithMutex 结构体封装了 sync.WaitGroup
func (*WaitGroupWithMutex) Add ¶ added in v0.11.28
func (w *WaitGroupWithMutex) Add(delta int)
Add 方法增加等待组的计数
func (*WaitGroupWithMutex) Done ¶ added in v0.11.28
func (w *WaitGroupWithMutex) Done()
Done 方法减少等待组的计数
func (*WaitGroupWithMutex) Wait ¶ added in v0.11.28
func (w *WaitGroupWithMutex) Wait()
Wait 方法阻塞直到等待组计数为零