Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

9
  • 3
    A Dictionary<TKey, TValue> solves all these problems and can handle collisions . It is based on a hash table and performs lookups with O(1) time complexity. Commented Mar 13, 2022 at 13:47
  • 1
    IMHO you should use Dictionary<ObjectDescriptor, T>. Have you compared the cost of hash collisions with HashCode.Combine ? learn.microsoft.com/en-us/dotnet/api/… Commented Mar 13, 2022 at 13:50
  • If you think that collisions happen too often, you could group your data by key and create a Dictionary<TKey, List<TValue>> instead. And btw, if you do not have a key per se, use a Hashset<T> instead to store unique values. Commented Mar 13, 2022 at 13:55
  • 2
    @OlivierJacot-Descombes That doesn't fix the fundamental problem of hashing collisions and the fact that full comparisons take too long. It sounds like a better hashing function is needed Commented Mar 13, 2022 at 13:58
  • 1
    Don't forget if your objects are immutable to cache the hashcodes Commented Mar 13, 2022 at 14:11