xxhash 返回整数类型

最后更新于:2022-04-02 02:40:43

[TOC] ## 概述 xxhash 字符长度不固定 ![UTOOLS1588991050283.png](http://yanxuan.nosdn.127.net/f678c3f86b806d63a983b422729028c9.png) ## 安装 `go get github.com/OneOfOne/xxhash ` ## 实例 ``` package main import ( "fmt" "github.com/OneOfOne/xxhash" ) // 将一个键进行Hash func XXHash(key []byte) uint64 { h := xxhash.New64() h.Write(key) return h.Sum64() } func main() { keys := []string{"hi", "my", "friend", "I", "love", "you", "my", "apple"} for _, key := range keys { fmt.Printf("xxhash('%s')=%d\n", key, XXHash([]byte(key))) } } /** xxhash('hi')=16899831174130972922 xxhash('my')=13223332975333369668 xxhash('friend')=4642001949237932008 xxhash('I')=12677399051867059349 xxhash('love')=12577149608739438547 xxhash('you')=943396405629834470 xxhash('my')=13223332975333369668 xxhash('apple')=6379808199001010847 */ ```
';