Is it possible to define a fixed size unordered_map
?
Looking at the member functions, there is no resize()
similar to std::vector
and std::list
. Also, google didn't help me.
By default, unordered_map containers have a max_load_factor of 1.0.
In libc++ sizeof map is 24 whereas sizeof unordered_map is 40.
From a logical standpoint, sorting an unordered container makes no sense. It's unordered. And the complexity guarantees that unordered_map is able to achieve require a very specific ordering that you shouldn't be, and aren't, allowed to mess with.
As I know, std::unordered_map is used for fast access to elements. This achieves by storing and comparing the key hash instead of the key itself. Also, unordered means that the elements in it are not sorted.
Yes, it is possible but there is no such map in the STL. What you can do is write your own class containing an std::array< std::pair<Key, Value>, N>
and provide most of the find()
, insert()
functionality using std::hash
yourself. If you use a std::vector< std::pair<Key, Value> >
as data member, you could even have a resize()
function to only expand the table explicitly, but not implicitly after an insert()
.
An important thing to realize is that you also need to provide a way to iterate over the various elements, in order to satisfy all the container requirements. Typically this is done by having auxiliary data that implements a linked list over all the stored elements.
One issue you need to resolve, however, is which replacement policy you use to replace items if your array is full. The std::unorderd_map
uses so-called chaining, with -for each entry- a dynamically sized bucket (with at least forward iteration, so at least equivalent to forward_list
). Most chess programs have a fixed-size hash table with a replacement policy to always replace an item if a particular table entry is already occupied.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With