getHash inconsistency
H. S. Teoh
hsteoh at quickfur.ath.cx
Tue Mar 20 06:38:10 PDT 2012
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
More information about the Digitalmars-d
mailing list