使用Golang制作mmh3哈希。

huangapple go评论162阅读模式
英文:

make mmh3 hash with golang

问题

我想使用Golang进行mmh3哈希计算!我找到了这个pkg,但是我遇到了运行时错误!

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))
}
英文:

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))
}

答案1

得分: 1

roberson-io/mmh3的实现似乎存在一些问题。

你可以尝试使用datadog/mmh3

示例:

package main

import (
    "fmt"

    "github.com/datadog/mmh3"
)

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

或者使用reusee/mmh3

示例:

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))
}
英文:

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))
}

huangapple
  • 本文由 发表于 2022年7月19日 16:13:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/73033389.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定