Skip to content

Commit

Permalink
added a JumpConsistentHash implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
OneOfOne committed Sep 3, 2014
1 parent 5f1a0d3 commit 918ad6c
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions hash/jumpconsistenthash.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package hash

const prime = 2862933555777941757

// JumpConsistentHash a fast, minimal memory, consistent hash algorithm based on the
// [paper](http://arxiv.org/pdf/1406.2294v1.pdf) by John Lamping and Eric Veach.
func JumpConsistentHash(key uint64, buckets int) (b int) {
j := 0
for j < buckets {
b = j
key = key*prime + 1
j = int(float64(b+1) * (float64(1<<31) / float64(key>>33+1)))
}
return b
}

0 comments on commit 918ad6c

Please sign in to comment.