Module: SimpleRecord::Sharding::Hashing

Defined in:
lib/simple_record/sharding.rb

Overview

Some hashing algorithms

Class Method Summary collapse

Class Method Details

.sdbm_hash(str, len = str.length) ⇒ Object



295
296
297
298
299
300
301
302
303
304
305
306
# File 'lib/simple_record/sharding.rb', line 295

def self.sdbm_hash(str, len=str.length)
#                puts 'sdbm_hash ' + str.inspect
  hash = 0
  len.times { |i|
    c = str[i]
#                    puts "c=" + c.class.name + "--" + c.inspect + " -- " + c.ord.inspect
    c = c.ord
    hash = c + (hash << 6) + (hash << 16) - hash
  }
#                puts "hash=" + hash.inspect
  return hash
end