I'm looking for a specialized (and fast) Int32/UInt32 sorted map (that preferably is faster then System.Collections.Generic.SortedDictionary where K is either Int32 or UInt32).
I开发者_运维百科t's going to be used as a sparse array, are there any implementations for .NET?
As was mentioned in the comments, I'd write a custom collection that uses both a SortedDictionary and a regular Dictionary as its backing store. It doubles your memory usage, but it's the best performance for lookups and iteration. Modifications will be slower, but it sounds like you're mostly interested in fast accesses.
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.
}
精彩评论