Class: Digest::XXHash
- Inherits:
-
Class
- Object
- Class
- Digest::XXHash
- Defined in:
- lib/ruby-xxhash.rb
Instance Attribute Summary collapse
-
#digest_length ⇒ Object
readonly
Returns the value of attribute digest_length.
Instance Method Summary collapse
- #digest(val = nil) ⇒ Object
- #digest!(val = nil) ⇒ Object
-
#initialize(bitlen, seed = 0) ⇒ XXHash
constructor
A new instance of XXHash.
- #reset ⇒ Object
- #update(chunk) ⇒ Object
Constructor Details
#initialize(bitlen, seed = 0) ⇒ XXHash
Returns a new instance of XXHash.
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/ruby-xxhash.rb', line 48 def initialize bitlen, seed = 0 case bitlen when 32 @hash = XXhash::XXhashInternal::XXhash32.new(seed) when 64 @hash = XXhash::XXhashInternal::XXhash64.new(seed) else raise ArgumentError, "Unsupported bit length: %s" % bitlen.inspect end @digest_length = bitlen end |
Instance Attribute Details
#digest_length ⇒ Object (readonly)
Returns the value of attribute digest_length.
47 48 49 |
# File 'lib/ruby-xxhash.rb', line 47 def digest_length @digest_length end |
Instance Method Details
#digest(val = nil) ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/ruby-xxhash.rb', line 64 def digest val=nil if val @hash.update val end @hash.digest end |
#digest!(val = nil) ⇒ Object
72 73 74 75 76 |
# File 'lib/ruby-xxhash.rb', line 72 def digest! val=nil result = digest(val) @hash.reset result end |
#reset ⇒ Object
78 79 80 |
# File 'lib/ruby-xxhash.rb', line 78 def reset @hash.reset end |
#update(chunk) ⇒ Object
60 61 62 |
# File 'lib/ruby-xxhash.rb', line 60 def update chunk @hash.update(chunk) end |