高效Int32 / Uint32排序映射/稀疏数组

时间:2011-03-25 15:39:59

标签: c# .net f# dictionary sparse-array

我正在寻找一个专门的(快速的)Int32 / UInt32排序地图(最好比System.Collections.Generic.SortedDictionary更快,其中K是Int32或UInt32)。

它将被用作稀疏数组,是否有.NET的实现?

1 个答案:

答案 0 :(得分:1)

正如评论中提到的,我会编写一个自定义集合,它使用SortedDictionary和常规Dictionary作为其后备存储。它使您的内存使用量翻倍,但它是查找和迭代的最佳性能。修改会比较慢,但听起来你最感兴趣的是快速访问。

public class DoubleDictionary<TKey, TValue> : IDictionary<TKey, TValue>
{
    private Dictionary<TKey, TValue> backingHash = new Dictionary<TKey, TValue>();
    private SortedDictionary<TKey, TValue> backingTree = new SortedDictionary<TKey, TValue>();

    // For all the modify methods, do it in both.
    // For all retrieval methods, pick one of the backing dictionaries, and just use that one.
    // For example, contains and get on the Hash, iteration on the Tree.
}
相关问题