[Issue 653] New: AAs are slightly broken
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Dec 5 09:09:50 PST 2006
http://d.puremagic.com/issues/show_bug.cgi?id=653
Summary: AAs are slightly broken
Product: D
Version: 0.176
Platform: PC
OS/Version: Windows
Status: NEW
Severity: major
Priority: P1
Component: DMD
AssignedTo: bugzilla at digitalmars.com
ReportedBy: mslenc at gmail.com
import std.stdio;
void main()
{
int[uint] aa;
aa[1236448822] = 0;
aa[2716102924] = 1;
aa[ 315901071] = 2;
aa.remove(1236448822);
writefln(aa[2716102924]);
}
========================
The reason it happens is in aaA.d:
int c = key_hash - e.hash;
//...
if (c < 0) {
e = e.left;
} else {
e = e.right;
}
If key_hash is bigger than e.hash + int.max, this will incorrectly determine
that it is in fact smaller. The loop should be changed to something like
while (e) {
if (key_hash == e.hash) {
int c = keyti.compare(pkey, e + 1);
if (c) {
e = c < 0 ? e.left : e.right;
} else {
return cast(void *)(e + 1) + keysize;
}
} else {
e = key_hash < e.hash ? e.left : e.right;
}
}
--
More information about the Digitalmars-d-bugs
mailing list