0

This question's answer points to a talk that says unordered_map uses linked lists for its buckets. Is it possible to construct an instance of std::unordered_map that uses std::vectors as the container for its buckets?

DeepDeadpool
  • 1,441
  • 12
  • 36
  • 2
    No, you cannot change `std::unordered_map`. You'd have to write your own or find one that already does. – NathanOliver Mar 12 '18 at 17:31
  • Note that even if you did this, it would have to be something like a vector of pointers to dynamically allocated key-value pairs, not just a vector of pairs, in order to maintain the guarantees of reference invalidation promised by `std::unordered_map`. So you lose out on one of the main benefits of using a vector over a linked list, which is having your values tightly packed in one location in memory. – Benjamin Lindley Mar 12 '18 at 17:41
  • @BenjaminLindley Though, you can provide an allocator to `std::unordered_map` if you want to improve data locality. – François Andrieux Mar 12 '18 at 17:43

0 Answers0