Skip to content

Instantly share code, notes, and snippets.

@jdunphy
Created March 25, 2010 20:44
Show Gist options
  • Save jdunphy/344086 to your computer and use it in GitHub Desktop.
Save jdunphy/344086 to your computer and use it in GitHub Desktop.
module ConsistentHashing
module JenkinsOneAtATime
extend self
def hash_to_unit_circle(key)
hash(key)/0xffffffff.to_f
end
def hash(key)
hash = 0
key.each_byte do |byte|
hash += byte
hash += (hash << 10)
hash &= 0xffffffff
hash ^= (hash >> 6)
end
hash += (hash << 3)
hash &= 0xffffffff
hash ^= (hash >> 11)
hash += (hash << 15)
hash &= 0xffffffff
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment