Opened 10 years ago
Closed 10 years ago
#8069 closed Bugs (invalid)
Boost unordered_map iterator bug
Reported by: | Owned by: | Daniel James | |
---|---|---|---|
Milestone: | To Be Determined | Component: | unordered |
Version: | Boost 1.53.0 | Severity: | Problem |
Keywords: | Cc: |
Description
The documentation (http://www.boost.org/doc/libs/1_53_0/doc/html/boost/unordered_map.html) states that mapped_type& operator[](key_type const& k) function can invalidate iterators, but only if the insert causes the load factor to be greater to or equal to the maximum load factor.
In particular, this does not happen. I have written a simple test for this. I compare boost::unordered_map with std::tr1::unordered_map. The former does not guarantuees that iterators are still valid if the insert DOES NOT cause the load factor to be greater to or equal to the maximum load factor.
I run tests with g++4.7.2 and boost 1.53.
Attachments (1)
Change History (6)
by , 10 years ago
comment:1 by , 10 years ago
Component: | None → unordered |
---|---|
Owner: | set to |
comment:2 by , 10 years ago
comment:3 by , 10 years ago
Thanks for the reply.
I don't expect unordered map (keys) following a specific order. I thought that if i insert into an unordered map (e.g int->int) the pairs 0->5, 4->3, 6->9, 2->0 and before the insert of the pair 6->9 take the iterator of map[4 ] then after the insertion of the last pair, i can print out map[4 ], map[6 ] and map[2 ] using the operator ++. This is very useful in case of large unordered maps and multithreading (one thread inserts/looksup elements and another one checks every x seconds (the next) y map's elements, not simultaneously).
comment:4 by , 10 years ago
comment:5 by , 10 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
The iterator is still valid, it's pointing at '0' which is the last element in the container, so your loop only prints out that element. Try printing out all the elements and you can see that the '0' comes last. Remember that these are unordered containers, so there's no guarantee that they'll have any particular order.