I have a version of dictionary.c that has all of the functions completed and compiling.

When I run ./speller on my small test sets it completes succesfully.

When I run it using the following test, the results do not match the staff run.

My solution was implemented with a hashtable, not a trie.

I'm assuming the issue is in check, but it could be in the load or the hashfunction.

Following is the code for my check function.

I can post the code for load if that would help.

Thanks for any suggestions.

bool check(const char* word)
    int index, word_exists;
    node* bucket_node;

    // if the word exists, then it can be found in the hash table.
    // The bucket the word would be in would be hashtable[hash(word)]

    // Get the index of the linked list where the word would be 
    // stored in the hashtable
    index = hashstring((unsigned char *) word);

    // Get the address of the first element of the linked list.
    bucket_node = hashtable[index];

    // walk the linked list looking for the word.
    // - use strcasecmp to compare words - returns 0 if equal
    //   irrespective of case.
    while (bucket_node != NULL)
        word_exists = strcasecmp(word, bucket_node->word);        
        if (word_exists == 0)
            return true;

        // word not found keep traversing the list
        bucket_node = bucket_node->next;
    return false;
  • Actually right after posting this I thought of the solution I think :) All my failed matches in check are mixed case or upper case. All of the words in the dictionary are lower case, and that determines the hashvalue of the location of its link list in the table. I need to lower the word to be matched in check before I get its hash value, so that I can look in the proper hashtable bucket for its potential match in the dictionary. – Jeffery R Roche Dec 8 '14 at 14:45
  • good to hear you found your own solution! ;) If you confirm it, please post your answer and accept it, for future reference. – abelinux Dec 8 '14 at 15:04
  • Yup that was my problem. – Jeffery R Roche Dec 17 '14 at 14:38
  • It would be great if you could answer your own question and mark it "accepted" for future reference. – abelinux Dec 17 '14 at 14:43

You must log in to answer this question.

Browse other questions tagged .