Created
March 25, 2010 20:44
-
-
Save jdunphy/344086 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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