0

Golang里面怎样把字符串转换为数字

annabelle created at4 years ago view count: 88

最好是int64的,碰撞要小

report
回复
0

你要干嘛,数据库uniq索引加自增id就行了。

4 years ago 回复
0

自带的有,碰撞不大。

package main

import (
        "fmt"
        "hash/fnv"
)

func hash(s string) uint32 {
        h := fnv.New32a()
        h.Write([]byte(s))
        return h.Sum32()
}

func main() {
        fmt.Println(hash("HelloWorld"))
        fmt.Println(hash("HelloWorld."))
}
4 years ago 回复

Recent search keywords