# include # include # include "icecream.C" # include "string.C" # include "rstream.h" # include "rstream.c" unsigned int hf(const iceCreamRecord & x) { string name(x.name()); return name[2] - 'a'; } # include "openHashTable.h" # include "openHashTable.c" template class openHashTableIterator : public rstreamIterator { public: openHashTableIterator(openHashTable &); virtual int operator ++ (); }; template openHashTableIterator::openHashTableIterator(openHashTable & t) : rstreamIterator(t.rfile) { // nothing more } template int openHashTableIterator::operator ++() { if (rstreamIterator::operator ++() == 0) return 0; if (isEmpty(operator()())) return operator ++ (); return 1; } openHashTable hashtab("/tmp/openHashTableFile", hf); openHashTableIterator itr(hashtab); string iceCreamFlavor(const string name) { // make entry with name but no known flavor iceCreamRecord rec(name, ""); // read database if (hashtab.includes(rec)) return rec.flavor(); return "not in database"; } int main() { for (itr.init(); ! itr; itr++) { cout << " for " << itr().name() ; cout << " flavor " << itr().flavor() << "\n"; } # if 0 cout << "for fred " << iceCreamFlavor("fred") << '\n'; cout << "for alex " << iceCreamFlavor("alex") << '\n'; cout << "for amanda " << iceCreamFlavor("amanda") << '\n'; cout << "for albert " << iceCreamFlavor("albert") << '\n'; cout << "for alice " << iceCreamFlavor("alice") << '\n'; cout << "for amy " << iceCreamFlavor("amy") << '\n'; cout << "for anne " << iceCreamFlavor("anne") << '\n'; cout << "for alfred " << iceCreamFlavor("alfred") << '\n'; cout << "for andy " << iceCreamFlavor("andy") << '\n'; cout << "for arthur " << iceCreamFlavor("arthur") << '\n'; cout << "for abraham " << iceCreamFlavor("abraham") << '\n'; cout << "deleting amy \n "; hashtab.remove(iceCreamRecord("amy","")); cout << "for fred " << iceCreamFlavor("fred") << '\n'; cout << "for alex " << iceCreamFlavor("alex") << '\n'; cout << "for amanda " << iceCreamFlavor("amanda") << '\n'; cout << "for albert " << iceCreamFlavor("albert") << '\n'; cout << "for alice " << iceCreamFlavor("alice") << '\n'; cout << "for amy " << iceCreamFlavor("amy") << '\n'; cout << "for anne " << iceCreamFlavor("anne") << '\n'; cout << "for alfred " << iceCreamFlavor("alfred") << '\n'; cout << "for andy " << iceCreamFlavor("andy") << '\n'; cout << "for arthur " << iceCreamFlavor("arthur") << '\n'; cout << "for abraham " << iceCreamFlavor("abraham") << '\n'; # endif return 0; }