consistenthash

package
v0.0.0-...-d6d0da0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 4, 2018 License: Apache-2.0 Imports: 4 Imported by: 0

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 Hash

type Hash func(data []byte) uint32

type Map

type Map struct {
	// contains filtered or unexported fields
}

func New

func New(replicas int, fn Hash) *Map

New returns a blank consistent hash ring that will return the key whose hash comes next after the hash of the input to Map.Get. Increasing the number of replicas will improve the smoothness of the hash ring and reduce the data moved when adding/removing nodes, at the cost of more memory.

func NewConsistentHash

func NewConsistentHash(replicas int, tableExpansion int, fn Hash) *Map

NewConsistentHash returns a blank consistent hash ring that will return the key whose hash comes next after the hash of the input to Map.Get. Increasing the number of replicas will improve the smoothness of the hash ring and reduce the data moved when adding/removing nodes. Increasing the tableExpansion will allocate more entries in the internal hash table, reducing the frequency of lg(n) binary searches during calls to the Map.Get method.

func (*Map) Add

func (m *Map) Add(keys ...string)

Adds some keys to the hash.

func (*Map) Get

func (m *Map) Get(key string) string

Gets the closest item in the hash to the provided key.

func (*Map) IsEmpty

func (m *Map) IsEmpty() bool

Returns true if there are no items available.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL