google::sparse_hash_map<const char*, unsigned long, stdext::hash_compare<const char*>> MyHash;
MyHash["Pizza"] = 42;
if(!MyHash["Pizza"]){
//Pizza is not in the table!
}else{
//Pizza is in the table!
}
google::sparse_hash_map<const char*, unsigned long, stdext::hash_compare<const char*>> MyHash;
MyHash["Pizza"] = 42;
if(!MyHash["Pizza"]){
//Pizza is not in the table!
}else{
//Pizza is in the table!
}
Quote:Original post by Foofles
Thanks for the reply :)
Hmmm that didn't occur to me before. I did try std::string instead but I'm still having the same problem.
This may sound silly but I'm not even sure what stdext::hash_compare does... it's a templated class buried in templated classes. So I'm not sure what ultimately happens when it gets to the const char * or std::string.
Is there a way to use my own compare function?
struct eqstr{ bool operator()(const char* s1, const char* s2) const { return strcmp(s1, s2) == 0; }};google::sparse_hash_map<const char*, unsigned long, stdext::hash_compare<const char*, eqstr>> MyHash;
Quote:Original post by the_edd
Try!
FWIW, I've had good experiences with boost's unordered_map.
Quote:Original post by Foofles
I've been staring at that documentation page for days, tried that page's eqstr function and everything else on it as well. Nothing seems to work!
Quote:Edit: OOps. Here I was so confident I had solved the problem. I haven't. Any advice on hash_map , google::sparse_hash_map or unordered_map is still greatly appreciated. :)