Last active
February 26, 2016 09:30
-
-
Save paincompiler/e204d180794fd5836579 to your computer and use it in GitHub Desktop.
Revisions
-
paincompiler revised this gist
Feb 26, 2016 . No changes.There are no files selected for viewing
-
paincompiler created this gist
Feb 26, 2016 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ import "math/big" // simulate python 2.7 built-in __hash__ of string object func hash(s string) *big.Int { if len(s) == 0 { return big.NewInt(0) } value := big.NewInt(int64([]byte(s)[0]) << 7) for _, v := range []byte(s) { value = value.Xor(value.Mul(value, big.NewInt(1000003)), big.NewInt(int64(v))) } value = value.Xor(value, big.NewInt(int64(len(s)))) if value.Int64() == -1 { value.SetInt64(-2) } return value }