syncx

package
v0.11.14 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2024 License: Apache-2.0 Imports: 4 Imported by: 2

Documentation

Overview

* @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.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyMeta

func CopyMeta(src, dst map[string]string)

CopyMeta 复制 src 中的所有键值对到 dst 中。 如果 dst 为 nil,则不进行任何操作。

func MetaMapToString

func MetaMapToString(meta map[string]string) string

MetaMapToString 将 map 转换为 meta 字符串

func MetaStringToMap

func MetaStringToMap(meta string) map[string]string

MetaStringToMap 将 meta 字符串转换为键值对的 map

Types

type Map

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

Map 是一个线程安全的映射,使用泛型 K 和 V。

func NewMap

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

NewMap 创建一个新的 Map 实例。

func (*Map[K, V]) Clear added in v0.11.6

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

Clear 清空 Map 中的所有键值对

func (*Map[K, V]) CompareAndDelete

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

CompareAndDelete 比较指定键的值,如果相等则删除该键的值。

func (*Map[K, V]) CompareAndSwap

func (m *Map[K, V]) CompareAndSwap(key K, old, new V) bool

CompareAndSwap 比较指定键的现有值,如果相等则将其替换为新值。

func (*Map[K, V]) Delete

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

Delete 删除指定键的值。

func (*Map[K, V]) Equals

func (m *Map[K, V]) Equals(key K, value V, cmpFunc func(existing V) bool) bool

Equals 函数用于比较两个键值对是否相等, 需要用户提供自定义的比较函数。

func (*Map[K, V]) Keys added in v0.11.6

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

Keys 返回所有键的切片

func (*Map[K, V]) Load

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

Load 获取指定键的值。

func (*Map[K, V]) LoadAndDelete

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

LoadAndDelete 方法从 Map 中加载并删除指定键的值

func (*Map[K, V]) LoadOrStore

func (m *Map[K, V]) LoadOrStore(key K, new V) (V, bool)

LoadOrStore 获取指定键的值,如果不存在则存储新值。

func (*Map[K, V]) Range

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

Range 遍历 Map 中的所有键值对。

func (*Map[K, V]) Size added in v0.11.6

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

Size 返回当前 Map 中元素的数量

func (*Map[K, V]) Store

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

Store 设置指定键的值。

func (*Map[K, V]) Swap

func (m *Map[K, V]) Swap(key K, value V) (pre V, ok bool)

Swap 替换指定键的值,并返回之前的值。

func (*Map[K, V]) Values added in v0.11.6

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

Values 返回所有值的切片

type Set added in v0.11.6

type Set[K comparable] struct {
	// contains filtered or unexported fields
}

Set 是一个线程安全的集合,使用 Map 实现。

func NewSet added in v0.11.6

func NewSet[K comparable]() *Set[K]

NewSet 创建一个新的 Set 实例。

func (*Set[K]) Add added in v0.11.6

func (s *Set[K]) Add(key K)

Add 向集合中添加一个元素。

func (*Set[K]) AddAll added in v0.11.6

func (s *Set[K]) AddAll(keys ...K)

AddAll 向集合中添加多个元素。

func (*Set[K]) Clear added in v0.11.6

func (s *Set[K]) Clear()

Clear 清空集合中的所有元素。

func (*Set[K]) Delete added in v0.11.6

func (s *Set[K]) Delete(key K)

Delete 从集合中删除指定的元素。

func (*Set[K]) DeleteAll added in v0.11.6

func (s *Set[K]) DeleteAll(keys ...K)

DeleteAll 从集合中删除多个元素。

func (*Set[K]) Elements added in v0.11.6

func (s *Set[K]) Elements() []K

Elements 返回集合中的所有元素。

func (*Set[K]) Has added in v0.11.6

func (s *Set[K]) Has(key K) bool

Has 检查集合中是否存在指定的元素。

func (*Set[K]) HasAll added in v0.11.6

func (s *Set[K]) HasAll(keys ...K) (existing []K, all bool)

HasAll 检查集合中是否包含所有指定的元素。

func (*Set[K]) IsEmpty added in v0.11.6

func (s *Set[K]) IsEmpty() bool

IsEmpty 检查集合是否为空。

func (*Set[K]) Size added in v0.11.6

func (s *Set[K]) Size() int

Size 返回集合中元素的数量。

Jump to

Keyboard shortcuts

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