我想换我的头周围的数据结构是最有效和何时/何使用哪些。
I'm trying to wrap my head around which data structures are the most efficient and when / where to use which ones.
现在,这可能是因为我根本就不懂结构不够好,但如何从一个 ILookup(键,...)不同词典(键,列表(...的)的)?
Now, it could be that I simply just don't understand the structures well enough, but how is an ILookup(of key, ...) different from a Dictionary(of key, list(of ...))?
也将在那里我想使用 ILookup 和地点会是在程序速度/内存/数据访问等?
Also where would I want to use an ILookup and where would it be more efficient in terms of program speed / memory / data accessing, etc?
推荐答案二显著差异:
- 查找是不可改变的。耶:)(至少,我认为具体的查找类是不可变的,而 ILookup 接口没有提供任何变异的成员,有可以的是其他可变实现的,当然。)
- 当你查找一个关键这是不是在查找present,你会得到一个空的顺序背,而不是 KeyNotFoundException 。 (因此没有 TryGetValue ,AFAICR。)
- Lookup is immutable. Yay :) (At least, I believe the concrete Lookup class is immutable, and the ILookup interface doesn't provide any mutating members. There could be other mutable implementations, of course.)
- When you lookup a key which isn't present in a lookup, you get an empty sequence back instead of a KeyNotFoundException. (Hence there's no TryGetValue, AFAICR.)
他们可能是在效率等同 - 查找可能使用词典< TKEY的,GroupingImplementation< TValue>> 的场景,例如落后。根据您的要求二者之间做出选择。我个人而言,查找通常是一个比一个更适合词典< TKEY的,列表与LT; TValue>> ,主要是由于上面的第一个两分。
They're likely to be equivalent in efficiency - the lookup may well use a Dictionary<TKey, GroupingImplementation<TValue>> behind the scenes, for example. Choose between them based on your requirements. Personally I find that the lookup is usually a better fit than a Dictionary<TKey, List<TValue>>, mostly due to the first two points above.
请注意,作为一个实现细节,具体落实 IGrouping&LT;,&GT; 这是用于数值工具的IList&LT; TValue&GT; ,这意味着它的效率与 COUNT(),的ElementAt()等。
Note that as an implementation detail, the concrete implementation of IGrouping<,> which is used for the values implements IList<TValue>, which means that it's efficient to use with Count(), ElementAt() etc.
更多推荐
查找()和字典之间的差异(名单())
发布评论