Home > Software design >  make mmh3 hash with golang
make mmh3 hash with golang

Time:07-20

I want make mmh3 hash with golang!
I found this pkg but i get runtime error!

package main

import (
    "encoding/binary"
    "fmt"

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

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

CodePudding user response:

It seem there is some issue in roberson-io/mmh3 implementation

Instead you can try datadog/mmh3

Example:

package main

import (
    "fmt"

    "github.com/datadog/mmh3"
)

func main() {
    key := []byte("foo")
    fmt.Printf("%x\n", mmh3.Hash32(key))
}

Or reusee/mmh3

Example:

package main

import (
    "fmt"

    "github.com/reusee/mmh3"
)

func main() {
    key := []byte("foo")
    h := mmh3.New32()
    h.Write(key)
    fmt.Printf("%x\n", h.Sum(nil))
}
  • Related