Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does an iterator iterate through boost::unordered_set or boost::unordered_map in the same order as long as the set's unchanged?

Does an iterator iterate through boost::unordered_set or boost::unordered_map in the same order as long as the set or the map is unchanged?

like image 410
Tianyang Li Avatar asked Oct 04 '12 14:10

Tianyang Li


1 Answers

Some implementations of a hash map will reorder the items that hash to the same bin, putting the most recently accessed item at the front of a list, as an optimization. This would change the order. I'm not aware that boost::unordered_map does this, but in the future you might end up substituting std::unordered_map and it will all depend on your compiler's implementation.

like image 116
Mark Ransom Avatar answered Sep 21 '22 03:09

Mark Ransom