Documentation
¶
Index ¶
Constants ¶
View Source
const ( // DEFAULT_BUCKET_LOAD_FACTOR 代表默认的装载因子。 // 当散列段中的某个散列桶的尺寸超过了 // 本因子与当散列段尺寸的乘积,就会触发再散列。 DEFAULT_BUCKET_LOAD_FACTOR float64 = 0.75 // DEFAULT_BUCKET_NUMBER 代表一个散列段包含的散列桶的默认数量。 DEFAULT_BUCKET_NUMBER int = 16 // DEFAULT_BUCKET_MAX_SIZE 代表单个散列桶的默认最大尺寸。 DEFAULT_BUCKET_MAX_SIZE uint64 = 1000 )
View Source
const ( // MAX_CONCURRENCY 代表最大并发量。 MAX_CONCURRENCY int = 65536 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bucket ¶
type Bucket interface {
// Put 会放入一个键-元素对。
// 第一个返回值表示是否新增了键-元素对。
// 若在调用此方法前已经锁定lock,则不要把lock传入!否则必须传入对应的lock!
Put(p Pair, lock sync.Locker) (bool, error)
// Get 会获取指定键的键-元素对。
Get(key string) Pair
// GetFirstPair 会返回第一个键-元素对。
GetFirstPair() Pair
// Delete 会删除指定的键-元素对。
// 若在调用此方法前已经锁定lock,则不要把lock传入!否则必须传入对应的lock!
Delete(key string, lock sync.Locker) bool
// Clear 会清空当前散列桶。
// 若在调用此方法前已经锁定lock,则不要把lock传入!否则必须传入对应的lock!
Clear(lock sync.Locker)
// Size 会返回当前散列桶的尺寸。
Size() uint64
// String 会返回当前散列桶的字符串表示形式。
String() string
}
Bucket 代表并发安全的散列桶的接口。
type BucketStatus ¶
type BucketStatus uint8
BucketStatus 代表散列桶状态的类型。
const ( // BUCKET_STATUS_NORMAL 代表散列桶正常。 BUCKET_STATUS_NORMAL BucketStatus = 0 // BUCKET_STATUS_UNDERWEIGHT 代表散列桶过轻。 BUCKET_STATUS_UNDERWEIGHT BucketStatus = 1 // BUCKET_STATUS_OVERWEIGHT 代表散列桶过重。 BUCKET_STATUS_OVERWEIGHT BucketStatus = 2 )
type ConcurrentMap ¶
type ConcurrentMap interface {
// Concurrency 会返回并发量。
Concurrency() int
// Put 会推送一个键-元素对。
// 注意!参数element的值不能为nil。
// 第一个返回值表示是否新增了键-元素对。
// 若键已存在,新元素值会替换旧的元素值。
Put(key string, element interface{}) (bool, error)
// Get 会获取与指定键关联的那个元素。
// 若返回nil,则说明指定的键不存在。
Get(key string) interface{}
// Delete 会删除指定的键-元素对。
// 若结果值为true则说明键已存在且已删除,否则说明键不存在。
Delete(key string) bool
// Len 会返回当前字典中键-元素对的数量。
Len() uint64
}
ConcurrentMap 代表并发安全的字典的接口。
func NewConcurrentMap ¶
func NewConcurrentMap( concurrency int, pairRedistributor PairRedistributor) (ConcurrentMap, error)
NewConcurrentMap 会创建一个ConcurrentMap类型的实例。 参数pairRedistributor可以为nil。
type IllegalPairTypeError ¶
type IllegalPairTypeError struct {
// contains filtered or unexported fields
}
IllegalPairTypeError 代表非法的键-元素对类型的错误类型。
func (IllegalPairTypeError) Error ¶
func (ipte IllegalPairTypeError) Error() string
type IllegalParameterError ¶
type IllegalParameterError struct {
// contains filtered or unexported fields
}
IllegalParameterError 代表非法的参数的错误类型。
func (IllegalParameterError) Error ¶
func (ipe IllegalParameterError) Error() string
type Pair ¶
type Pair interface {
// Key 会返回键的值。
Key() string
// Hash 会返回键的哈希值。
Hash() uint64
// Element 会返回元素的值。
Element() interface{}
// Set 会设置元素的值。
SetElement(element interface{}) error
// Copy 会生成一个当前键-元素对的副本并返回。
Copy() Pair
// String 会返回当前键-元素对的字符串表示形式。
String() string
// contains filtered or unexported methods
}
Pair 代表并发安全的键-元素对的接口。
type PairRedistributor ¶
type PairRedistributor interface {
// UpdateThreshold 会根据键-元素对总数和散列桶总数计算并更新阈值。
UpdateThreshold(pairTotal uint64, bucketNumber int)
// CheckBucketStatus 用于检查散列桶的状态。
CheckBucketStatus(pairTotal uint64, bucketSize uint64) (bucketStatus BucketStatus)
// Redistribe 用于实施键-元素对的再分布。
Redistribe(bucketStatus BucketStatus, buckets []Bucket) (newBuckets []Bucket, changed bool)
}
PairRedistributor 代表针对键-元素对的再分布器。 用于当散列段内的键-元素对分布不均时进行重新分布。
type PairRedistributorError ¶
type PairRedistributorError struct {
// contains filtered or unexported fields
}
PairRedistributorError 代表无法再分布键-元素对的错误类型。
func (PairRedistributorError) Error ¶
func (pre PairRedistributorError) Error() string
type Segment ¶
type Segment interface {
// Put 会根据参数放入一个键-元素对。
// 第一个返回值表示是否新增了键-元素对。
Put(p Pair) (bool, error)
// Get 会根据给定参数返回对应的键-元素对。
// 该方法会根据给定的键计算哈希值。
Get(key string) Pair
// GetWithHash 会根据给定参数返回对应的键-元素对。
// 注意!参数keyHash应该是基于参数key计算得出哈希值。
GetWithHash(key string, keyHash uint64) Pair
// Delete 会删除指定键的键-元素对。
// 若返回值为true则说明已删除,否则说明未找到该键。
Delete(key string) bool
// Size 用于获取当前段的尺寸(其中包含的散列桶的数量)。
Size() uint64
}
Segment 代表并发安全的散列段的接口。
Source Files
¶
Click to show internal directories.
Click to hide internal directories.