Documentation ¶
Overview ¶
Package consistenthash implements a consistent hash.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConsistentHash ¶
type ConsistentHash struct { // to enter elements into the hash multiple times Mult int // the sorted list of hashed elements SumList []uint32 // a map of hash values to original strings Source (map[uint32]string) }
ConsistentHash maps hashed values to targets.
func NewConsistentHash ¶
func NewConsistentHash(mult int) (*ConsistentHash, error)
NewConsistentHash will create a new consistent hash with hashed elements multiplied and entered into the SumList "mult" times.
func (*ConsistentHash) Find ¶
func (h *ConsistentHash) Find(s string) (string, error)
Find the nearest hashed element (in ascending order) that the candidate string s maps to. should s hash to a greater value than the maximum hashed item in the SumList, loop around and select the zeroth hashed element
func (*ConsistentHash) Insert ¶
func (h *ConsistentHash) Insert(s string) error
Insert a new element into the SumList as "mult" instances of crc32 hashes.
func (*ConsistentHash) Remove ¶
func (h *ConsistentHash) Remove(s string) error
Remove a new element from the SumList as "mult" instances of crc32 hashes.
Click to show internal directories.
Click to hide internal directories.