Documentation ¶
Overview ¶
Package GoConsistentHash provides an implementation of a ring hash.
Index ¶
- func AcceptAny([]string, string) bool
- func AcceptUnique(stack []string, found string) bool
- type EntryValue
- type Hash
- type Map
- func (m *Map) AddString(keys ...string) error
- func (m *Map) AddStringWithWeight(key string, weight int) error
- func (m *Map) AddWithWeight(entryValue EntryValue, weight int) error
- func (m *Map) Del(key string) error
- func (m *Map) Get(key string) string
- func (m *Map) GetN(key string, n int, accept func([]string, string) bool) []string
- func (m *Map) IsEmpty() bool
- type StringValue
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AcceptUnique ¶
Accepts only unique items when used as accept argument in GetN.
Types ¶
type EntryValue ¶
type EntryValue interface {
HashRingId() string
}
type Map ¶
type Map struct {
// contains filtered or unexported fields
}
func (*Map) AddStringWithWeight ¶
Adds some strings to the hash with a custom weight.
func (*Map) AddWithWeight ¶
func (m *Map) AddWithWeight(entryValue EntryValue, weight int) error
Adds an item to the hash.
func (*Map) GetN ¶
Gets the N closest items in the hash to the provided key, if they're permitted by the accept function. This can be used to implement placement strategies like storing items in different availability zones.
The accept function returns a bool to indicate whether the item is acceptable. Its first argument is the items that have already been accepted, the second argument is the item that is about to be selected (if accepted).
The AcceptAny and AcceptUnique functions are provided as utility functions that can be used as accept-callback.
type StringValue ¶
type StringValue struct {
// contains filtered or unexported fields
}
func (*StringValue) HashRingId ¶
func (e *StringValue) HashRingId() string