Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

SortedMap with custom comparator

Moderators: larsivi kris

Posted: 10/03/08 08:18:58


I'm trying to use a SortedMap? with an integer as a key and a float as value and would like to sort the Map by the value of the float? Is this even possible? I saw in the API documentation that there is a compareElem function, but how do I override it and how do I invoke it?

The sample from the Wiki isn't very helpful anymore as TreeBag? is deprecated.

thank you very much.


Some thoughts about switching from PHP to D:

Author Message

Posted: 10/03/08 15:41:32

As far as I am aware, SortedMap? is just a red-black tree based map. For this to work, the contents (pairs)) must be sorted by the key. If you want the compare function to compare the values not the keys, isn't this essentially the same as swapping the keys and values in the map?

Not really sure what you're trying to do, so can't really help more..