ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
[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 */ ```