src/avl/avl_bench1.c File Reference

#include <stdio.h>
#include "array.h"
#include "avl.h"
#include "util.h"
Include dependency graph for avl_bench1.c:

Go to the source code of this file.

Defines

#define MAX_WORD   1024

Functions

long random ()
 main (argc, char *argv)

Define Documentation

#define MAX_WORD   1024

Definition at line 15 of file avl_bench1.c.


Function Documentation

main ( argc  ,
char *  argv 
)

Definition at line 20 of file avl_bench1.c.

00022 {
00023     array_t *words;
00024     avl_tree *table;
00025     char word[MAX_WORD], *tempi, *tempj;
00026     register int i, j;
00027     long time;
00028 #ifdef TEST
00029     avl_generator *gen;
00030     char *key;
00031 #endif
00032 
00033     /* read the words */
00034     words = array_alloc(char *, 1000);
00035     while (gets(word) != NIL(char)) {
00036         array_insert_last(char *, words, util_strsav(word));
00037         if (array_n(words) == 100000) break;
00038     }
00039 
00040     /* scramble them */
00041     for(i = array_n(words)-1; i >= 1; i--) {
00042         j = random() % i;
00043         tempi = array_fetch(char *, words, i);
00044         tempj = array_fetch(char *, words, j);
00045         array_insert(char *, words, i, tempj);
00046         array_insert(char *, words, j, tempi);
00047     }
00048 
00049 #ifdef TEST
00050     (void) printf("Initial data is\n");
00051     for(i = array_n(words)-1; i >= 0; i--) {
00052         (void) printf("%s\n", array_fetch(char *, words, i));
00053     }
00054 #endif
00055 
00056     /* time putting them into an avl tree */
00057     time = util_cpu_time();
00058     table = avl_init_table(strcmp);
00059     for(i = array_n(words)-1; i >= 0; i--) {
00060         (void) avl_insert(table, array_fetch(char *, words, i), NIL(char));
00061     }
00062     (void) printf("Elapsed time for insert of %d objects was %s\n",
00063         array_n(words), util_print_time(util_cpu_time() - time));
00064 
00065 #ifdef TEST
00066     (void) printf("Sorted data is\n");
00067     avl_foreach_item(table, gen, AVL_FORWARD, &key, NIL(char *)) {
00068         (void) printf("%s\n", key);
00069     }
00070 #endif
00071     return 0;
00072 }

long random (  ) 

Generated on Tue Jan 12 13:57:09 2010 for glu-2.2 by  doxygen 1.6.1