Documentation ¶
Index ¶
- func AllExist[K comparable, V any](m map[K]V, keys ...K) bool
- func Clear[K comparable, V any](m map[K]V)
- func Copy[K comparable, V any](m map[K]V) map[K]V
- func Exist[K comparable, V any](m map[K]V, key K) bool
- func KeyToSlice[K comparable, V any](m map[K]V) []K
- func RandomGet[K comparable, V any](m map[K]V) (v V)
- func RandomGetKey[K comparable, V any](m map[K]V) (k K)
- func RandomGetKeyN[K comparable, V any](m map[K]V, n int) (ks []K)
- func RandomGetN[K comparable, V any](m map[K]V, n int) (vs []V)
- func Reversal[K comparable, V comparable](m map[K]V) map[V]K
- func Sum[K comparable, V generic.Number](m map[K]V) V
- func ToIterator[V comparable](slice []V) map[V]struct{}
- func ToJson[K comparable, V any](m map[K]V) string
- func ToMap[V any](slice []V) map[int]V
- func ToMapBool[V comparable](slice []V) map[V]bool
- func ToSlice[K comparable, V any](m map[K]V) []V
- type Consistency
- type Set
- func (s Set[K]) Add(key K)
- func (s Set[K]) AddAll(keys ...K)
- func (s Set[K]) AllExist(keys ...K) bool
- func (s Set[K]) Clear()
- func (s Set[K]) Exist(key K) bool
- func (s Set[K]) RandomGet() (k K)
- func (s Set[K]) Remove(key K)
- func (s Set[K]) RemoveAll(keys ...K)
- func (s Set[K]) Size() int
- func (s Set[K]) ToJson() string
- func (s Set[K]) ToMap() map[K]struct{}
- func (s Set[K]) ToSlice() []K
- type SortMap
- func (slf *SortMap[K, V]) Del(key K)
- func (slf *SortMap[K, V]) For(handle func(key K, value V) bool)
- func (slf *SortMap[K, V]) ForSort(handle func(key K, value V) bool)
- func (slf *SortMap[K, V]) Get(key K) V
- func (slf *SortMap[K, V]) KeyToSlice() []K
- func (slf *SortMap[K, V]) Set(key K, value V)
- func (slf *SortMap[K, V]) ToMap() map[K]V
- func (slf *SortMap[K, V]) ToSlice() []V
- func (slf *SortMap[K, V]) ToSliceSort() []V
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AllExist ¶
func AllExist[K comparable, V any](m map[K]V, keys ...K) bool
AllExist 检查多个 key 是否存在
func RandomGet ¶ added in v0.0.9
func RandomGet[K comparable, V any](m map[K]V) (v V)
RandomGet 随机获取一个元素
func RandomGetKey ¶ added in v0.0.9
func RandomGetKey[K comparable, V any](m map[K]V) (k K)
RandomGetKey 随机获取一个 key
func RandomGetKeyN ¶ added in v0.0.9
func RandomGetKeyN[K comparable, V any](m map[K]V, n int) (ks []K)
RandomGetKeyN 随机获取 n 个 key
- 获取到的元素不会是重复的,当 map 的长度不足 n 时,返回的元素等同于 hash.KeyToSlice
func RandomGetN ¶ added in v0.0.9
func RandomGetN[K comparable, V any](m map[K]V, n int) (vs []V)
RandomGetN 随机获取 n 个元素
- 获取到的元素不会是重复的,当 map 的长度不足 n 时,返回的元素等同于 hash.ToSlice
func Reversal ¶
func Reversal[K comparable, V comparable](m map[K]V) map[V]K
Reversal 将 map 的 key 和 value 互换
func ToIterator ¶ added in v0.0.13
func ToIterator[V comparable](slice []V) map[V]struct{}
ToIterator 将切片转换为 Iterator
func ToJson ¶ added in v0.0.4
func ToJson[K comparable, V any](m map[K]V) string
ToJson 将 map 转换为 json 字符串
Types ¶
type Consistency ¶
type Consistency struct {
// contains filtered or unexported fields
}
Consistency 一致性哈希生成
https://blog.csdn.net/zhpCSDN921011/article/details/126845397
func NewConsistency ¶
func NewConsistency(replicas int) *Consistency
func (*Consistency) PickNode ¶
func (slf *Consistency) PickNode(key any) int
PickNode 获取与 key 最接近的节点
type Set ¶ added in v0.0.21
type Set[K comparable] map[K]struct{}
Set 集合
type SortMap ¶
type SortMap[K comparable, V any] struct { // contains filtered or unexported fields }
SortMap 有序的 map 实现
func NewSortMap ¶
func NewSortMap[K comparable, V any]() *SortMap[K, V]
func (*SortMap[K, V]) KeyToSlice ¶
func (slf *SortMap[K, V]) KeyToSlice() []K
func (*SortMap[K, V]) ToSliceSort ¶
func (slf *SortMap[K, V]) ToSliceSort() []V
Click to show internal directories.
Click to hide internal directories.