Documentation ¶
Index ¶
- Constants
- Variables
- type Config
- type Hash
- func (h *Hash) Add(nodes []medley.Node) (added int)
- func (h *Hash) Algorithm() medley.Algorithm
- func (h *Hash) Get(k medley.Key) (n medley.Node, err error)
- func (h *Hash) Len() (l int)
- func (h *Hash) Rehash(nodes []medley.Node) (added, removed int)
- func (h *Hash) Remove(nodes []medley.Node) (removed int)
- func (h *Hash) Vnodes() int
Constants ¶
const (
// DefaultVnodes is the default number of virtual nodes per node
DefaultVnodes = 211
)
Variables ¶
var ( // ErrEmpty indicates that a search operation was attempted over an empty hash ErrEmpty = errors.New("no hash nodes defined") )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { // Algorithm is the name of the algorithm to use. If this field // is unset, medley.DefaultAlgorithm() is used. Algorithm string `json:"algorithm"` // Vnodes is the number of virtual nodes for each node. If this field // is unset or nonpositive, DefaultVnodes is used. Vnodes int `json:"vnodes"` // Extensions is an optional set of algorithms beyond this package's builtins. // The Algorithm field can refer to a key within this map. Extensions map[string]medley.Algorithm `json:"-"` }
Config represents the available configuration options for a consistent hash.
type Hash ¶
type Hash struct {
// contains filtered or unexported fields
}
Hash represents a consistent hash. This type is backward compatible with https://github.com/billhathaway/consistentHash.
A Hash is safe for concurrent use.
func (*Hash) Add ¶
Add inserts nodes and their corresponding vnodes into this hash. Any nodes already present are left intact.
This method reorders the nodes slice in-place using NodeSet.Filter.
func (*Hash) Get ¶
Get obtains the closest Node associated with a Key. The hash ring is walked clockwise to find the nearest node.
func (*Hash) Len ¶
Len returns the count of nodes associated with this hash. This is not the size of the internal storage of the hash. Len()*Vnodes() would return the total size of the internal hash ring.
func (*Hash) Rehash ¶
Rehash restructures this hash so that the given nodes are the only ones in the ring. Any nodes currently part of this hash that are not in the set of nodes passed to this method are removed. Nodes passed to this method that are not in this hash are added.
Unlike Add and Remove, this method does not reorder the nodes slice.
The separate counts of nodes added and removed are returned.