This file contains 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
TWO_31 = 2 ** 31 | |
TWO_32 = 2 ** 32 | |
def java_hash_code(str) | |
size = str.size | |
hash = 0 | |
str.chars.each_with_index do |ch, i| | |
hash += ch.ord * (31 ** (size-(i+1))) | |
hash = hash % TWO_32 - TWO_31 | |
end |