By chance, I came across this magical hexadecimal number 0x5f3759df
and decided to make a note of it.
Science changes the world, and mathematics changes science.
Last time, I encountered an irrational number, 0.75
, which appeared in the source code of Java HashMap and represents the default load factor. Let me briefly explain the meaning of this value: when the number of elements in the HashMap reaches 0.75 times its capacity (i.e., 12 elements when the capacity is 16), the HashMap will be resized to reduce hash collisions and avoid the degradation of HashMap into a linked list, which significantly increases the query time. As for why this value is 0.75, there is a simple explanation: it is a compromise between improving space utilization and reducing query costs, mainly based on the Poisson distribution, and 0.75 minimizes collisions.