January 02, 2015 Re: Can the order in associative array change when keys are not midified? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | On Thursday, 1 January 2015 at 18:58:04 UTC, Andrej Mitrovic via Digitalmars-d-learn wrote:
> On 1/1/15, Tobias Pankrath via Digitalmars-d-learn
> <digitalmars-d-learn@puremagic.com> wrote:
>> You could implement an OrderedMap!(Key, Value) via
>> RedBlackTree!(Tuple!(Key, Value), (a,b) => a[0] < b[0]).
>
> We could add this as an alias into Phobos or perhaps as just a
> documentation line on the website.
V good point.
This is one of those small frictions that cumulatively raises the cost of adoption for newcomers who are not by nature hackers but want to get stuff done, and yet could be valuable members of the D community over time. For whatever reason, there is some resistance for many people to ask for help in a forum and it is easy to be overwhelmed and give up. Modern people don't have much tolerance for pain, even though that's an essential part of learning and being a developer. And compare python where you have OrderedDict and a search will find many examples of how to use it.
I agree with comments about readability of library functions, but maybe also worth extending hints and tips for common patterns / code fragments.
What is the protocol for contributing to the wiki? Can one just edit it ?
|
January 02, 2015 Re: Can the order in associative array change when keys are not midified? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | On Thursday, 1 January 2015 at 18:58:04 UTC, Andrej Mitrovic via Digitalmars-d-learn wrote:
> On 1/1/15, Tobias Pankrath via Digitalmars-d-learn
> <digitalmars-d-learn@puremagic.com> wrote:
>> You could implement an OrderedMap!(Key, Value) via
>> RedBlackTree!(Tuple!(Key, Value), (a,b) => a[0] < b[0]).
>
> We could add this as an alias into Phobos or perhaps as just a
> documentation line on the website.
Will do. Going to submit some documentation PRs anyway.
|
January 02, 2015 Re: Can the order in associative array change when keys are not midified? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Idan Arye | On 1/1/15 7:32 AM, Idan Arye 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?
I would never make that assumption. An AA is free to rehash at any time, for whatever reason.
What I would say is that you can probably safely assume an AA will iterate in the same order as long as it hasn't been changed.
If you need guaranteed ordering, use an array or a RedBlackTree.
-Steve
|
Copyright © 1999-2021 by the D Language Foundation