Created
June 29, 2012 00:16
-
-
Save Kudo/3014898 to your computer and use it in GitHub Desktop.
Hashing two integer to one key
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
static int _HashingSourceInfo(in_addr_t sourceIp, uint32_t sourceId) | |
{ | |
// [0] Cantor pairing function | |
unsigned long long key = (sourceIp + sourceId) * (sourceIp + sourceId + 1) / 2 + sourceId; | |
// Ref: http://elliottback.com/wp/hashmap-implementation-in-c/ | |
// [1] Robert Jenkins 32 bit Mix Function | |
key += (key << 12); | |
key ^= (key >> 22); | |
key += (key << 4); | |
key ^= (key >> 9); | |
key += (key << 10); | |
key ^= (key >> 2); | |
key += (key << 7); | |
key ^= (key >> 12); | |
// [2] Knuth's Multiplicative Hash | |
key = (key >> 3) * 2654435761UL; | |
return key % NF_V9_MAX_SOURCE_ENTRIES; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment