Is there a sorted map?
cym13 via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Mar 13 06:44:35 PDT 2016
On Sunday, 13 March 2016 at 10:06:24 UTC, stunaep wrote:
> On Sunday, 13 March 2016 at 08:33:43 UTC, Jonathan M Davis
> wrote:
>> On Sunday, March 13, 2016 02:35:27 stunaep via
>> Digitalmars-d-learn wrote:
>>> [...]
>>
>> The closest that we have in Phobos at the moment is
>> RedBlackTree in std.container. Its API is geared towards sets,
>> not maps, but you can get it to work as a map if you define
>> the comparison functions appropriately. Red-black trees are
>> typically used for both sets and maps, so using RedBlackTree
>> in that manner is pretty normal from an implementation
>> perspective, but there's no question that what we really need
>> is a wrapper around it that provides a map API, since it's not
>> terribly user-friendly to use the set API for a map, much as
>> it works.
>>
>> [...]
>
> Wow, thanks!
Note that implementing an (admitedly not perfect) ordered
associative array yourself really isn't much work:
https://github.com/cym13/miscD/blob/master/ordered_aa.d
More information about the Digitalmars-d-learn
mailing list