Module: SamplingHash
- Defined in:
- lib/sampling-hash.rb,
lib/sampling-hash/hash.rb,
lib/sampling-hash/sampler.rb,
lib/sampling-hash/version.rb,
lib/sampling-hash/sampling-io.rb
Defined Under Namespace
Classes: Hash, Sampler, SamplingIO
Constant Summary collapse
- VERSION =
'0.1.2'
Class Method Summary collapse
-
.hash(path, seed = File.size(path), hash = XXhash::XXhashInternal::StreamingHash64.new(seed)) ⇒ Object
We default to 64 bit xxhash.
- .hash32(path, seed = File.size(path)) ⇒ Object
- .hash64(path, seed = File.size(path)) ⇒ Object
Class Method Details
.hash(path, seed = File.size(path), hash = XXhash::XXhashInternal::StreamingHash64.new(seed)) ⇒ Object
We default to 64 bit xxhash.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/sampling-hash.rb', line 9 def self.hash(path, seed = File.size(path), hash = XXhash::XXhashInternal::StreamingHash64.new(seed)) raise ArgumentError, 'file not found' unless File.file?(path) File.open(path, 'r') do |fd| sio = SamplingIO.new(fd) sio.samples do |chunk| hash.update(chunk) end hash.digest end end |
.hash32(path, seed = File.size(path)) ⇒ Object
24 25 26 |
# File 'lib/sampling-hash.rb', line 24 def self.hash32(path, seed = File.size(path)) hash path, seed, XXHash::XXhashInternal::StreamingHash32.new(seed) end |
.hash64(path, seed = File.size(path)) ⇒ Object
28 29 30 |
# File 'lib/sampling-hash.rb', line 28 def self.hash64(path, seed = File.size(path)) hash path, seed, XXHash::XXhashInternal::StreamingHash64.new(seed) end |