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的哈希值,即計算機節點的哈希值