Absolutely horrible default string hashing
BCS
none at anon.com
Sat May 2 18:59:26 PDT 2009
Hello dsimcha,
> == Quote from bearophile (bearophileHUGS at lycos.com)'s article
>
>> dsimcha:
>>
>>> we first need to fix D's string hashing.<
>>>
>> Ages ago I did suggest this one in the main D newsgroup:
>> http://www.azillionmonkeys.com/qed/hash.html
>> Bye,
>> bearophile
> Yeah, upon further reverse engineering, the way string hashing "works"
> is that it simply adds up all the character code values of the
> characters and returns this sum. The implementation is in
>
> dmd\src\druntime\src\compiler\dmd\typeinfo\ti_AC.d ,
>
> and I've verified this both by reading the code and by implementing
> the same thing myself and seeing if the results are the same. If
> anyone has a better way to do it (which would be almost anything; I've
> written a few myself, although they are extremely simplistic and I'm
> sure anyone who actually knows what they're doing could do even
> better), please submit a patch. I've filed this as bug 2922, because
> it's a severe performance issue, so please submit there.
>
IIRC something like this is common:
hash_t ret = 0;
foreach(c;str) { ret *= SomePrime; ret += c; }
More information about the Digitalmars-d
mailing list