package hashtag

import 

// RendezvousHash implements HRW (Highest Random Weight) hashing.
type RendezvousHash struct {
	nodes []node
}

type node struct {
	name string
	hash 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
	 ^=  >> 27
	return  * 2685821657736338717
}