getHash inconsistency

Daniel Murphy yebblies at nospamgmail.com
Tue Mar 20 21:55:49 PDT 2012


"H. S. Teoh" <hsteoh at quickfur.ath.cx> wrote in message 
news:mailman.917.1332250604.4860.digitalmars-d at puremagic.com...
> On Tue, Mar 20, 2012 at 05:07:12PM +1100, Daniel Murphy wrote:
>> "H. S. Teoh" <hsteoh at quickfur.ath.cx> wrote in message
>> news:mailman.910.1332214803.4860.digitalmars-d at puremagic.com...
>> > Is this a bug?
>> >
>> > char[] a = "abc".dup;
>> > const(char)[] b = "abc";
>> > string c = "abc";
>> >
>> > writeln(typeid(a).getHash(&a)); // 12914
>> > writeln(typeid(b).getHash(&b)); // 8503969683799911018
>> > writeln(typeid(c).getHash(&c)); // 12914
>> >
>>
>> Of course.
> [...]
>
> Then the question is, what should be the fix?
>
> Currently, char[] and string have getHash defined in
> rt.typeinfo.ti_Ad.TypeInfo_Aa, which appears to be a custom hashing
> algorithm, whereas const(char)[] uses TypeInfo_Array.getHash, which uses
> rt.util.hash.hashOf. Which one should be used?
>
>
> T
>
> -- 
> Life would be easier if I had the source code. -- YHL

I assume the custom hashing routine is better/faster?  If so, that one.  I'd 
assume that getHash not working the same for const strings is an oversight. 




More information about the Digitalmars-d mailing list