排序列表&LT;&gt;中SortedDictionary&LT;&GT;和字典&LT;&GT; [英] SortedList<>, SortedDictionary<> and Dictionary<>
问题描述
我觉得排序列表&LT; TKEY的,TValue&GT;
SortedDictionary&LT; TKEY的,TValue&GT;
和词典&LT; TKEY的,TValue&GT;
实现相同的接口。
- 我们应该何时选择
排序列表
和SortedDictionary
在词典
? - 是什么
排序列表
和SortedDictionary
在应用方面? 之间的区别
-
当超过任两个的元件进行迭代,该元素将被排序。并非如此,
词典&LT; T,V方式&gt;
-
MSDN 地址
排序列表℃之间的差异;吨,V&GT;
和SortedDictionary&LT; T,V&GT;
:
的SortedDictionary(TKEY的,TValue)泛型类是二进制搜索
树为O(log n)的检索,其中n是元件的数量
词典。在这方面,它是类似于排序列表(TKEY的,
TValue)泛型类。这两个类具有相似的对象模型和
都具有O(log n)的检索。其中两个类的区别是
内存使用和插拔速度:
排序列表(TKEY的,TValue)使用比SortedDictionary(TKEY的内存更少,
TValue)。
SortedDictionary(TKEY的,TValue)具有更快的插入和去除
对于未排序的数据操作:O(log n)的,而不是为O(n)为
排序列表(TKEY的,TValue)。
如果该列表是从排序的数据填充全部一次,
排序列表(TKEY的,TValue)比SortedDictionary(TKEY的更快,
TValue)。
块引用>I find that
SortedList<TKey, TValue>
SortedDictionary<TKey, TValue>
andDictionary<TKey, TValue>
implement the same interfaces.
- When should we opt for
SortedList
andSortedDictionary
overDictionary
?- What is the difference between
SortedList
andSortedDictionary
in terms of application?
解决方案
When iterating over the elements in either of the two, the elements will be sorted. Not so with
Dictionary<T,V>
.MSDN addresses the difference between
SortedList<T,V>
andSortedDictionary<T,V>
:
The SortedDictionary(TKey, TValue) generic class is a binary search tree with O(log n) retrieval, where n is the number of elements in the dictionary. In this respect, it is similar to the SortedList(TKey, TValue) generic class. The two classes have similar object models, and both have O(log n) retrieval. Where the two classes differ is in memory use and speed of insertion and removal:
SortedList(TKey, TValue) uses less memory than SortedDictionary(TKey, TValue).
SortedDictionary(TKey, TValue) has faster insertion and removal operations for unsorted data: O(log n) as opposed to O(n) for SortedList(TKey, TValue).
If the list is populated all at once from sorted data, SortedList(TKey, TValue) is faster than SortedDictionary(TKey, TValue).
这篇关于排序列表&LT;&gt;中SortedDictionary&LT;&GT;和字典&LT;&GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!