Created
October 16, 2012 09:18
-
-
Save titanjer/3898250 to your computer and use it in GitHub Desktop.
Jenkins Hash
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 characters
def jenkins_32bits(key): | |
xf = 0xFFFFFFFF | |
key = (key+0x7ed55d16) + (key<<12); key = key&xf | |
key = (key^0xc761c23c) ^ (key>>19); key = key&xf | |
key = (key+0x165667b1) + (key<<5); key = key&xf | |
key = (key+0xd3a2646c) ^ (key<<9); key = key&xf | |
key = (key+0xfd7046c5) + (key<<3); key = key&xf | |
key = (key^0xb55a4f09) ^ (key>>16); key = key&xf | |
return key; | |
def test(min, max): | |
d = redis.StrictRedis(host='localhost', port=6379, db=0) | |
for i in xrange(min, max): | |
h = jenkins_32bits(i) | |
if d.exists(h): | |
print i, d.get(h) | |
d.set(h, i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment