SPEAKER 1: Now we're ready to check each word in the text file
against the words in our dictionary.
For check, you're allowed to assume case insensitivity.
That means that any word spelled with any combination of uppercase
or lowercase letters is going to be the same, no matter what.
You're also allowed to assume that these strings are
comprised of only alphabetical characters and apostrophes.
Let's talk about a hash table implementation first.
If the word indeed exists, then it means that it
should be found in our hash table.
So the first thing that we need to figure out
is, which bucket would that word be in?
We do that by hashing that word, because remember-- hash functions
are deterministic.
They're going to return the exact same index every time if we're
passing in the exact same thing.
So remembering that hash tables are simply arrays of linked lists,
then going to hash of word will give you the index for your hash table.
So now that we know which link list to look in,
let's talk about how we can search within that link list.
We'll want to iterate over our linked list.
And for every word, we'll want to compare that to the word
we're looking for, using this function-- string case
comp-- which is found in strings.h.
And that will compare strings with case insensitivity.
Now that we know what to do for every word in our node,
we need to figure out how to actually get to every node in the linked list.
So how do we iterate over a linked list?
Well, recall back to when we iterate over an array.
In our for loop, we would have an iterator variable, i.
So we're going to do something very similar
here, where we have a node pointer.
In this case I'm going to call it cursor.
And I'm going to not malloc a new node for it.
Rather, I'm just pointing it right at the head of my linked list.
And so as long as my cursor isn't pointing to null,
I'm going to do something with the node that cursor is pointing to.
And then I'm going to update my cursor, setting it
to the next node, and the next node, and the next,
until the cursor points to null, meaning that I've
reached the end of my linked list.
And so if I don't find the word in that linked list,
that means that word doesn't belong in my dictionary.
So now let's talk about checking the dictionary for words
if our dictionary is implemented as a try.
If the word exists in the dictionary, then that
means that we'll be able to find the path in the try.
Not only that, is_word must be true for the last character
in order for that to be a valid word.
So let's talk about how we might traverse our try, looking for a word.
For each letter in our input word, we'll want
to go to the corresponding element in children, using its alphabetical index.
If that's null, then that means that word is misspelled.
The path doesn't exist.
But if it's not null, then we can move to the next letter.
If we reach the end of our input word, then we'll
want to check if the Boolean is_word is true.
If it is, then great-- we found our word.
Otherwise, that word doesn't exist in our dictionary.