Closed RKleminski closed 4 years ago
Hi, perhaps the SortedSet with a custom comparator is a better fit for your use case. You just work with values and you don't worry about the keys. You will not be able to lookup by ID though.
Anther options is to keep a traditional Map for looking up by ID, and a companion SortedMap with key=Date and value=ID that will be sorted by date.
It might be that I don't understand something basic about the under-the-hood workings of a SortedMap, but why is there no way to have it operate on the basis of values? The comparator operates on keys.
For context, in my use case, I want to store objects in a SortedMap that have multiple fields and are identified by an ID. I previously used OrderedMap, but I find myself in need to ensure sorting by a
date
field. The way the comparator works, I am required to include thedate
in the keys for every object.Is a SortedMap that sorts by value planned as a possible extension, or is there a strong reason to keep this operation only available via .sort functions available to Maps in general?