Sort SortedDictionary is automatically sorted?

I never used SortedDictionary, and I was curious if when adding values ​​to it, for example, in a for loop, the values ​​are automatically sorted when they are added or you need to sort them after they are added.

+3
source share
3 answers

This is done automatically. The dictionary is structured so that it must be properly sorted.

+6
source

Yes. Microsoft discusses SortedDictionary here .

The couple cites this page, which indicates that sorting is automatic:

"The SortedDictionary < (Of < (TKey, TValue > ) > ) O (log n) n - .

O (log n) lookup (), - , .

"SortedDictionary < (Of < (TKey, TValue > ) > ) : O (log n) O (n) SortedList < (Of < (TKey, TValue > ) > )."

, O (log n) , , .

.

+4

There is an invariant in sorted order SortedDictionary, so you do not need to sort it explicitly.

+2
source

Source: https://habr.com/ru/post/1704587/


All Articles