A faster replacement to the Dictionary

后端 未结 10 876
醉梦人生
醉梦人生 2020-12-08 15:03

I need a fast replacement for the System.Collections.Generic.Dictionary. My application should be really fast. So, the repl

10条回答
  •  长情又很酷
    2020-12-08 15:25

    Dictionaries allow a specified IEqualityComparer comparer. for strings, or other types of A generic compare may not be the best performing. A little ILSpy will show you that it, if take the default == comparer, if your implementation suffers performance you can inject your own IEqualityComparer compairer. In the end the dictionary will compare hash code of what you provide as a key with the existing hash codes in it’s list of entries.

    So if you have specific needs dictionary, perhaps specialize it in FastDictionary class getting to the hascode in a more efficient way,

    In your implementation that would be:

    var dictionary = new Dictionary(StringComparer.Ordinal); 
    

提交回复
热议问题