hash

package
v0.0.15 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

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 Copy

func Copy[K comparable, V any](m map[K]V) map[K]V

Copy 复制一个map

func Exist

func Exist[K comparable, V any](m map[K]V, key K) bool

Exist 检查特定 key 是否存在

func KeyToSlice

func KeyToSlice[K comparable, V any](m map[K]V) []K

KeyToSlice 将 map 的 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 Sum

func Sum[K comparable, V generic.Number](m map[K]V) V

Sum 计算一个 map 中的 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 字符串

func ToMap

func ToMap[V any](slice []V) map[int]V

ToMap 将切片转换为 map

func ToMapBool

func ToMapBool[V comparable](slice []V) map[V]bool

ToMapBool 将切片转换为 map,value作为Key

func ToSlice

func ToSlice[K comparable, V any](m map[K]V) []V

ToSlice 将 map 的 value 转换为切片

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) AddNode

func (slf *Consistency) AddNode(keys ...int)

AddNode 添加节点

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)
	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 ToSortMap

func ToSortMap[V any](slice []V) SortMap[int, V]

ToSortMap 将切片转换为 SortMap

func (*SortMap[K, V]) Del

func (slf *SortMap[K, V]) Del(key K)

func (*SortMap[K, V]) For

func (slf *SortMap[K, V]) For(handle func(key K, value V) bool)

func (*SortMap[K, V]) ForSort

func (slf *SortMap[K, V]) ForSort(handle func(key K, value V) bool)

func (*SortMap[K, V]) Get

func (slf *SortMap[K, V]) Get(key K) V

func (*SortMap[K, V]) KeyToSlice

func (slf *SortMap[K, V]) KeyToSlice() []K

func (*SortMap[K, V]) Set

func (slf *SortMap[K, V]) Set(key K, value V)

func (*SortMap[K, V]) ToMap

func (slf *SortMap[K, V]) ToMap() map[K]V

func (*SortMap[K, V]) ToSlice

func (slf *SortMap[K, V]) ToSlice() []V

func (*SortMap[K, V]) ToSliceSort

func (slf *SortMap[K, V]) ToSliceSort() []V

Jump to

Keyboard shortcuts

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