boost::unordered_map is... ordered?

Posted by Thanatos on Stack Overflow See other posts from Stack Overflow or by Thanatos
Published on 2010-06-14T18:28:39Z Indexed on 2010/06/14 18:42 UTC
Read the original article Hit count: 222

Filed under:
|

I have a boost::unordered_map, but it appears to be in order, giving me an overwhelming feeling of "You're Doing It Wrong". Why is the output to this in order? I would've expected the underlying hashing algorithm to have randomized this order:

#include <iostream>
#include <boost/unordered_map.hpp>

int main()
{
    boost::unordered_map<int, int> im;

    for(int i = 0; i < 50; ++i)
    {
        im.insert(std::make_pair(i, i));
    }

    boost::unordered_map<int, int>::const_iterator i;

    for(i = im.begin(); i != im.end(); ++i)
    {
        std::cout << i->first << ", " << i->second << std::endl;
    }

    return 0;
}

...gives me...

0, 0
1, 1
2, 2
...
47, 47
48, 48
49, 49

© Stack Overflow or respective owner

Related posts about c++

Related posts about boost