排序列表<>中SortedDictionary<>和字典<> [英] SortedList<>, SortedDictionary<> and Dictionary<>

查看:88
本文介绍了排序列表<>中SortedDictionary<>和字典<>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我觉得排序列表< TKEY的,TValue> SortedDictionary< TKEY的,TValue> 词典< TKEY的,TValue> 实现相同的接口。


  1. 我们应该何时选择排序列表 SortedDictionary 词典

  2. 是什么排序列表 SortedDictionary 在应用方面?
  3. 之间的区别

解决方案

  1. 当超过任两个的元件进行迭代,该元素将被排序。并非如此,词典< T,V方式>


  2. MSDN 地址排序列表℃之间的差异;吨,V> SortedDictionary< T,V>



  

的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> and Dictionary<TKey, TValue> implement the same interfaces.

  1. When should we opt for SortedList and SortedDictionary over Dictionary?
  2. What is the difference between SortedList and SortedDictionary in terms of application?

解决方案

  1. When iterating over the elements in either of the two, the elements will be sorted. Not so with Dictionary<T,V>.

  2. MSDN addresses the difference between SortedList<T,V> and SortedDictionary<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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆