Documentation ¶
Overview ¶
Package medley implements distributed hashing aimed at microservices. Currently, only consistent hashing is implemented.
Index ¶
- Constants
- func ComputeHash(k Key, alg Algorithm) uint64
- type Algorithm
- type Bytes
- type Key
- type Node
- type NodeSet
- func (ns *NodeSet) Add(n Node) (added bool)
- func (ns *NodeSet) AddAll(nodes ...Node) (count int)
- func (ns NodeSet) Filter(nodes []Node) (in, notIn []Node)
- func (ns NodeSet) Has(n Node) bool
- func (ns NodeSet) Len() int
- func (ns *NodeSet) Remove(n Node) (removed bool)
- func (ns *NodeSet) RemoveAll(nodes ...Node) (count int)
- type String
- type UnknownAlgorithmError
Constants ¶
const ( // AlgorithmFNV is the configuration value for an fnv.New64a algorithm AlgorithmFNV = "fnv" // AlgorithmMurmur3 is the configuration value for a murmur3.New64 algorithm AlgorithmMurmur3 = "murmur3" )
Variables ¶
This section is empty.
Functions ¶
func ComputeHash ¶
ComputeHash is a convenience for computing a single key's hash value using an algorithm. In general, the hash object returned from an Algorithm should be reset and reused when computing many hash values. This function is provided as a utility for test code and a convenience for tools that can query a hash.
Types ¶
type Algorithm ¶
Algorithm is a constructor for a 64-bit hash object. The various NewXXX function in the stdlib hash subpackages are of this type.
func DefaultAlgorithm ¶
func DefaultAlgorithm() Algorithm
DefaultAlgorithm returns the Algorithm to be used when none is supplied or configured. Currently, this package defaults to github.com/spaolacci/murmur3.
func FindAlgorithm ¶
FindAlgorithm accepts a configured name and attempts to locate the appropriate Algorithm. The set of built-in algorithms is consulted first, followed by the extensions (if supplied). The set of extensions can be nil. If name is empty, DefaultAlgorithm() is returned.
This function will return an error of type *UnknownAlgorithmError if no such algorithm was found.
func GetAlgorithm ¶
GetAlgorithm accepts a configured name and attempts to locate the built-in algorithm associated with that name. If name is empty, DefaultAlgorithm() is returned.
This function will return an error of type *UnknownAlgorithmError if no such algorithm was found.
type Key ¶
Key defines the behavior of hash keys. All hash keys can write their own hashable bytes to an output sink.
type Node ¶
type Node string
Node is a string type that is assigned hash values in a ring. A node can be any string, but is most often a URL or host name.
type NodeSet ¶
NodeSet is a set of nodes. The zero value of this type is ready to use.
The typical use case for a NodeSet is to track which nodes are part of a hash. Without a set, the hash would likely need to do binary or even linear searches to determine if a node was already hashed.
func NewNodeSet ¶
NewNodeSet constructs a NodeSet from a slice of nodes
func (*NodeSet) Add ¶
Add inserts the given node into this set. This set is initialized as needed. This method returns true to indicate that the node was added, false to indicate that the node was already present.
func (*NodeSet) AddAll ¶
AddAll adds each of a sequence of nodes. Any nodes already in this set are not modified. This method returns the count of nodes actually added.
As with Add, this set is initialized as needed.
func (NodeSet) Filter ¶
Filter examines each node in a slice to determine if it is present in this set. The slice is rearranged in-place so that nodes that are in this set are contiguous in the first portion of the slice, while all the nodes not in this set follow. The two slices that are returned point into the given slice and contain the nodes in and not in this set, respectively.
type UnknownAlgorithmError ¶
type UnknownAlgorithmError struct { // Name is the name which is unrecognized. This will never be blank, // as a blank name is interpreted as AlgorithmDefault. Name string }
UnknownAlgorithmError indicates that no algorithm could be created using the given Name
func (*UnknownAlgorithmError) Error ¶
func (e *UnknownAlgorithmError) Error() string
Error fulfills the error interface