Class: Digest::XXHash

Inherits:
Class
  • Object
show all
Defined in:
lib/xxhash.rb

Direct Known Subclasses

XXHash32, XXHash64

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bitlen, seed = 0) ⇒ XXHash

Returns a new instance of XXHash.



56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/xxhash.rb', line 56

def initialize(bitlen, seed = 0)
  bitlen = bitlen.to_i
  seed = seed.to_i
  @hash = case bitlen
  when 32
    XXhash::XXhashInternal::StreamingHash32.new(seed)
  when 64
    XXhash::XXhashInternal::StreamingHash64.new(seed)
  else
    raise ArgumentError, "Unsupported bit length: %s" % bitlen.inspect
  end

  @digest_length = bitlen
end

Instance Attribute Details

#digest_lengthObject (readonly)

Returns the value of attribute digest_length.



54
55
56
# File 'lib/xxhash.rb', line 54

def digest_length
  @digest_length
end

Instance Method Details

#digest(val = nil) ⇒ Object



75
76
77
78
79
# File 'lib/xxhash.rb', line 75

def digest(val = nil)
  @hash.update(val) if val

  @hash.digest
end

#digest!(val = nil) ⇒ Object



81
82
83
84
85
86
# File 'lib/xxhash.rb', line 81

def digest!(val = nil)
  result = digest(val)
  @hash.reset

  result
end

#resetObject



88
89
90
# File 'lib/xxhash.rb', line 88

def reset
  @hash.reset
end

#update(chunk) ⇒ Object



71
72
73
# File 'lib/xxhash.rb', line 71

def update(chunk)
  @hash.update(chunk.to_s)
end