Source File
rendezvous.go
Belonging Package
github.com/redis/go-redis/v9/internal/hashtag
package hashtagimport// RendezvousHash implements HRW (Highest Random Weight) hashing.type RendezvousHash struct {nodes []node}type node struct {name stringhash uint64}// NewRendezvousHash builds a hash from shard names.func ( []string) *RendezvousHash {:= make([]node, len())for , := range {[] = node{name: ,hash: xxhash.Sum64String(),}}return &RendezvousHash{nodes: }}// Get returns the shard name for the given key.func ( *RendezvousHash) ( string) string {if len(.nodes) == 0 {return ""}:= xxhash.Sum64String():= 0:= mix64( ^ .nodes[0].hash)for := 1; < len(.nodes); ++ {if := mix64( ^ .nodes[].hash); > {==}}return .nodes[].name}// mix64 is a xorshift-based mixing function.func mix64( uint64) uint64 {^= >> 12^= << 25^= >> 27return * 2685821657736338717}
![]() |
The pages are generated with Golds v0.8.7. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |