My understanding is that tbb::concurrent_unordered_multimap
should behave like std::unordered_multimap
if I am using only one thread. However, in this example, it does not:
#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 this:
tbb size 100
tbb count 1
std size 100
std count 10
If I remove myhash
, I get the correct result. The way I understand hashmaps, however, is that a horrible hash function should only affect the performance, not the correctness as long as the function returns the same value if x==y
.
i / 10, i
instead ofi % 10, i
), everything is fine. – Leaguevolatile size_t one = 1;
andreturn one
instead ofreturn 1
? I'm curious if something is being optimized away because all hashes are equal. – Interrelate-O0
. – League