GNU bug report logs -
#50093
djb2 correction
Previous Next
Reported by: Jim Meyering <jim <at> meyering.net>
Date: Tue, 17 Aug 2021 10:33:02 UTC
Severity: normal
Done: Paul Eggert <eggert <at> cs.ucla.edu>
Bug is archived. No further changes may be made.
Full log
Message #19 received at 50093-done <at> debbugs.gnu.org (full text, mbox):
On 8/17/21 7:50 PM, Alex Murray wrote:
> How about letting the compiler choose which prime to use? - something like the following:
>
> #define H15_PRIME (unsigned long long)5381
> #define H32_PRIME (unsigned long long)3657500101
> #define H64_PRIME (unsigned long long)4123221751654370051
> size_t h = H64_PRIME <= SIZE_MAX ? H64_PRIME : H32_PRIME <= SIZE_MAX ? H32_PRIME : H15_PRIME;
That's equivalent to the patch I suggested; on my platform it even
generates the same machine code. It's better to avoid macros when that's
easy, as is the case here.
I installed the patch, except with uint_fast64_t instead of unsigned
long long int as that's a better type for the 64-bit constants in
question. (In case you're wondering what that "_fast" is doing there,
POSIX and the C standard guarantee the existence of uint_fast64_t but
not of uint64_t, as a concession to Unisys mainframes where long long is
72 bits.)
This bug report was last modified 3 years and 281 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.