Hash
不同的输入可能会散列成相同的输出,而不可能从散列值来唯一的确定输入值,简单的说就是一种将任意长度的消息压缩到某一固定长度的消息摘要的函数
import(
"gotest/hash/cityhash"
"gopkg.in/mgo.v2/bson"
"fmt"
"time"
)
func main(){
for{
subKey := bson.NewObjectId().Hex()
hValue := cityhash.CityHash32([]byte(subKey), uint32(len(subKey)))
idx := hValue % 100
fmt.Printf("hValue: %d, %d\n", hValue, idx)
time.Sleep(1 * time.Second)
}
}
ketama 一致性哈希算法
http://blog.codinglabs.org/articles/consistent-hashing.html
在这个圆圈上会映射两种元素的哈希值,一种元素是Object的哈希值,另一种元素是cache的哈希值,即计算机节点的哈希值