Documentation ¶
Index ¶
- func AllExist[K comparable, V any](m map[K]V, keys ...K) bool
- 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 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 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 Map
- type MapReadonly
- 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 Reversal ¶
func Reversal[K comparable, V comparable](m map[K]V) map[V]K
Reversal 将 map 的 key 和 value 互换
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 Map ¶
type Map[Key comparable, Value any] interface { Set(key Key, value Value) Get(key Key) Value // AtomGetSet 原子方式获取一个值并在之后进行赋值 AtomGetSet(key Key, handle func(value Value, exist bool) (newValue Value, isSet bool)) // Atom 原子操作 Atom(handle func(m Map[Key, Value])) Exist(key Key) bool GetExist(key Key) (Value, bool) Delete(key Key) DeleteGet(key Key) Value DeleteGetExist(key Key) (Value, bool) DeleteExist(key Key) bool Clear() ClearHandle(handle func(key Key, value Value)) Range(handle func(key Key, value Value)) RangeSkip(handle func(key Key, value Value) bool) RangeBreakout(handle func(key Key, value Value) bool) RangeFree(handle func(key Key, value Value, skip func(), breakout func())) Keys() []Key Slice() []Value Map() map[Key]Value Size() int // GetOne 获取一个 GetOne() (value Value) }
Map 提供了map集合接口
type MapReadonly ¶
type MapReadonly[Key comparable, Value any] interface { Get(key Key) Value Exist(key Key) bool GetExist(key Key) (Value, bool) Length() int Range(handle func(key Key, value Value)) RangeSkip(handle func(key Key, value Value) bool) RangeBreakout(handle func(key Key, value Value) bool) RangeFree(handle func(key Key, value Value, skip func(), breakout func())) Keys() []Key Slice() []Value Map() map[Key]Value Size() int GetOne() (value Value) }
MapReadonly 只读字典接口
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.