Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
#include <tbb/tbb.h>
#include <tbb/concurrent_hash_map.h>
#include <iostream>
#include <string>
using namespace std;
using namespace tbb;
class VariantHashCompare {
bool ignore_case;
size_t hash(const string& x) const {
size_t h = 0;
for(const char* s = x.c_str(); *s; s++)
h = (h*16777179)^(ignore_case?(size_t) tolower(*s):(size_t) *s);
return h;
bool equal(const string& x, const string& y) const {
if( ignore_case )
return strcasecmp(x.c_str(), y.c_str())==0;
return x==y;
VariantHashCompare(bool ignore_case_) : ignore_case(ignore_case_) {}
typedef concurrent_hash_map<string,int, VariantHashCompare> VariantStringTable;
VariantStringTable CaseSensitiveTable(VariantHashCompare(false));
VariantStringTable CaseInsensitiveTable(VariantHashCompare(true));
int main()
VariantStringTable::accessor a;
CaseSensitiveTable.insert(make_pair("ab", 3));
std::cout << CaseSensitiveTable.find(a, "AB") << std::endl;
CaseInsensitiveTable.insert(make_pair("ab", 3));
std::cout << CaseInsensitiveTable.find(a, "AB") << std::endl;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.