Documentation
¶
Overview ¶
Package consistenthash provides an implementation of a ring hash.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConsistentHash ¶
type ConsistentHash struct {
// contains filtered or unexported fields
}
ConsistentHash everything we need for CH
func New ¶ added in v1.0.0
func New(replicas int, hashFunction HashFunc) *ConsistentHash
New makes new ConsistentHash
func (*ConsistentHash) Add ¶
func (ch *ConsistentHash) Add(key string)
Add adds some keys to the hash key can be also ip:port of a replica
func (*ConsistentHash) AddReplicas ¶
func (ch *ConsistentHash) AddReplicas(key string, replicas int)
AddReplicas adds key and generates "replicas" number of hashes in ring key can be also ip:port of a replica
func (*ConsistentHash) Get ¶
func (ch *ConsistentHash) Get(key string) string
Get gets the closest item in the hash ring to the provided key e.g. key = "request url" O(log n)
func (*ConsistentHash) IsEmpty ¶
func (ch *ConsistentHash) IsEmpty() bool
IsEmpty returns true if there are no items available
func (*ConsistentHash) Remove ¶
func (ch *ConsistentHash) Remove(key string) bool
Remove removes the key from hash table
Click to show internal directories.
Click to hide internal directories.