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.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/xxhash.rb', line 48

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.



46
47
48
# File 'lib/xxhash.rb', line 46

def digest_length
  @digest_length
end

Instance Method Details

#digest(val = nil) ⇒ Object



67
68
69
70
71
# File 'lib/xxhash.rb', line 67

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

  @hash.digest
end

#digest!(val = nil) ⇒ Object



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

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

  result
end

#resetObject



80
81
82
# File 'lib/xxhash.rb', line 80

def reset
  @hash.reset
end

#update(chunk) ⇒ Object



63
64
65
# File 'lib/xxhash.rb', line 63

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