Module: ConsistentHashing::JenkinsOneAtATime

Extended by:
JenkinsOneAtATime
Included in:
JenkinsOneAtATime
Defined in:
lib/consistent_hashing/jenkins_one_at_a_time.rb

Instance Method Summary collapse

Instance Method Details

#hash(key) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/consistent_hashing/jenkins_one_at_a_time.rb', line 9

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

#hash_to_unit_circle(key) ⇒ Object



5
6
7
# File 'lib/consistent_hashing/jenkins_one_at_a_time.rb', line 5

def hash_to_unit_circle(key)
  hash(key)/0xffffffff.to_f
end