Created
January 31, 2017 05:32
-
-
Save cipepser/e254088e7a699d3955f1ba1d101c13a6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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