/////////////////////////////////////////////////////////// //! rcsid="$Id: WordFreq.cc,v 1.6 2000/04/07 12:10:47 ees1cg Exp $" // Test arbitary hash. #include "amma/String.hh" #include "amma/HashIter.hh" #include "amma/HashAR.hh" #include //: Word Count // Use a class to hold the word count because // we can use the constructor to make sure its // resent to 0 on construction. class WCount { public: WCount(void) : Val(0) {} int Val; }; int main() { cout << "Counting..... \n"; // Creat the table... HashARC WordFreq(21); // Read a the standard input one word at a time. StringC Word; while(!cin.eof()) { cin >> Word; WordFreq[Word.Copy()].Val++; } // Print out the results. cout << WordFreq.Size() << " Unique words found: \n"; // Print out the number of times we've seen each word. for(HashIterC It(WordFreq);It.IsElm();It.Next()) cout << "'" << It.Key().chars() << "' " << It.Data().Val << " \n"; }