What’s the best way to design such a container, which can support randomized value access? but the container has to support other operations, such as insert key/value pairs and remove by key, with the best possible time performance.
One way to do this is to combine hash map with array, but if hash map is used, what’s the best way to do random access of hash map values, i.e., without generating a key.
If you’re talking about data structures, and not existing language support – then you just have to design a data structure to support that.
You can do that, for example, by implementing a hash map which will hold, in addition, an array of pointers to its members. You can then translate random access operators to that array, and maintain it with every insertion or removal (that is of course a general idea, some implementation details omitted).
Some languages support traversing the data structures through iterators. Although looping on an iterator for a random amount of times is not really random access (performance-wise), it will give you the same result in more time.
I would say your question sounds like some algorithms’ coursework homework. Why would you want to do it in the real life? What is the problem you’re trying to solve?
edit
In the comments you phrased the problem as:
My suggestions above hold, but the question is what is the trade-off. If the “best performance” is time-wise, then my suggestion with the array gives you that. If the best performance is memory-wise then the iterating over the tree would give you that, that’s my other suggestion.
In general, when you come to a need to design a new data structure, you need to answer the following questions:
Sometimes you just can’t do in O(1) without additional memory. Sometimes you can do in O(1) with additional O(n) memory, but you can make it with O(lg n) memory if you compromise on O(lg n) time. There are trade offs that you have to make your decision about, I don’t know them.
So my first suggestion (combining a BST or hash with an array of pointers to its nodes) does all the operations of the BST (map) or hash with the standard complexity of BST/hash operations, and all the read operations of array with the standard complexity (i.e.: random access in O(1) time). Write operations of the array will be with complexity of map/hash, and additional memory footprint is O(n).
My second suggestion has no additional memory footprint, but the “random” access is pseudo random: you can just iterate to the point you want instead of directly accessing it. That would make your random access in O(n) while zero additional coding, or wasting memory.
Name of the game? Trade-offs.