I'm looking for a data structure that is able to handle concurrency well (as removal & add from multiple threads will happen), and that allows me to map quickly (O(1)) from a hashed key to the corresponding object.
I also have to be able to retrieve X elements at random from this data structure.
I started with a Set, but oddly enough there is no ConcurrentSet implementation and I want to retrieve the reference to my object, as I want to do things with it.
I'm currently having a ConcurrentDictionary that maps an int (the hashed value) to the object. This seems to work fine for the first requirements, but this is not convenient at all for picking elements at random. I've thought about converting the values to an array and picking at random from this, but I don't think this would fit in term of complexity and memory.
Is there a way to do this ? Or another approach to this problem that would allow me to have good performances to map objects concurrently and pick some at random ?