SortedDictionary should have GetViewBetween method #26754
Labels
api-needs-work
API needs work before it is approved, it is NOT ready for implementation
area-System.Collections
Milestone
Even though
SortedDictionary
currently storesKeyValuePair
's inside aSortedSet
, it does not provide access toGetViewBetween
.Rational and Usage
SortedDictionary
doesn't have a efficient way to enumerate through batches of elements. Currently you would either have to enumerate through the entire collection and then filter out thekey
range needed or convert theKeyCollection
into aSortedSet
and then useGetViewBetween
. Both the described ways are performance intensive, the first way iterates through unnecessary keys and in the latter method, the conversion toSortedSet
is extremely costly.Or
With the proposed changes, we can leverage
SortedSet
's already implemented methodGetViewBetween
to efficiently enumerate through a range of keys:If you have a large dictionary and only need to iterate through a certain range of keys, this allows you to do that efficiently.
Proposed API
Details and Open Questions
SortedSet
returned byGetViewBetween
is mutable, so any changes may be in conflict with the global dictionary. For example if there is aSortedDictionary
that contains:Now we try to add
1:"11"
to theSortedSet
returned byGetViewBetween
, how do we go about blocking these type of operations?SortedSet
into a immutable one before being returned, however this would be an expensive operationSortedSet
which restricts the allowed operationsThe text was updated successfully, but these errors were encountered: