On Thursday, 1 January 2015 at 13:39:57 UTC, Peter Alexander
wrote:
On Thursday, 1 January 2015 at 13:13:10 UTC, Andrej Mitrovic
via Digitalmars-d-learn wrote:
On 1/1/15, Idan Arye via Digitalmars-d-learn
<digitalmars-d-learn@puremagic.com> wrote:
If I have an associative array and I only modify it's values,
without changing the keys, can I assume that the order won't
change?
Associative arrays are not ordered at all.
See the first note here: http://dlang.org/hash-map.html
The order is unspecified, but an iteration must iterate in
*some* order. The question (if I've understood it correctly),
is whether that order of iteration changes when the keys aren't
changed.
The spec doesn't say anything about this, although I would
expect in practice that the order will not change.
I've added a bug to track this omission from the spec:
https://issues.dlang.org/show_bug.cgi?id=13923
That's right.
My use case is that I have a large AA where the values are
numbers and the keys are strings, and I need to send it over
network again and again. The values constantly change but the
keys should remain the same(after an initial initialization
process), so I don't want to always have to send the keys, which
compose the larger part of the AA's size. If the order is fixed
as long as the keys are fixed I can cache the keys order and send
only the values(without having to sort them each time).