Thanks @MortenStov - to provide your own hash, you can use the overload that takes an IEqualityComparer. Also, I think the most optimal capacity is the one that's implemented, which is is the next prime number that is larger than the entries that you have (or expect). I would guess that the fastest way to initialise a dictionary would be to read your data into KeyValuePairs, and then use the constructor that takes those.
Morten Stov
commented
This was a fantastic blog - thanks. What I really would like to see in the class is:
a simpel way to find an optimal initial capacity
a property for current capacity
a property for number of collisions
And some questions: a) I have an ulong key and could provide a better GetHascode() function. Is that possible? b) is there a faster collection when I only do inserts and lookups? c) is there a "fastest" way to initialize a Dictionary from say a file (Deserialize) d) Is there a guideline to optimal initial capacity such as 2 or 4 times expected number of entries?
2 comments on this page
Thanks @MortenStov - to provide your own hash, you can use the overload that takes an
IEqualityComparer
. Also, I think the most optimal capacity is the one that's implemented, which is is the next prime number that is larger than the entries that you have (or expect).I would guess that the fastest way to initialise a dictionary would be to read your data into
KeyValuePairs
, and then use the constructor that takes those.Morten Stov
This was a fantastic blog - thanks.
What I really would like to see in the class is:
And some questions:
a) I have an ulong key and could provide a better GetHascode() function. Is that possible?
b) is there a faster collection when I only do inserts and lookups?
c) is there a "fastest" way to initialize a Dictionary from say a file (Deserialize)
d) Is there a guideline to optimal initial capacity such as 2 or 4 times expected number of entries?