forked from haskell-unordered-containers/hashable
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Try different methods of hashing integers.
Preliminary results on my laptop: Status quo (id): 9 ns Wang 32-bit (best): 12 Jenkins 32-bit: 13 Wang 64-bit: 14 SipHash 32-bit: 33 SipHash 64-bit: 36
- Loading branch information
Showing
4 changed files
with
115 additions
and
7 deletions.
There are no files selected for viewing
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
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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,46 @@ | |||
#include <stdint.h> | |||
|
|||
uint32_t hash_wang_32(uint32_t a) | |||
{ | |||
a = (a ^ 61) ^ (a >> 16); | |||
a = a + (a << 3); | |||
a = a ^ (a >> 4); | |||
a = a * 0x27d4eb2d; | |||
a = a ^ (a >> 15); | |||
return a; | |||
} | |||
|
|||
uint64_t hash_wang_64(uint64_t key) | |||
{ | |||
key = (~key) + (key << 21); // key = (key << 21) - key - 1; | |||
key = key ^ ((key >> 24) | (key << 40)); | |||
key = (key + (key << 3)) + (key << 8); // key * 265 | |||
key = key ^ ((key >> 14) | (key << 50)); | |||
key = (key + (key << 2)) + (key << 4); // key * 21 | |||
key = key ^ ((key >> 28) | (key << 36)); | |||
key = key + (key << 31); | |||
return key; | |||
} | |||
|
|||
uint32_t hash_jenkins_32a(uint32_t a) | |||
{ | |||
a = (a+0x7ed55d16) + (a<<12); | |||
a = (a^0xc761c23c) ^ (a>>19); | |||
a = (a+0x165667b1) + (a<<5); | |||
a = (a+0xd3a2646c) ^ (a<<9); | |||
a = (a+0xfd7046c5) + (a<<3); | |||
a = (a^0xb55a4f09) ^ (a>>16); | |||
return a; | |||
} | |||
|
|||
uint32_t hash_jenkins_32b(uint32_t a) | |||
{ | |||
a -= (a<<6); | |||
a ^= (a>>17); | |||
a -= (a<<9); | |||
a ^= (a<<4); | |||
a -= (a<<3); | |||
a ^= (a<<10); | |||
a ^= (a>>15); | |||
return a; | |||
} |
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
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