ArrayBoundsError for associative array operation
Egor Starostin
egorst at gmail.com
Tue Dec 5 02:34:22 PST 2006
I have a testcase (simplified from real data) when access to
associative array by existing key produces ArrayBoundsError.
Here it is:
***
import std.stdio;
void main() {
struct SKey {
int dep;
char[] hv;
uint toHash() {
uint hkey;
for (int i=0;i<hv.length;i++) {
hkey = hkey*10 + (hv[i]-'0');
}
return hkey + dep;
}
}
int[SKey] aa;
SKey ck;
// populate aa (in that exact order)
ck.dep=0; ck.hv="1236448822";
aa[ck] = 1;
ck.dep=0; ck.hv="2716102924";
aa[ck] = 1;
ck.dep=0; ck.hv="315901071";
aa[ck] = 1;
// remove one key
ck.dep=0; ck.hv="1236448822";
aa.remove(ck);
// get an error ArrayBoundsError
// while trying to access by one of remaining keys
ck.dep=0; ck.hv="2716102924";
writefln(aa[ck]);
}
***
Why I get an ArrayBoundsError for existing key?
Is this a bug in D? If yes -- can somebody suggest a workaround?
--
Egor
More information about the Digitalmars-d
mailing list