-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Shouldn't there be a SortedList<T>?
#126958
-
I was looking at SortedList and I noticed that it actually is a kind of Dictionary, the difference being that a SortedList allows duplicate and null "keys", whilst a Dictionary does not.
But for use cases where the key and the value are the same element, the SortedList uses more memory, as it allocates arrays for both keys and values. A SortedList<T> would be more efficient. Shouldn't there be one?
I was unsure of opening an issue for this, so I started as a discussion.
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 2 comments 2 replies
-
You can actually use SortedSet<T>.
Beta Was this translation helpful? Give feedback.
All reactions
-
SortedSet<T> doesn't allow repeated items and doesn't have indexes...
Beta Was this translation helpful? Give feedback.
All reactions
-
In that case, List<T> with BinarySearch would be the common practice.
Beta Was this translation helpful? Give feedback.
All reactions
-
If you feel like there should be an explicit SortedList<T> to avoid the overhead of SortedList<T, T> or SortedList<T, byte> then feel free to open a proposal.
There's always one more collection type that could be exposed and most of them could be provided by external libraries instead. It being in the core libraries really depends on need/demand.
Beta Was this translation helpful? Give feedback.