home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / diverses / leda / prog / basic / dic_test.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-15  |  2.5 KB  |  133 lines

  1. #include <LEDA/ab_tree.h>
  2. #include <LEDA/bb_tree.h>
  3. #include <LEDA/rb_tree.h>
  4. #include <LEDA/ch_hashing.h>
  5. #include <LEDA/dp_hashing.h>
  6.  
  7. main()
  8.  
  9. {
  10.   ab_tree  AB_TREE;
  11.   bb_tree  BB_TREE;
  12.   rb_tree  RB_TREE;
  13.   dphash   DP_HASH;
  14.   ch_hashing  CH_HASH;
  15.  
  16. print_statistics();
  17. Yes("->");
  18.  
  19.   int    N = read_int("# keys = ");
  20.   void** RAND = new void*[N];
  21.   int    i;
  22.  
  23.   init_random();
  24.  
  25.   for(i=0; i<N; i++) RAND[i] = (void*)random(0,MAXINT-1);
  26.  
  27.   float T = used_time();
  28.  
  29. print_statistics();
  30. Yes("->");
  31.  
  32.   newline;
  33.   cout << "              insert    lookup    delete";
  34.   newline;
  35.   newline;
  36.   cout << "ab_tree: ";
  37.   cout.flush();
  38.   for(i=0; i<N; i++)  AB_TREE.insert(RAND[i],0);
  39.   cout << string("%10.2f",used_time(T));
  40.   cout.flush();
  41.  
  42.   for(i=0; i<N; i++)  AB_TREE.lookup(RAND[i]);
  43.   cout << string("%10.2f",used_time(T));
  44.   cout.flush();
  45.  
  46.   for(i=0; i<N; i++)  AB_TREE.del(RAND[i]);
  47.   cout << string("%10.2f",used_time(T));
  48.   cout.flush();
  49.   newline;
  50.  
  51. print_statistics();
  52. Yes("->");
  53.  
  54.  
  55.   cout << "bb_tree: ";
  56.   cout.flush();
  57.   for(i=0; i<N; i++)  BB_TREE.insert(RAND[i],0);
  58.   cout << string("%10.2f",used_time(T));
  59.   cout.flush();
  60.  
  61.   for(i=0; i<N; i++)  BB_TREE.lookup(RAND[i]);
  62.   cout << string("%10.2f",used_time(T));
  63.   cout.flush();
  64.  
  65.   for(i=0; i<N; i++)  BB_TREE.del(RAND[i]);
  66.   cout << string("%10.2f",used_time(T));
  67.   cout.flush();
  68.   newline;
  69.  
  70.  
  71. print_statistics();
  72. Yes("->");
  73.  
  74.  
  75.   cout << "rb_tree: ";
  76.   cout.flush();
  77.   for(i=0; i<N; i++)  RB_TREE.insert(RAND[i],0);
  78.   cout << string("%10.2f",used_time(T));
  79.   cout.flush();
  80.  
  81.   for(i=0; i<N; i++)  RB_TREE.lookup(RAND[i]);
  82.   cout << string("%10.2f",used_time(T));
  83.   cout.flush();
  84.  
  85.   for(i=0; i<N; i++)  RB_TREE.del(RAND[i]);
  86.   cout << string("%10.2f",used_time(T));
  87.   cout.flush();
  88.   newline;
  89.  
  90.  
  91. print_statistics();
  92. Yes("->");
  93.  
  94.  
  95.   cout << "ch_hash: ";
  96.   cout.flush();
  97.   for(i=0; i<N; i++)  CH_HASH.insert(RAND[i],0);
  98.   cout << string("%10.2f",used_time(T));
  99.   cout.flush();
  100.  
  101.   for(i=0; i<N; i++)  CH_HASH.lookup(RAND[i]);
  102.   cout << string("%10.2f",used_time(T));
  103.   cout.flush();
  104.  
  105.   for(i=0; i<N; i++)  CH_HASH.del(RAND[i]);
  106.   cout << string("%10.2f",used_time(T));
  107.   cout.flush();
  108.   newline;
  109.  
  110.  
  111. print_statistics();
  112. Yes("->");
  113.  
  114.   cout << "dp_hash: ";
  115.   cout.flush();
  116.   for(i=0; i<N; i++)  DP_HASH.insert(RAND[i],0);
  117.   cout << string("%10.2f",used_time(T));
  118.   cout.flush();
  119.  
  120.   for(i=0; i<N; i++)  DP_HASH.lookup(RAND[i]);
  121.   cout << string("%10.2f",used_time(T));
  122.   cout.flush();
  123.  
  124.   for(i=0; i<N; i++)  DP_HASH.del(RAND[i]);
  125.   cout << string("%10.2f",used_time(T));
  126.   cout.flush();
  127.   newline;
  128.  
  129. print_statistics();
  130.  
  131. }
  132.  
  133.