Im working on the unload function and I had fortunately written a "print" function that printed every member in the hash table. Writing this I was able to use it for the unload and size function.
however....im really unsure when I should be returning true
on the unload function. How would I know that the memory is free'd as it is without running valgrind?
Current Unload():
/**
* Unloads dictionary from memory. Returns true if successful else false.
*/
bool unload(void)
{
node *ptr = NULL;
for(int i = 0; i < HASHTABLESIZE; i++)
{
if(hashtable[i] == NULL)
{
i++;
}
else
{
ptr = hashtable[i];
while(ptr->next != NULL)
{
node *temp = ptr;
ptr=ptr->next;
free(temp);
}
}
}
return false;
}
Also size for reference (hopefully it's remotely correct):
/**
* Returns number of words in dictionary if loaded else 0 if not yet loaded.
*/
unsigned int size(void)
{
node *ptr = NULL;
int counter = 0;
for(int i = 0; i < HASHTABLESIZE; i++)
{
if(hashtable[i] == NULL)
{
i++;
}
else
{
ptr = hashtable[i];
while(ptr->next != NULL)
{
counter++;
ptr=ptr->next;
}
}
}
return counter;
if(counter == 0)
{
return 0;
}
}
Sure...if it goes through the entire loop it would be correct I would think? I suppose at the end I could go through every loop and make sure I see nothing but Null pointers on the array at the end?