int _tmain(int argc, _TCHAR* argv[]) { SimpleHash *sh = new SimpleHash(); sh->AddItem("Adam", 1); sh->AddItem("Brain", 2); sh->AddItem("Claw", 3); sh->AddItem("Duff", 4); sh->AddItem("Enough", 5); sh->AddItem("Enoughisenough", 5); sh->AddItem("Enoughtellme", 111); sh->AddItem("abcdefghikklmnop", 444); cout << sh->GetItem("Duff") << endl; sh->PrintTable(); // use unordered map unordered_map<string, int> phonebook; pair<string, int> mypair; mypair.first = "Adam"; mypair.second = 1; phonebook.insert(mypair); for (auto i = phonebook.begin(); i != phonebook.end(); i++) cout << (*i).first << (*i).second << endl; return 0; }
void distribution(string filename) { SimpleHash* hash = new SimpleHash(100000000); ifstream ifs(filename.c_str()); string line; while (ifs && getline(ifs,line)) { vector<string> k = split(line,'\t'); if (k.size() > 1) hash->increment(k[1].c_str()); } vector<string> keys = hash->keySet(); sort(keys.begin(),keys.end(), [](const string& x, const string& y) { return atoi(x.c_str()) < atoi(y.c_str()); }); for (uint i = 0; i < keys.size(); i++) { cout << keys[i] << "\t" << hash->get(keys[i].c_str()) << endl; } delete hash; }
//Get data from cache std::string getFromCache(std::string url){ return cacheTable.get(url); //return data obtained }
//Add data to cache void addToCache(std::string url, std::string curlData){ cacheTable.set(url, curlData); //put in hash table for cache }