I have to create a hash for a set of ints. The hash function which I need to use is this:
f(x) = k * x % TableSize.
I know I definitely need 4 loops, with them being set up like this:
Outer loop - TableSize = 10 to 1000
Middle loop - k = 1 to 500
Inner loop - create a table, and set it to -1
Inner inner loop - step through 10 #s loc = f(num)
The problem is, while I kind of know how to set up the outer and middle loops, I'm stuck regarding the last two loops.
What I do know regarding the hash function, is that the values which I want to put into the hash take the place of the 'x'
While I know how to set up a hash table when it comes to strings, I don't know how to do it for ints (as I heard that the setup is a bit different). Also, based on the requirements, would I be creating the table in the inner loop, or just calling a different function?
This is everything which I have in my .h file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
#pragma once
#include <iostream>
#include <string>
using namespace std;
class intHash{
public:
intHash(int tableSize);
~intHash();
void someStuff(){
for (int TableSize = 10; TableSize < 1000; TableSize++){
for (int k = 1; k < 500; k++){
for (){
intHash(-1);
for (){
}
}
}
}
}
private:
string *hashTable;
};
|