I have a data structure contains a 4-letter string as a key (char key[5]) with all the characters in upper case. I'm trying to write a formula to calculate a base-26 hash index for a key in order to place the structure in a hash table that is TABLESIZE in length. The main thing I wasn't sure about what having enough key[] to index all my data being that it is key[5]. Here is the formula I have written so far:
long index = ((key[0]-'A')*pow(26,3)) + ((key[1]-'A')*pow(26,2)) + ((key[2]-'A')*26) + ((key[3]-'A')) % TABLESIZE;