apt-get install sparsehash #include <iostream> #ifdef __GNUC__ #include <ext/hash_map> #else #include <hash_map> #endif using namespace std; namespace std { using namespace __gnu_cxx; } int main() { std::hash_map<const char*,int> hm; hm["str1"] = 1; hm["str2"] = 2; hm["str3"] = 0; hm["str3"] = 3; cout << "str1-->" << hm["str1"] << endl; cout << "str3-->" << hm["str3"] << endl; return 0; } google-sparsehash http://code.google.com/p/google-sparsehash/ #include <iostream> #include <google/sparse_hash_map> #include <ext/hash_map>//<---------------------------this line is important using google::sparse_hash_map; // namespace where class lives by default using std::cout; using std::endl; //using ext::hash; //using tr1::hash; using __gnu_cxx::hash; // or ext::hash, or maybe tr1::hash, depending on your OS struct eqstr { bool operator()(const char* s1, const char* s2) const { return (s1 == s2) || (s1 && s2 && strcmp(s1, s2) == 0); } }; int main() { sparse_hash_map<const char*, int, hash<const char*>, eqstr> months; sparse_hash_map<const char*, int, hash<const char*>, eqstr>::iterator It; months.set_deleted_key(NULL); months["january"] = 31; months["february"] = 28; months["march"] = 31; months["april"] = 30; months["may"] = 31; months["june"] = 30; months["july"] = 31; months["august"] = 31; months["september"] = 30; months["october"] = 31; months["november"] = 30; months["december"] = 31; cout << "september -> " << months["september"] << endl; cout << "april -> " << months["april"] << endl; cout << "june -> " << months["june"] << endl; cout << "november -> " << months["november"] << endl; /* Find and erase */ It = months.find("january"); if (It != months.end()) { cout << "january found" << endl; cout << "erasing january" << endl; months.erase(It); if (months.find("january") == months.end()) cout << "january erased" << endl; else cout << "january NOT erased" << endl; } else cout << "january NOT found" << endl; return 0; }