Module: XXhash

Defined in:
lib/xxhash.rb,
lib/xxhash/version.rb,
ext/xxhash/xxhash.c

Defined Under Namespace

Modules: XXhashInternal

Constant Summary collapse

VERSION =
"0.4.0"

Class Method Summary collapse

Class Method Details

.xxh32(input, seed = 0) ⇒ Object


6
7
8
# File 'lib/xxhash.rb', line 6

def self.xxh32(input, seed = 0)
  XXhashInternal.xxh32(input.to_s, seed.to_i)
end

.xxh32_stream(io, seed = 0, chunk_size = 32) ⇒ Object

Raises:

  • (ArgumentError)

14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/xxhash.rb', line 14

def self.xxh32_stream(io, seed = 0, chunk_size = 32)
  seed = seed.to_i
  chunk_size = chunk_size.to_i
  raise ArgumentError, 'first argument should be IO' if !io.respond_to?(:read)

  hash = XXhashInternal::StreamingHash32.new(seed)

  while chunk = io.read(chunk_size)
    hash.update(chunk.to_s)
  end

  hash.digest
end

.xxh64(input, seed = 0) ⇒ Object


10
11
12
# File 'lib/xxhash.rb', line 10

def self.xxh64(input, seed = 0)
  XXhashInternal.xxh64(input.to_s, seed.to_i)
end

.xxh64_stream(io, seed = 0, chunk_size = 32) ⇒ Object

Raises:

  • (ArgumentError)

28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/xxhash.rb', line 28

def self.xxh64_stream(io, seed = 0, chunk_size = 32)
  seed = seed.to_i
  chunk_size = chunk_size.to_i
  raise ArgumentError, 'first argument should be IO' if !io.respond_to?(:read)

  hash = XXhashInternal::StreamingHash64.new(seed)

  while chunk = io.read(chunk_size)
    hash.update(chunk.to_s)
  end

  hash.digest
end