Bug 3639 – std.conv.to!string(anytype[numeric]) items order seems inconsistent

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2009-12-22T06:03:00Z
Last change time
2015-06-09T01:27:03Z
Assigned to
nobody
Creator
julien

Attachments

IDFilenameSummaryContent-TypeSize
530main.dTest caseapplication/octet-stream1593
531conv-numeric-array.dQuick hackapplication/octet-stream1745
532conv-numeric-array.dQuick hack (const s.length)application/octet-stream1772
533conv-numeric-array.dif (i > 0) result.put(separator);application/octet-stream1748

Comments

Comment #0 by julien — 2009-12-22T06:03:27Z
Created attachment 530 Test case Hello, the order of the items seems inconsistent depending on key type. Please see the attachment. Thank you, Julian.
Comment #1 by andrei — 2009-12-22T06:56:19Z
This is by design - associative arrays don't come out in key sorted order. We could change that behavior but that would make the function slower.
Comment #2 by julien — 2009-12-22T07:29:04Z
Created attachment 531 Quick hack Would this quick hack make the function slower too ? Tested with a few unittests. It removes the segfaults from anytype[ushort] too.
Comment #3 by julien — 2009-12-22T07:30:52Z
Created attachment 532 Quick hack (const s.length) Small correction.
Comment #4 by julien — 2009-12-22T07:32:53Z
Created attachment 533 if (i > 0) result.put(separator);
Comment #5 by andrei — 2009-12-22T08:02:56Z
(In reply to comment #4) > Created an attachment (id=533) [details] > if (i > 0) result.put(separator); The code assumes the set of numeric keys is contiguous, which is untrue for most associative arrays. For example, trying the code with [5:"a", 100:"b"] will fail.
Comment #6 by julien — 2009-12-22T08:16:07Z
Right. Back to slow indexes sorting. Thank you, Julian.