I understand that tbb::concurrent_unordered_multimap should behave like std::unordered_multimap if I use only one thread. However, this is not the case in this example:
#include "tbb/concurrent_unordered_map.h" #include <iostream> #include <unordered_map> struct myhash { size_t operator()(const int& a) const { return 1; } }; int main() { tbb::concurrent_unordered_multimap<int, int, myhash> tbbidx; std::unordered_multimap<int, int, myhash> stdidx; for(int i = 0; i < 100; ++i) { tbbidx.insert(std::make_pair(i % 10, i)); stdidx.insert(std::make_pair(i % 10, i)); } std::cout << "tbb size " << tbbidx.size() << std::endl; std::cout << "tbb count " << tbbidx.count(0) << std::endl; std::cout << "std size " << stdidx.size() << std::endl; std::cout << "std count " << stdidx.count(0) << std::endl; }
The result is the following:
tbb size 100 tbb count 1 std size 100 std count 10
If I remove myhash , I get the correct result. However, the way I understand hashmaps is that a terrible hash function should only affect performance and not correctness if the function returns the same value if x==y .
c ++ hashmap unordered-map tbb
mrks
source share