Last active
April 24, 2020 15:18
-
-
Save teivah/0e80278625dd21d6b78de98e01e326bf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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