Skip to content

Instantly share code, notes, and snippets.

@onemouth
Last active July 21, 2019 07:52
Show Gist options
  • Save onemouth/ddcbb3ee235bd2f91414c919d58387b0 to your computer and use it in GitHub Desktop.
Save onemouth/ddcbb3ee235bd2f91414c919d58387b0 to your computer and use it in GitHub Desktop.
func (m *Map) Add(nodes ...string) {
for _, n := range nodes {
for i := 0; i < m.replicas; i++ {
hash := int(m.hash([]byte(strconv.Itoa(i) + " " + n)))
m.nodes = append(m.nodes, hash)
m.hashMap[hash] = n
}
}
sort.Ints(m.nodes)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment