Documentation ¶
Overview ¶
Package consistentHash implements a consistent hashing algorithm
Index ¶
- Constants
- Variables
- type ConsistentHash
- func (ch *ConsistentHash) Add(address string)
- func (ch *ConsistentHash) Get(key []byte) (string, error)
- func (ch *ConsistentHash) Get2(key []byte) (string, string, error)
- func (ch *ConsistentHash) GetN(key []byte, count int) ([]string, error)
- func (ch *ConsistentHash) Remove(address string)
- func (ch *ConsistentHash) SetVnodeCount(count int) error
Constants ¶
View Source
const (
// DefaultVnodeCount is a tradeoff of memory and ~ log(N) speed versus how well the hash spreads
DefaultVnodeCount = 200
)
Variables ¶
View Source
var ( // ErrNoMembers occurs when trying to hash before any members are added ErrNoMembers = errors.New("no members added") // ErrNotEnoughMembers occurs when more members are asked for than are available ErrNotEnoughMembers = errors.New("not enough members") // ErrNotAvailableOnceMembersAdded occurs if any attempt is made to modify the vnode account once members are added ErrNotAvailableOnceMembersAdded = errors.New("not available once members are added") // ErrInvalidVnodeCount occurs if the vnode count is set to 0 or lower ErrInvalidVnodeCount = errors.New("vnodeCount must be > 0") )
Functions ¶
This section is empty.
Types ¶
type ConsistentHash ¶
type ConsistentHash struct {
// contains filtered or unexported fields
}
ConsistentHash holds the internal data structures for the hashing
func New ¶
func New() *ConsistentHash
New creates a new consistentHash pointer and initializes all the necessary fields
func (*ConsistentHash) Add ¶
func (ch *ConsistentHash) Add(address string)
Add adds a server to the consistentHash
func (*ConsistentHash) Get ¶
func (ch *ConsistentHash) Get(key []byte) (string, error)
Get finds the closest member for a given key
func (*ConsistentHash) Get2 ¶
func (ch *ConsistentHash) Get2(key []byte) (string, string, error)
Get2 finds the closest 2 members for a given key and is just a helper function calling into GetN
func (*ConsistentHash) GetN ¶
func (ch *ConsistentHash) GetN(key []byte, count int) ([]string, error)
GetN finds the closest N members for a given key
func (*ConsistentHash) Remove ¶
func (ch *ConsistentHash) Remove(address string)
Remove removes a server from the consistentHash
func (*ConsistentHash) SetVnodeCount ¶
func (ch *ConsistentHash) SetVnodeCount(count int) error
SetVnodeCount sets the number of vnodes that will be added for every server This must be called before any Add() calls
Click to show internal directories.
Click to hide internal directories.