Documentation
¶
Overview ¶
Package hrw implements Rendezvous hashing. http://en.wikipedia.org/wiki/Rendezvous_hashing.
Example ¶
// given a set of servers
servers := []string{
"one.example.com",
"two.example.com",
"three.example.com",
"four.example.com",
"five.example.com",
"six.example.com",
}
// HRW can consistently select a uniformly-distributed set of servers for
// any given key
var (
key = []byte("/examples/object-key")
h = Hash(key)
)
SortSliceByValue(servers, h)
for id := range servers {
fmt.Printf("trying GET %s%s\n", servers[id], key)
}
Output: trying GET three.example.com/examples/object-key trying GET two.example.com/examples/object-key trying GET five.example.com/examples/object-key trying GET six.example.com/examples/object-key trying GET one.example.com/examples/object-key trying GET four.example.com/examples/object-key
Index ¶
- Constants
- func Hash(key []byte) uint64
- func Sort(nodes []uint64, hash uint64) []uint64
- func SortByWeight(nodes []uint64, weights []float64, hash uint64) []uint64
- func SortSliceByIndex(slice interface{}, hash uint64)
- func SortSliceByValue(slice interface{}, hash uint64)
- func SortSliceByWeightIndex(slice interface{}, weights []float64, hash uint64)
- func SortSliceByWeightValue(slice interface{}, weights []float64, hash uint64)
- func ValidateWeights(weights []float64) error
- type Hasher
Examples ¶
Constants ¶
View Source
const ( NormalizedMaxWeight = 1.0 NormalizedMinWeight = 0.0 )
Boundaries of valid normalized weights
Variables ¶
This section is empty.
Functions ¶
func SortByWeight ¶
SortByWeight receive nodes, weights and hash, and sort it by distance * weight
func SortSliceByIndex ¶
func SortSliceByIndex(slice interface{}, hash uint64)
SortSliceByIndex received []T and hash to sort by index-distance
func SortSliceByValue ¶
func SortSliceByValue(slice interface{}, hash uint64)
SortSliceByValue received []T and hash to sort by value-distance
func SortSliceByWeightIndex ¶ added in v1.0.7
SortSliceByWeightIndex received []T, weights and hash to sort by index-distance * weights
func SortSliceByWeightValue ¶ added in v1.0.7
SortSliceByWeightValue received []T, weights and hash to sort by value-distance * weights
func ValidateWeights ¶ added in v1.0.8
ValidateWeights checks if weights are normalized between 0.0 and 1.0
Types ¶
Click to show internal directories.
Click to hide internal directories.