Skip to content

Instantly share code, notes, and snippets.

@roylee0704
Created May 15, 2016 11:21
Show Gist options
  • Save roylee0704/4a9775fc627fe739c1a4ec2d9c19d6bb to your computer and use it in GitHub Desktop.
Save roylee0704/4a9775fc627fe739c1a4ec2d9c19d6bb to your computer and use it in GitHub Desktop.
python prehash implementation of tuple type. (simplified version)
def hash(tuple):
mult = 1000003
x = 0x345678
for index, item in enumerate(tuple):
x = ((x ^ hash(item)) * mult) & (1<<32)
mult += (82520 + (len(tuple)-index)*2)
return x + 97531
@MartinThoma
Copy link

Do you know where the numbers come from? For example, why is 97531 added? Why not 97530 or 97529? Why not 13933?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment