英文:
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))
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论