mmh3

package module
v0.0.0-...-fdfce3b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 29, 2019 License: CC0-1.0 Imports: 3 Imported by: 1

README

BuildStatus GoDoc

MurmurHash3 for Golang

This is a Golang wrapper for the original MurmurHash3 C++ implementation. It was created with SWIG. The goal is to make something similar to the Python mmh3 package for Golang.

Usage

You probably just want to use the three helper functions in the mmh3.go file at the root of this package:

  • Hashx86_32
  • Hashx86_128
  • Hashx64_128

The files in the MurmurHash3 directory are for SWIG and are not very readable.

The Python mmh3 package has a hash function that is just shorthand for the x86 32-bit MurmurHash3 function. It also returns signed integers by default. I have done no such thing in this package. You must pass the input as a byte slice, provide a seed value, and specify which MurmurHash3 function you want to use. If you want to hash a string à la print(hex(mmh3.hash('foo'))) in Python mmh3, you might do something like:

import (
    "encoding/binary"
    "fmt"

    "github.com/roberson-io/mmh3"
)

 key := []byte("foo")
 var seed uint32 = 0
 hash := mmh3.Hashx86_32(key, seed)
 fmt.Printf("%x\n", binary.LittleEndian.Uint32(hash))

You can call the other two functions the same way:

 key := []byte("foo")
 var seed uint32 = 0

 hashx86 := mmh3.Hashx86_128(key, seed)
 fmt.Printf(
     "%x\t%x\n",
     binary.LittleEndian.Uint64(hashx86[:8]),
     binary.LittleEndian.Uint64(hashx86[8:]),
 )

 hashx64 := mmh3.Hashx64_128(key, seed)
 fmt.Printf(
     "%x\t%x\n",
     binary.LittleEndian.Uint64(hashx64[:8]),
     binary.LittleEndian.Uint64(hashx64[8:]),
 )

Why?

I am aware of reusee's Golang implementation of mmh3. Key differences between that project and this one are:

  • This just a wrapper around the original C++ implementation (not pure Go)
  • This allows you to specify a seed value.
  • This does not implement the hash.Hash interface used in standard library packages (crypto/md5, crypto/sha256, etc.).

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Hashx64_128

func Hashx64_128(key []byte, seed uint32) []byte

Hashx64_128 is a helper function for MurmurHash3_x64_128 in the original C++ implementation. It accepts data to be hashed as a byte slice as well as a seed value. It returns a byte slice with the hash.

func Hashx86_128

func Hashx86_128(key []byte, seed uint32) []byte

Hashx86_128 is a helper function for MurmurHash3_x86_128 in the original C++ implementation. It accepts data to be hashed as a byte slice as well as a seed value. It returns a byte slice with the hash.

func Hashx86_32

func Hashx86_32(key []byte, seed uint32) []byte

Hashx86_32 is a helper function for MurmurHash3_x86_32 in the original C++ implementation. It accepts data to be hashed as a byte slice as well as a seed value. It returns a byte slice with the hash.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL