Phashtable->base.baseelement = pchainelements Pchainelements = (chainelements *)malloc(sizeof(chainelements)) įprintf(stderr, " - memory allocation failed for the word - \n") * if no elements are present - insert word */ Void insertWord(hashtable *phashtable, char *str) New node and appends the word at the end of chain Word is present if it's not present creates a Input params - pointer to hashtable and word to be inserted * compares the given word with present in node */įuncntion - insertWord(hashtable *phashtable, char *str) * pointer to first element of the chained linked list */Ĭhainelements *pchainelements = phashtable->base.baseelement Task - for given string finds it's hashindexĪnd searches all nodes in that chain to see ifīool searchWord(hashtable *phashtable, char *str)įprintf(stderr, " - invalid pointer to string or hashtable - \n") įprintf(stderr, " - invalid hashindex - \n") Return value - returns 1 if word is present else 0 Input params - pointer to hashtable and word to be searched Printf("IS the searchword %s present - %d \n", searchword, ispresent) įuncntion - searchWord(hashtable *phashtable, char *str) Ispresent = searchWord(phashtable, searchword) InsertWord(phashtable, oneword) /* Test code to check insert does not happen again*/ Printf("%s \n", oneword) /* display it on the monitor */ Hashtable *phashtable = createHashTable(SIZE) Ĭ = fscanf(fp1, "%s", oneword) /* got one word from the file */ Void insertWord(hashtable *phashtable, char *str) īool searchWord(hashtable *phashtable, char *str) For given string find its key and hash index Tblelements *base /* Pointer to first table element */īelow functions accomplish task as listedĢ. Int size /* Number of table elements in hashtable */ Int total_elements /* total elements in chain - Not used here so far */Ĭhainelements *baseelement /* Pointer to chained linked list of words */ Struct CHAINELEMENTS *next /* pointer to next element */ #define WORD_SIZE 100 /* Max size of word */Ĭhar word /* word to be saved in list */ #define SIZE 10000 /* Number of elements in table */ In regards to the hash function, I have kept it simple as I was not very concerned about collisions.Ĭan someone please review it and let me know of anything I should improve? Like: The implementation is using a hash table with a chained linked list. I have written the below code which loads the dictionary and checks if the given word is present or not.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
December 2022
Categories |