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 four.example.com/examples/object-key trying GET three.example.com/examples/object-key trying GET one.example.com/examples/object-key trying GET two.example.com/examples/object-key trying GET six.example.com/examples/object-key trying GET five.example.com/examples/object-key
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SortByWeight ¶
SortByWeight receive nodes and hash, and sort it by weight
func SortSliceByIndex ¶
func SortSliceByIndex(slice interface{}, hash uint64)
SortSliceByIndex received []T and hash to sort by index-weight
func SortSliceByValue ¶
func SortSliceByValue(slice interface{}, hash uint64)
SortSliceByValue received []T and hash to sort by value-weight
Types ¶
Click to show internal directories.
Click to hide internal directories.