Fibonacci Hashing: The Optimization That the World Forgot
If you need to map a uniform b-bit integer x into the [0, n) range, using ((x * n) >> b) will work just as well as the modulo in terms of (quasi-)even distribution, and it avoids integer division.<p>The idea is just to imagine x as a b-bit fixed-point uniformly random number in [0, 1), and rescaling it by multiplication.<p>This works great for hash tables whose size is not a power of 2, provided that you start from a good hash function.