Class: SamplingHash::Hash
- Inherits:
-
Object
- Object
- SamplingHash::Hash
- Defined in:
- lib/sampling-hash/hash.rb
Instance Method Summary collapse
- #digest ⇒ Object
-
#initialize(size, seed = size, sampler = nil, xxhash = XXhash::XXhashInternal::StreamingHash64.new(seed)) ⇒ Hash
constructor
A new instance of Hash.
- #update(chunk) ⇒ Object
Constructor Details
#initialize(size, seed = size, sampler = nil, xxhash = XXhash::XXhashInternal::StreamingHash64.new(seed)) ⇒ Hash
Returns a new instance of Hash.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/sampling-hash/hash.rb', line 3 def initialize(size, seed = size, sampler = nil, xxhash = XXhash::XXhashInternal::StreamingHash64.new(seed)) @sampler = sampler || Sampler.new(size) @xxhash = xxhash # Position in data stream. @position = 0 # Current sample. @current_sample = nil # The data. @current_sample_offset = 0 # The offset (within the stream). @current_sample_size = 0 # The sample size. @next = 0 # The next sample index. # Start. next_sample end |
Instance Method Details
#digest ⇒ Object
30 31 32 |
# File 'lib/sampling-hash/hash.rb', line 30 def digest @xxhash.digest end |
#update(chunk) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/sampling-hash/hash.rb', line 20 def update(chunk) pos = 0 while pos < chunk.size len = chunk.size - pos used = advance(chunk, pos, len) @position += used pos += used end end |