Class: String

Inherits:
Object show all
Defined in:
lib/console/mux/color_formatter.rb

Instance Method Summary collapse

Instance Method Details

#hash_djb2Object

DJB hash algorithm 2. The default Ruby string hash is not stable across Ruby invocations (for security reasons).



26
27
28
29
30
31
32
# File 'lib/console/mux/color_formatter.rb', line 26

def hash_djb2
  hash = 5381
  each_codepoint do |c|
    hash = ((hash << 5) + hash) + c # equiv. hash * 33 + c?
  end
  hash
end