home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / GCC / GERLIB_DEV08B.LHA / gerlib / libg++ / etc / ADT-examples / Patmain.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-12  |  1.1 KB  |  60 lines

  1. #ifdef amiga
  2. #include <use_standard_argc_argv.h>
  3. #endif
  4.  
  5. // Tests the Patricia tree
  6.  
  7. #include <stream.h>
  8. #include <stdio.h>
  9. #include <string.h>
  10. #include "Patricia.h"
  11.  
  12. double start_timer (void);
  13. double return_elapsed_time (double);
  14.  
  15. const int MAX_KEY_LEN = 1000;
  16.  
  17. main (int argc, char *argv[])
  18. {
  19.   if (argc != 3)
  20.     {
  21.       cerr << "usage: " << argv [0] << " file1 file2\n";
  22.       return 1;
  23.     }
  24.   else
  25.     {
  26.       if (!freopen (argv [1], "r", stdin))
  27.         {
  28.           perror (argv [0]);
  29.           return 1;
  30.         }
  31.  
  32.       Patricia_Trie trie;
  33.       char key [MAX_KEY_LEN];
  34.  
  35.       while (gets (key)) 
  36.         trie.insert (key, 0);
  37.  
  38.       fclose (stdin);
  39.       if (! freopen (argv [2], "r", stdin))
  40.         {
  41.           perror (argv [0]);
  42.           return 1;
  43.         }
  44.  
  45.       start_timer ();
  46.  
  47.       while (gets (key))
  48.         {
  49.           Trie_Record *t = trie.find (key);
  50.           cout << key << ": " << (! strcmp (key, t->get_key ()) ? "is found!\n" : "is not found!\n");
  51.         }
  52.       
  53.       double Elapsed_Time = return_elapsed_time (0.0);
  54.       cout << "Time = " << Elapsed_Time << "\n";
  55.       fclose (stdin);
  56.       return 0;
  57.     }
  58.   
  59. }
  60.