V Hash<V>::get(string key) { int hashed = hash(key); if(!table[hashed].empty()) { // If the spot in the table is not empty... typename list< Entry<V> >::iterator it; // for(it = table[hashed].begin(); it != table[hashed].end(); it++) { // it = Entry obj in list std::cout << hashed << std::endl; if(it->getKey() == key) // And the key is the same... return it->getValue(); // return the value. } } //else the key was not present in the table return (V)0; }
void Hash<V>::print() { std::cout << "[ " ; for(int i = 0; i < height; i++) { std::cout << "{ " ; if(!table[i].empty()){ typename list< Entry<V> >::iterator it; for(it = table[i].begin(); it != table[i].end(); it++) { std::cout << "(" << it->getKey() << ", " << it->getValue() << ") " ; } } std::cout << " }"; if(i+1 != height) std::cout << std::endl; } std::cout << " ]" << std::endl; }
void HashTable<V>::print() { typename list<Entry<V> >::iterator it; cout << endl; for (int i=0; i<SIZE; i++) { cout << i << ": "; list<Entry<V> > &hList = vecTable[i]; for (it=hList.begin(); it!=hList.end(); it++) { cout << "[" << it->getKey() << "," << it->getValue() << "]"; } cout << endl; } cout << endl; return; }