#include #include "l3utilities/l3stringhashmap.hpp" using namespace std; int main() { // test hashmap l3string test="bla"; float * test2 = new float(8.); l3stringhashmap myhashmap; cout << "Hashmap size: " << myhashmap.size() << endl; // insert an element myhashmap.insert(test,test2); cout << "Hashmap size: " << myhashmap.size() << endl; // there's an iterator l3stringhashmap::iterator hashiter=myhashmap.begin(); cout << "The first element contains " << hashiter->first << ", " << *(hashiter->second) << endl; if (*(hashiter->second) != *test2) return 1; float * val; // lookup(key, value&) allows you to find a value corresponding to a key cout << "Search for " << test << ": " << myhashmap.lookup(test,val) << ". Yields: " << *val << endl; if (*val != *test2) return 2; // there's also a lookup that returns an iterator cout << *((myhashmap.lookup(test))->second) << " is the value corresponding to key " << test << endl; if (*((myhashmap.lookup(test))->second) != *test2) return 3; // insert another element l3string buh = "buh"; float * nine = new float(9.); myhashmap.insert(buh,nine); // new size: cout << "After new insert the size is " << myhashmap.size() << endl; if (myhashmap.size() != 2) return 4; // erase the first element we inserted (can also erase using iterator // as an argument) cout << "Erase first inserted element: " << myhashmap.erase(test) << endl; cout << "After erase the size is " << myhashmap.size() << endl; // what's left? - reset iterator hashiter = myhashmap.begin(); cout << "The first element now contains " << hashiter->first << ", " << *(hashiter->second) << endl; if (*(hashiter->second) != *nine) return 5; // Now clear myhashmap.clear(); cout << "After clear the size is " << myhashmap.size() << endl; cout << "Is the table empty? " << myhashmap.empty() << endl; if (!myhashmap.empty()) return 6; return 0; }