Skip to content

Instantly share code, notes, and snippets.

@teivah
Last active April 24, 2020 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save teivah/0e80278625dd21d6b78de98e01e326bf to your computer and use it in GitHub Desktop.
Save teivah/0e80278625dd21d6b78de98e01e326bf to your computer and use it in GitHub Desktop.
type RendezVous struct {
nodes []Node
}
type Node struct {
id string
}
func (r *RendezVous) Get(key string) (*Node, error) {
length := uint32(len(r.nodes))
var maxHashValue = hash(key, r.nodes[0].id, length)
result := 0
for index, node := range r.nodes[1:] {
currentHashValue := hash(key, node.id, length)
if currentHashValue > maxHashValue {
maxHashValue = currentHashValue
result = index
}
}
return &r.nodes[result], nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment