kmaps

package
v0.4.13 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clear

func Clear[K comparable, V any](m AnyMap[K, V])

清除 map中的所有元素

func Copy

func Copy[K comparable, V any](dst AnyMap[K, V], src AnyMap[K, V])

func DeleteFunc

func DeleteFunc[K comparable, V any](m AnyMap[K, V], del func(K, V) bool)

DeleteFunc deletes any key/value pairs from m for which del returns true.

func Equal

func Equal[K, V comparable](m1 AnyMap[K, V], m2 AnyMap[K, V]) bool

Equal reports whether two maps contain the same key/value pairs. Values are compared using ==.

func EqualFunc

func EqualFunc[K comparable, V any](m1 AnyMap[K, V], m2 AnyMap[K, V], eq func(V, V) bool) bool

EqualFunc is like Equal, but compares values using eq. Keys are still compared with ==.

func FindValue

func FindValue[K comparable, V comparable](m ComparableMap[K, V], val V) (*K, bool)

判断map中是否存在对应的val

func HasKey

func HasKey[K comparable, V any](m AnyMap[K, V], key K) bool

判断map中对应的key是否存在

func Keys

func Keys[K comparable, V any](m AnyMap[K, V]) []K

获取map中的所有key

func Values

func Values[K comparable, V any](m AnyMap[K, V]) []V

获取map中的所有Values

Types

type AnyMap

type AnyMap[K comparable, V any] map[K]V

定义一个泛型的 map 类型

type ByPair

type ByPair struct {
	Pairs    []*Pair
	LessFunc func(a *Pair, j *Pair) bool
}

func (ByPair) Len

func (a ByPair) Len() int

func (ByPair) Less

func (a ByPair) Less(i, j int) bool

func (ByPair) Swap

func (a ByPair) Swap(i, j int)

type ComparableMap

type ComparableMap[K comparable, V comparable] map[K]V

type OrderedMap

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

@bref OrderedMap 定义有序的键值对。

func NewOrderedMap

func NewOrderedMap() *OrderedMap

@bref NewOrderedMap 创建新的有序的键值对。OrderedMap 默认启用HTML转义。

返回值:

@return *OrderedMap 有序的键值对

func (*OrderedMap) Delete

func (o *OrderedMap) Delete(key string)

@bref Delete 从OrderedMap中删除指定的键值对。

参数:

@param key string 键

func (*OrderedMap) Get

func (o *OrderedMap) Get(key string) (interface{}, bool)

@bref Get 从OrderedMap中根据给定的键获取对应的值。

参数:

@param key string 键

返回值:

@return interface{} 对应的值, 如果键不存在,则返回nil
@return bool 如果键不存在,则返回false

func (*OrderedMap) Keys

func (o *OrderedMap) Keys() []string

@bref Keys 获取OrderedMap中所有的键。

返回值: @return []string 所有键

func (OrderedMap) MarshalJSON

func (o OrderedMap) MarshalJSON() ([]byte, error)

@bref MarshalJSON 将 OrderedMap 转换为 JSON 格式的字节切片

返回值:

@return []byte 字节切片
@return error 错误

func (*OrderedMap) Set

func (o *OrderedMap) Set(key string, value interface{})

@bref Set 将键值对存储到OrderedMap中。如果键已经存在,则更新其对应的值;

如果不存在,则添加新的键值对到OrderedMap中。

参数:

@param key string 键
@param value interface{} 值

func (*OrderedMap) SetEscapeHTML

func (o *OrderedMap) SetEscapeHTML(on bool)

@bref SetEscapeHTML 设置OrderedMap是否启用HTML转义。

参数:

@param on bool 是否启用HTML转义

func (*OrderedMap) Sort

func (o *OrderedMap) Sort(lessFunc func(a *Pair, b *Pair) bool)

@bref Sort 根据指定的排序函数对OrderedMap中的键进行排序。

参数:

@param lessFunc func(a *Pair, b *Pair) bool 排序函数, 返回true表示a排在b前面

func (*OrderedMap) SortKeys

func (o *OrderedMap) SortKeys(sortFunc func(keys []string))

@bref SortKeys 排序OrderedMap中的键。

参数:

@param sortFunc func(keys []string) 排序函数

func (*OrderedMap) UnmarshalJSON

func (o *OrderedMap) UnmarshalJSON(b []byte) error

@bref UnmarshalJSON 反序列化OrderedMap。

参数:

@param b []byte JSON字符串

func (*OrderedMap) Values

func (o *OrderedMap) Values() map[string]interface{}

@bref Values 获取OrderedMap中所有的值。

返回值:

@return map[string]interface{} 所有值, 键值对以map的形式返回

type Pair

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

func (*Pair) Key

func (kv *Pair) Key() string

func (*Pair) Value

func (kv *Pair) Value() interface{}

Jump to

Keyboard shortcuts

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