Associative value order
Ary Borenszweig via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Wed Aug 6 11:33:15 PDT 2014
On 8/6/14, 2:59 PM, H. S. Teoh via Digitalmars-d-learn wrote:
> On Wed, Aug 06, 2014 at 05:54:23PM +0000, Patrick via Digitalmars-d-learn wrote:
>> I know that there is no prescribed order that the .values array will
>> be sorted in, however I'm curious if the order is deterministic based
>> on keys.
>>
>> If I have two associative arrays with strings for keys and ints for
>> values and they each have an identical set of keys, would the .values
>> property return the values in the same order?
>
> In the current implementation, yes. But I think it's a bad idea to rely
> on that, since a future implementation might no longer do this. (E.g.,
> if we use a different hash collision resolution algorithm that is
> sensitive to insertion order.)
>
> It is probably safest to make an array of keys with .keys, and sort the
> array in the order you want.
>
>
> T
>
Why is a dictionary something built-in the language? Can't it be some
standard library class/struct with syntax sugar for creation? All of
these questions about associative arrays wouldn't exist if the source
code for these operations was available.
(it's probably available, but buried in some C++ code, I guess, on in dmd?)
More information about the Digitalmars-d-learn
mailing list