Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the order of two same unordered_maps the same?

In other words, if I fill two unordered_map, or unordered_set, objects with exactly the same content and the same hashing function, will iterating over them give the same sequence of key/value pairs?

If so, then what are the conditions for this to hold (e.g. same hashing function, same keys, not necessarily same values).

like image 271
pms Avatar asked Dec 22 '22 00:12

pms


1 Answers

No. There is no requirement, for example, that objects that have the same hash be placed in any particular order. In fact, in general it's impossible for an unordered map to do this because the only information it has access to is the hash value.

like image 138
David Schwartz Avatar answered Dec 24 '22 01:12

David Schwartz