Thread overview | |||||
---|---|---|---|---|---|
|
September 02, 2010 D2 Associative Arrays keys has a bug | ||||
---|---|---|---|---|
| ||||
private import std.stdio; static ubyte[] data = [1, 3, 5, 7, 9, 7, 5]; void main() { int[ubyte] set; foreach(e; data) set[e]++; //foreach(k, v; set) std.stdio.writef("%d: %d ", k, v); foreach(e; set.keys.sort) std.stdio.writef("%d ", e); //foreach(e; set.values) std.stdio.writef("%d ", e); } I expect result: 1 3 5 7 9 But result will be: 0 0 0 1 5 or something else, which not equals expaect result. |
September 02, 2010 Re: D2 Associative Arrays keys has a bug | ||||
---|---|---|---|---|
| ||||
Posted in reply to soarowl | soarowl:
> I expect result: 1 3 5 7 9
> But result will be: 0 0 0 1 5 or something else, which not equals expaect result.
You are right, there's a bug in the AA when not int keys are used:
import std.stdio: writeln;
ubyte[] data = [1, 3, 5, 7, 9, 7, 5];
void main() {
int[ubyte] set;
foreach (x; data)
set[x]++;
writeln(set.keys);
}
I think there is already a bug report about this. It's an important bug, makes AAs partially useless.
For your next bug reports in "freeform" like this one it is better to use D.learn newsgroup.
Bye,
bearophile
|
September 02, 2010 Re: D2 Associative Arrays keys has a bug | ||||
---|---|---|---|---|
| ||||
Posted in reply to soarowl | On Thu, 02 Sep 2010 06:28:14 -0400, soarowl <soarowl@yeah.net> wrote: > private import > std.stdio; > > static ubyte[] data = [1, 3, 5, 7, 9, 7, 5]; > > void main() > { > int[ubyte] set; > foreach(e; data) set[e]++; > //foreach(k, v; set) std.stdio.writef("%d: %d ", k, v); > foreach(e; set.keys.sort) std.stdio.writef("%d ", e); > //foreach(e; set.values) std.stdio.writef("%d ", e); > } > > > > I expect result: 1 3 5 7 9 > But result will be: 0 0 0 1 5 or something else, which not equals expaect result. http://d.puremagic.com/issues/show_bug.cgi?id=4201 -Steve |
Copyright © 1999-2021 by the D Language Foundation