Created
December 20, 2017 18:01
-
-
Save scalone/39d9fede023ea07979a421d859f2ace5 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
#!/usr/bin/env ruby | |
module Hashname | |
def self.calc_hashname(name) | |
name.chars.inject(5381) do |hash, ch| | |
max_int = (hash << 5) + hash + ch.ord | |
self.force_overflow_unsigned(max_int) | |
end | |
end | |
def self.force_overflow_unsigned(i) | |
i % 2**32 # or equivalently: i & 0xffffffff | |
end | |
end | |
if __FILE__ == $0 | |
ARGV.each do |name| | |
puts "#{name} = #{Hashname.calc_hashname(name)}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment