| 1 |
// Tests the generated perfect hash function. |
| 2 |
|
| 3 |
// The -v option prints diagnostics as to whether a word is in the set |
| 4 |
// or not. Without -v the program is useful for timing. |
| 5 |
|
| 6 |
#include "ace/OS_NS_string.h" |
| 7 |
#include "ace/OS_NS_stdio.h" |
| 8 |
|
| 9 |
static const int MAX_LEN = 80; |
| 10 |
|
| 11 |
// Lookup function. |
| 12 |
const char *in_word_set (const char *str, unsigned int len); |
| 13 |
|
| 14 |
int |
| 15 |
ACE_TMAIN (int argc, ACE_TCHAR *argv[]) |
| 16 |
{ |
| 17 |
int verbose = argc > 1 && ACE_OS::strcmp (argv[1], ACE_TEXT("-v")) == 0 ? 1 : 0; |
| 18 |
char buf[MAX_LEN]; |
| 19 |
|
| 20 |
while (ACE_OS::fgets (buf, sizeof buf, stdin) != 0) |
| 21 |
{ |
| 22 |
size_t len = ACE_OS::strlen (buf) - 1; |
| 23 |
buf[len] = '\0'; |
| 24 |
if (in_word_set (buf, len) && verbose) |
| 25 |
ACE_OS::printf ("in word set %s\n", buf); |
| 26 |
else if (verbose) |
| 27 |
ACE_OS::printf ("NOT in word set %s\n", buf); |
| 28 |
} |
| 29 |
|
| 30 |
return 0; |
| 31 |
} |