Is there any way to force `Dictionary` to resize upon key collision?

I'm in a situation where I'd like to use a dictionary where each bucket should have at max 1 value. If I'm inserting a KV pair into the dictionary and there's a collision, it should resize recursively until there are no collisions.

Context:
Insertion speed and memory occupied by the dictionary don't matter (within reason). The dictionary will be loaded one time upon startup of my app, and then never written to again.
Read speed should be very fast, and consistently fast. This is why I'd like to avoid linear probing if possible.

Is this possible? Am I using the wrong data structure entirely? Would I be better off implementing a dictionary with the properties I want myself?

I think you are better off writing your own Hash table implementation with a hash function tuned to your data, especially if it forces zero-collision mapping through brute-force techniques.

It sounds like what you want is a precomputed perfect hash: Generating Perfect Hash Functions | Dr Dobb's

2 Likes

Thanks for your help! I'll give that a shot