🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
[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 */ ```