Need Help With Hashing

Hey there, so I'm just learning (or trying to) a bit about hashing. I'm attempting to make a hashing function, however I'm confused where I save the data to. I'm trying to calculate the number of collisions and print that out. I have made 3 different files, one with 10,000 words, 20,000 words and 30,000 words. Each word is just 10 random numbers/letters.

1
2
3
4
5
6
7
8
9
10
11
12
  long hash(char* s]){
    long h;
    for(int i = 0; i < 10; i++){
      h = h + (int)s[i];
    }
     //A lot of examples then mod h by the table size
     //I'm a bit confused what this table is... Is it an array of
     //10,000 (or however many words)?
    
    //h & TABLE_SIZE
    return h
  }


1
2
3
4
5
6
7
8
  int main (int argc, char* argv[]){
    fstream input(argv[1]);
    char* nextWord;
    while(!input.eof()){
      input >> nextWord;
      hash(nextWord);
    }
  }


So that's what I currently have, but I can't figure out what the table is exactly, as I said in the comments above... Is it a predefined array in my main with the number of words in it? For example, if I have a file of 10 words, do I make an array a of size 10 in my main? Then if/when I return h, lets say the order goes: 3, 7, 2, 3

The 4th word is a collision, correct? When that happens, I add 1 to collision and then add 1 to then check if slot 4 is also full?

Thanks for the help!
Last edited on
Topic archived. No new replies allowed.