consistenthash: Index | Files

package consistenthash

import ""

Package consistenthash implements a consistent hash.


Package Files


type ConsistentHash Uses

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 New Uses

func New(mult int) (*ConsistentHash, error)

New is an alias to NewConsistentHash.

func NewConsistentHash Uses

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 Uses

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 Uses

func (h *ConsistentHash) Insert(s string) error

Insert a new element into the SumList as "mult" instances of crc32 hashes.

func (*ConsistentHash) Remove Uses

func (h *ConsistentHash) Remove(s string) error

Remove a new element from the SumList as "mult" instances of crc32 hashes.

Package consistenthash imports 3 packages (graph). Updated 2017-03-13. Refresh now. Tools for package owners. This is an inactive package (no imports and no commits in at least two years).