Merge pull request #894 from antmicro/integer-hashing

Better hashing function for integer pairs
This commit is contained in:
gatecat 2022-01-11 16:33:19 +00:00 committed by GitHub
commit 2ab08a872d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -26,8 +26,11 @@ NEXTPNR_NAMESPACE_BEGIN
const int hashtable_size_trigger = 2; const int hashtable_size_trigger = 2;
const int hashtable_size_factor = 3; const int hashtable_size_factor = 3;
// The XOR version of DJB2 // Cantor pairing function for two non-negative integers
inline unsigned int mkhash(unsigned int a, unsigned int b) { return ((a << 5) + a) ^ b; } // https://en.wikipedia.org/wiki/Pairing_function
inline unsigned int mkhash(unsigned int a, unsigned int b) {
return (a*a + 3*a + 2*a*b + b + b*b) / 2;
}
// traditionally 5381 is used as starting value for the djb2 hash // traditionally 5381 is used as starting value for the djb2 hash
const unsigned int mkhash_init = 5381; const unsigned int mkhash_init = 5381;