Created
September 9, 2015 14:23
-
-
Save rjauquet/d1d9f4c4fbb14758d19e to your computer and use it in GitHub Desktop.
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
| import mmh3 | |
| def fnv64(data): | |
| hash_ = 0xcbf29ce484222325 | |
| for b in data: | |
| hash_ *= 0x100000001b3 | |
| hash_ &= 0xffffffffffffffff | |
| hash_ ^= ord(b) | |
| return hash_ | |
| def java(data): | |
| length = len(data) | |
| answer = 0 | |
| i=0 | |
| for c in data: | |
| answer += ord(c) * 31^(length - 1 - i) | |
| i += 1 | |
| return answer | |
| def jauquet(data): | |
| prime = 79087987342985798987987 | |
| shift = 611 | |
| for c in data: | |
| prime = (prime * shift) + ord(c) | |
| return prime | |
| def main(): | |
| wordCount = 109583 | |
| tableSize = wordCount * 2 | |
| murmur_table = [0 for i in range(tableSize)] | |
| fnv_table = [0 for i in range(tableSize)] | |
| java_table = [0 for i in range(tableSize)] | |
| jauquet_table = [0 for i in range(tableSize)] | |
| murmur_collisions = 0 | |
| fnv_collisions = 0 | |
| java_collisions = 0 | |
| jauquet_collisions = 0 | |
| with open('wordsEn.txt') as f: | |
| content = f.readlines() | |
| for word in content: | |
| murmur_temp = mmh3.hash64(word)[1] % tableSize | |
| fnv_temp = fnv64(word) % tableSize | |
| java_temp = java(word) % tableSize | |
| jauquet_temp = jauquet(word) % tableSize | |
| if murmur_table[murmur_temp] is 0: | |
| murmur_table[murmur_temp] = 1 | |
| else: | |
| murmur_collisions += 1 | |
| if fnv_table[fnv_temp] is 0: | |
| fnv_table[fnv_temp] = 1 | |
| else: | |
| fnv_collisions += 1 | |
| if java_table[java_temp] is 0: | |
| java_table[java_temp] = 1 | |
| else: | |
| java_collisions += 1 | |
| if jauquet_table[jauquet_temp] is 0: | |
| jauquet_table[jauquet_temp] = 1 | |
| else: | |
| jauquet_collisions += 1 | |
| print 'murmur_collisions', murmur_collisions | |
| print 'fnv_collisions', fnv_collisions | |
| print 'java_collisions', java_collisions | |
| print 'jauquet_collisions', jauquet_collisions | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment