asgn2.c |
| /*************************************************************************** * * * Hash Table Program in C * * * * COSC 242 Assignment 06/09/01 * * * * JAMES LITTLE * * * ***************************************************************************/ #include <stdio.h> #include <stdlib.h> #include <time.h> #include "mylib.h" #include "htable.h" /************************** * * * main * * * ************************** Hash Table application: Compares the strengths of two hashing functions, Linear probing and Double Hashing. Accepts input through the command line in reference to the desired table size and the number of statistical snap-shots required. Input to the Hash table is read through the Standard in, however this could easily be altered to accept command line input. The hash table insert function is the same for both methods of hashing, however the technique differs greatly depending on the hashing method. PARAMETERS: argc = the number of arguments passed thru the command line, plus the program name. argv = an array of command line arguments in string format. And the program name. RETURN VALUE: EXIT_SUCCESS, which just hides the value of zero, which signals a normal exit of the program in C. */ int main(int argc, char **argv){ int i; htable ht_linear; htable ht_double; char word[256]; char op; FILE *in = stdin; int num_stats = (argc >= 3) ? atoi(argv[2]) : 10; int size = (argc >= 2) ? atoi(argv[1]) : 113; ht_linear = htable_new(size, LINEAR); ht_double = htable_new(size, DOUBLE); while(getword(word, sizeof word, in) != EOF){ htable_insert(ht_linear, word); htable_insert(ht_double, word); } htable_print_stats(ht_linear, stdout, num_stats); htable_print_stats(ht_double, stdout, num_stats); htable_destroy(ht_linear); htable_destroy(ht_double); return EXIT_SUCCESS; } |
James Little |