Method: TCellAgent::Utils::Strings.java_hashcode
- Defined in:
- lib/tcell_agent/utils/strings.rb
.java_hashcode(str) ⇒ Object
emulate the java String.hashcode() without upcasting to BigInt
21 22 23 24 25 26 27 28 |
# File 'lib/tcell_agent/utils/strings.rb', line 21 def self.java_hashcode(str) result = 0 str.each_codepoint do |cp| # prevent overflow into BigInt which would cause heap allocs + emulate c-style int32 signed add overflow result = ((((((result & 0x07FFFFFF) << 5) - result) + cp) + 0x80000000) & 0xFFFFFFFF) - 0x80000000 end result end |