# Astraya

Member

2

1. ## CRC32 of uint64 in uint32

Hello, I take a look at the hash function of Unreal Engine 4 on github. I do not understand a special case for int64 and uint64. inline uint32 GetTypeHash( const uint64 A ) { return (uint32)A+((uint32)(A>>32) * 23); } inline uint32 GetTypeHash( const int64 A ) { return (uint32)A+((uint32)(A>>32) * 23); } What I do not understand is how and why it's works? I can't find any algorithm or trick like that on internet, The std for long long and unsigned long run the murmur hash for thoses types. Can anybody can explain me or redirect me to a link that explain that? Why adding the low with the high part * 23 is relevant? why 23? Thank you very much, Best Regards,
2. ## CRC32 of uint64 in uint32

Thank you, I see. I make some research about hash combine and prime number in hash distribution. Multiplying by a prime number performs a better distribution and reduce collision has your just told me. Then what I did not understand was the addition... Then I understand that Unreal Engine 4 except that integer are two's complement so addition is a logical OR. Logical OR is a possible way to combine hash but the best for mathematical point of view is an XOR like Java do. So If i'm right inline uint32 GetTypeHash( const uint64 A ) { return (uint32)A ^ ((uint32)(A>>32) * 23); } has less collision than inline uint32 GetTypeHash( const uint64 A ) { return (uint32)A+((uint32)(A>>32) * 23); } Does this is correct for you gamedev programmer's ? Note1: This is perfectly explains in the tab here https://www.javamex.com/tutorials/collections/hash_function_guidelines.shtml This also means that multiplying by 31 (33 as it say is not a prime) is better than 23.