Skip to content

Instantly share code, notes, and snippets.

@cipepser
Created January 31, 2017 05:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cipepser/e254088e7a699d3955f1ba1d101c13a6 to your computer and use it in GitHub Desktop.
Save cipepser/e254088e7a699d3955f1ba1d101c13a6 to your computer and use it in GitHub Desktop.
func DoubleHashing(hashA, hashB int64, n int) (hash int64) {
// h = hashA + n * hashBの計算
h := new(big.Int).Mul(big.NewInt(int64(n)), big.NewInt(hashB))
h = new(big.Int).Add(big.NewInt(hashA), h)
h = new(big.Int).Rem(h, big.NewInt(int64(size)))
// 余りが負の数になったときは正の余りにする
hash = h.Int64()
if hash < 0 {
hash += int64(size)
}
return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment