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.
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ruby-xxhash.rb', line 46 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.
45 46 47 |
# File 'lib/ruby-xxhash.rb', line 45 def digest_length @digest_length end |
Instance Method Details
#digest(val = nil) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/ruby-xxhash.rb', line 62 def digest val=nil if val @hash.update val end @hash.digest end |
#digest!(val = nil) ⇒ Object
70 71 72 73 74 |
# File 'lib/ruby-xxhash.rb', line 70 def digest! val=nil result = digest(val) @hash.reset result end |
#reset ⇒ Object
76 77 78 |
# File 'lib/ruby-xxhash.rb', line 76 def reset @hash.reset end |
#update(chunk) ⇒ Object
58 59 60 |
# File 'lib/ruby-xxhash.rb', line 58 def update chunk @hash.update(chunk) end |