Documentation ¶
Overview ¶
Package consistenthash provides an implementation of a ring hash.
Package consistenthash provides an implementation of a ring hash.
Index ¶
- func SortUints(x []uint32)
- func SortUints64(x []uint64)
- type ConsistentHash
- func (ch *ConsistentHash) Add(keys ...[]byte)
- func (ch *ConsistentHash) AddReplicas(replicas uint, keys ...[]byte)
- func (ch *ConsistentHash) Get(key []byte) []byte
- func (ch *ConsistentHash) GetString(key string) string
- func (ch *ConsistentHash) IsEmpty() bool
- func (ch *ConsistentHash) Metrics() any
- func (ch *ConsistentHash) Remove(key []byte) bool
- type ConsistentHash64
- func (ch *ConsistentHash64) Add(keys ...[]byte)
- func (ch *ConsistentHash64) AddReplicas(replicas uint, keys ...[]byte)
- func (ch *ConsistentHash64) Get(key []byte) []byte
- func (ch *ConsistentHash64) GetString(key string) string
- func (ch *ConsistentHash64) IsEmpty() bool
- func (ch *ConsistentHash64) Metrics() any
- func (ch *ConsistentHash64) Remove(key []byte) bool
- type HashFunc
- type HashFunc64
- type Option
- type UInt64Slice
- type UIntSlice
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SortUints64 ¶ added in v2.1.0
func SortUints64(x []uint64)
Types ¶
type ConsistentHash ¶
type ConsistentHash struct {
// contains filtered or unexported fields
}
ConsistentHash everything we need for CH
func (*ConsistentHash) Add ¶
func (ch *ConsistentHash) Add(keys ...[]byte)
Add adds some keys to the hash
func (*ConsistentHash) AddReplicas ¶
func (ch *ConsistentHash) AddReplicas(replicas uint, keys ...[]byte)
AddReplicas adds key and generates "replicas" number of hashes in ring
func (*ConsistentHash) Get ¶
func (ch *ConsistentHash) Get(key []byte) []byte
Get finds the closest item in the hash ring to the provided key
func (*ConsistentHash) GetString ¶ added in v2.1.0
func (ch *ConsistentHash) GetString(key string) string
GetString gets the closest item in the hash ring to the provided key
func (*ConsistentHash) IsEmpty ¶
func (ch *ConsistentHash) IsEmpty() bool
IsEmpty returns true if there are no items available
func (*ConsistentHash) Metrics ¶ added in v2.1.0
func (ch *ConsistentHash) Metrics() any
Metrics return the collected metrics
func (*ConsistentHash) Remove ¶
func (ch *ConsistentHash) Remove(key []byte) bool
Remove removes the key from hash table
type ConsistentHash64 ¶ added in v2.1.0
type ConsistentHash64 struct {
// contains filtered or unexported fields
}
ConsistentHash64 everything we need for CH
func New64 ¶ added in v2.1.0
func New64(opts ...Option) *ConsistentHash64
New64 makes new ConsistentHash
func (*ConsistentHash64) Add ¶ added in v2.1.0
func (ch *ConsistentHash64) Add(keys ...[]byte)
Add adds some keys to the hash
func (*ConsistentHash64) AddReplicas ¶ added in v2.1.0
func (ch *ConsistentHash64) AddReplicas(replicas uint, keys ...[]byte)
AddReplicas adds key and generates "replicas" number of hashes in ring
func (*ConsistentHash64) Get ¶ added in v2.1.0
func (ch *ConsistentHash64) Get(key []byte) []byte
Get finds the closest item in the hash ring to the provided key
func (*ConsistentHash64) GetString ¶ added in v2.1.0
func (ch *ConsistentHash64) GetString(key string) string
GetString gets the closest item in the hash ring to the provided key
func (*ConsistentHash64) IsEmpty ¶ added in v2.1.0
func (ch *ConsistentHash64) IsEmpty() bool
IsEmpty returns true if there are no items available
func (*ConsistentHash64) Metrics ¶ added in v2.1.0
func (ch *ConsistentHash64) Metrics() any
Metrics return the collected metrics
func (*ConsistentHash64) Remove ¶ added in v2.1.0
func (ch *ConsistentHash64) Remove(key []byte) bool
Remove removes the key from hash table
type HashFunc64 ¶ added in v2.1.0
HashFunc64 hash function to generate random hash
type Option ¶
type Option func(*options)
func WithBlockPartitioning ¶ added in v2.1.0
WithBlockPartitioning uses block partitioning, divides total number of keys to the given number to get number of blocks
func WithDefaultReplicas ¶
WithDefaultReplicas default number of replicas to add for each key
func WithHashFunc ¶
WithHashFunc hash function for 32bit CH
func WithHashFunc64 ¶ added in v2.1.0
func WithHashFunc64(hashFunc HashFunc64) Option
WithHashFunc64 hash function for 64bit CH
func WithMetrics ¶ added in v2.1.0
func WithMetrics() Option
WithMetrics enables collecting metrics for block partitioning using metrics is not thread safe, and needs to be used only for test and debugging
func WithReadLockFree ¶ added in v2.1.0
WithReadLockFree setting to false, will disable creating a copy of hash records, and will use read lock for lookup process
type UInt64Slice ¶ added in v2.1.0
type UInt64Slice []uint64
UInt64Slice attaches the methods of Interface to []uint64, sorting in increasing order.
func (UInt64Slice) Len ¶ added in v2.1.0
func (x UInt64Slice) Len() int
func (UInt64Slice) Less ¶ added in v2.1.0
func (x UInt64Slice) Less(i, j int) bool
func (UInt64Slice) Swap ¶ added in v2.1.0
func (x UInt64Slice) Swap(i, j int)