0

I just wonder if this hash function is correct? I was thinking that the index cannot be above 26 as it would look for memory outside the array, and would probably cause a segmentation fault. Therefore i added %26. But im not sure if my hash function is correct. Any thoughts?

int hash(const char *word)
 {
     int hash_key = (word[0] - 'a') % 26;
     return hash_key;
 }

Later i make a call for the hash function:

int index = hash(new_node-> word);
1

Almost got it. What happens if the first letter (common in the text being checked) is upper case?

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

1
  • Ah, so if I add the tolower function it migh do the work? Like this: int hash_key = tolower(word[0] - 'a') % 26; Thanks for your reply!
    – L.D
    Mar 16 '17 at 14:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .