When I wake up the next day, I reread the lecture notes and watched one of the shorts videos on Hash Functions to gain a better understanding of what it actually is and what it actually does. Reading the lecture notes helped me write codes when I need to connect nodes for the hash function while watching the shorts helped me understand hash functions better.
In short, hash functions are actually an array of 'buckets' that store numbers. These numbers represent a string, calculated using a function (can be anything, but easier to use an established hash function that has been written by someone else). When we pass a string into the function, the function generates a number, and stores this into one of the buckets. Whenever we want to check whether the string exists or not in one of the buckets, we just have to find the bucket using the same number, and check whether the string is stored in there.
I had so many segmentation faults, but it was mainly because I typed the wrong 'stuff', so the computer was searching for something that doesn't exist, to begin with. But after correcting it, the programme ran smoothly. Yet, that was not the end of the problem.
When I checked the output of my programme, my Speller doesn't consider a word with full capital letters the same as the same word with lower cases. After searching for answers to this problem online, I realised that it was because my hash function was dependent on the ASCII values of each character of a string. The ASCII value for a capital letter is not the same as the one for the same letter but of lower case, so the words "word" and "WORD" would have different numbers generated by the hash function, and so, Speller considers these words as two different words.
Once I fixed this, I was finally done. Alhamdulillah.
No comments:
Post a Comment