Associative value order

H. S. Teoh via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Aug 6 10:59:47 PDT 2014


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

-- 
One Word to write them all, One Access to find them, One Excel to count
them all, And thus to Windows bind them. -- Mike Champion


More information about the Digitalmars-d-learn mailing list