Tools.h++ Manual

104011 Tandem Computers Incorporated 13-7
13
13.5 A more complicated example
Here's another example, this one involving a hashing dictionary.
Program input:
How much wood could a woodchuck chuck if a woodchuck
could chuck wood ?
#include <rw/tvhdict.h>
#include <rw/cstring.h>
#include <rstream.h>
#include <iomanip.h>
class Count { // 1
int N;
public:
Count() : N(0) { } // 2
int operator++() { return ++N; } // 3
operator int() { return N; } // 4
};
unsigned hashString ( const RWCString& str ) // 5
{ return str.hash(); }
main() {
RWTValHashDictionary<RWCString,Count> map(hashString); // 6
RWCString token;
while ( cin >> token ) // 7
++map[token]; // 8
RWTValHashDictionaryIterator<RWCString,Count> next(map);// 9
cout.setf(ios::left, ios::adjustfield); //10
while ( ++next ) //11
cout << setw(20) << next.key()
<< " " << setw(10) << next.value() << endl; //12
return 0;
}