The operations are all clear, but how do they thus provide evenly distributed hashing?
It is not, it is simply an attempt to arrange the bits randomly using the low-order bits, so that you have a reasonably random arrangement of the bits without undue complexity.
Unfortunately, he does not take into account that the shift is actually an expensive esp operation, when there is more than one of them, it can stop the processor pipeline. You can get good results with multiplication and addition, and possibly with one shift, and it will be faster. Multiplication and addition can also improve the randomness of higher bits.
Note: the least significant bits will be ^ between nine bits altogether from the input hash, however the upper bits, esp the highest 4, will not be changed by this process.
This is not such a problem as hash () will either mask the low-order bits (like this here) or use % , which is more expensive, but again only reasonably random low-order bits are needed if the module is not too big.
Why not put a size check and rephrase the block after size ++?
Resizing is expensive and you can add an element and then resize it, but that would mean adding an element that doubles in size (before resizing and as part of the resizing process).
source share