Hello everybody:
I have to implement a spell checker for my school assignment. This means reading in a dictionary file into a hash table with chaining. I have a general linked list ADT that I will use for the chains. The following structure will define the HashTable:
Here, tablesize will represent the size of the table which we do not know before hand, but will be calculated to be a percentage of the size of the number of words in the dictionary.Code:typedef struct hashtable{ int tablesize; List *table; }HashTable;
I believe the following can be used to initialize an empty HashTable:
Here, CreateList is a function from the List ADT. I do believe that the the call to malloc allocates enough memory to hold an array of pointers to linked list; this array of pointers should be tablesize long (i.e. the size of the table). Also, would H->table+i or H->table++ increment along this array of pointers.Code:void CreateTable(HashTable *H) { int i; int tablesize = H->tablesize; H->table = (List *)malloc(tablesize*sizeof(List *)); for(i=0; i<tablesize; i++) CreateList(H->table+i); }
Thanks,
tim