3 ms·
I suspect the author of the hash function thought this wouldn't add more than 4 bits: h = (h << 4) + *name++; But as one should know, two n-bit numbers ca
by userbinator 4y ago
I suspect the author of the hash function thought this wouldn't add more than 4 bits:
h = (h << 4) + *name++;
But as one should know, two n-bit numbers can create an n+1-bit result when added due to carry.
- dahfizz 4y agoI think the issue is that, when written, a `long` was 32 bits. I would guess the author was familiar with the concept of a carry bit, but they didn't care because the carry bit was discarded by their architecture.
- MaskRay 4y agoI added this sentence to the article, hopefully making it clearer: > If h is in the range [0x0fffff01,0x0fffffff] in the previous iteration, shifting it by 4 and adding *name may make h larger than UINT32_MAX.