我发现SortedList<TKey, TValue>
SortedDictionary<TKey, TValue>
and Dictionary<TKey, TValue>
实现相同的接口。
- 我们什么时候应该选择
SortedList
and SortedDictionary
over Dictionary
?
- 有什么区别
SortedList
and SortedDictionary
在应用方面?
当迭代两者中的任何一个中的元素时,元素将被排序。情况并非如此Dictionary<T,V>
.
MSDN解决了之间的差异SortedList<T,V>
and SortedDictionary<T,V>
:
SortedDictionary(TKey, TValue) 泛型类是二分查找
树O(log n) 检索,其中 n 是元素的数量
词典。在这方面,它类似于 SortedList(TKey,
TValue) 泛型类。这两个类具有相似的对象模型,并且
两者都有 O(log n) 检索。这两个类的不同之处在于
内存使用和插入和删除速度:
SortedList(TKey, TValue) 使用的内存少于 SortedDictionary(TKey,
T 值)。
SortedDictionary(TKey, TValue) 具有更快的插入和删除速度
未排序数据的操作:O(log n) 而不是 O(n)
排序列表(TKey,TValue)。
如果列表是从排序数据一次性填充的,
SortedList(TKey, TValue) 比 SortedDictionary(TKey,
T 值)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)