问题描述
、SortedDictionary
) 有关不同情况下不同操作的性能的详细信息.这是一个很好的总结(来自 SortedDictionary
文档):
Look at the MSDN docs for each of them (SortedList
, SortedDictionary
) for details of the performance for different operations in different situtations. Here's a nice summary (from the SortedDictionary
docs):
SortedDictionary
泛型类是一个二叉搜索树O(log n) 检索,其中 n 是字典中的元素数.在这方面,它类似于SortedList
通用班级.两个班级有相似之处对象模型,并且都有 O(log n)恢复.两个班级在哪里不同之处在于内存使用和速度插入和移除:
SortedList
使用较少内存比SortedDictionary
.
SortedDictionary
有更快的插入和移除未排序数据的操作,O(log n)与 O(n) 相反SortedList
.
SortedDictionary<TKey, TValue>
has faster insertion and removal operations for unsorted data, O(log n) as opposed to O(n) for SortedList<TKey, TValue>
.
如果列表一次全部填充来自排序的数据,SortedList
比SortedDictionary
.
If the list is populated all at once from sorted data, SortedList<TKey, TValue>
is faster than SortedDictionary<TKey, TValue>
.
(SortedList
实际上维护一个有序数组,而不是使用树.它仍然使用二分查找来查找元素.)
(SortedList
actually maintains a sorted array, rather than using a tree. It still uses binary search to find elements.)
这篇关于SortedList 和 SortedDictionary 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!