Sha256: a8129e2b26f8d5dcf35565a206dba99208cd6d4bc53c45e619fb989519d23f48

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 KB

Contents

require "digest/simple"

module Digest
  class MurmurHash < Simple
    def initialize
      @seed = self.class::DEFAULT_SEED
      super
    end

    def seed
      @seed
    end

    def seed=(s)
      fail ArgumentError, "seed string should #{digest_length * 16} bit chars" if s.bytesize != digest_length
      @seed = s
    end

    module Size32
      DEFAULT_SEED = "\x00\x00\x00\x00".encode('ASCII-8BIT')

      def digest_length
        4
      end

      def to_i
        finish.unpack("I")[0]
      end
    end

    module Size64
      DEFAULT_SEED = "\x00\x00\x00\x00\x00\x00\x00\x00".encode('ASCII-8BIT')

      def digest_length
        8
      end

      def to_i
        finish.unpack("L")[0]
      end
    end
  end

  class MurmurHash1 < MurmurHash
    include Size32
  end

  class MurmurHash2 < MurmurHash
    include Size32
  end

  class MurmurHash2A < MurmurHash
    include Size32
  end

  class MurmurHash64A < MurmurHash
    include Size64
  end

  class MurmurHash64B < MurmurHash
    include Size64
  end

  class MurmurHashAligned2 < MurmurHash
    include Size32
  end

  class MurmurHashNeutral2 < MurmurHash
    include Size32
  end
end

require "digest/murmurhash/murmurhash"

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
digest-murmurhash-1.0.0 lib/digest/murmurhash.rb