I am writing a double hashing program and I seem to have a problem here. I get always bus error. I have used std:: cout to print out where exactly the problem occurs and it seems to occur at E * newvalues = new T [newtavleLength]; Here is the part of the code. It is the part of the code where I rehash all the values in a new larger table (double old tbaleSize) after the number of values exceed 70% of tableLength.
Code:
template <typename T>
void ContDynArray<T>::rehash() {
size_t newtableLength = tableLength * 2;
size_t newmaxvalues = 0.7 * newtableLength;
T * newvalues = 0;
T * newprintvalues = 0;
bool * newoccupied = false;
newvalues = new T[newtableLength];
newprintvalues = new T[newmaxvalues];
newoccupied = new bool [newtableLength];
for (size_t i = 0; i < newtableLength; ++i) newoccupied[i] = false;
for (size_t i = 0; i < tableSize; ++i) {
unsigned long hashvalue = hashValue(printvalues[i]);
size_t newplace = hashvalue% newtableLength;
while(newoccupied[newplace]) newplace = collisionfunction (hashvalue, newplace);
newvalues[newplace] = printvalues[i];
newoccupied[newplace] = true;
newprintvalues[i] = printvalues[i];
}
delete[] values;
delete[] occupied;
delete[] printvalues;
values = newvalues;
occupied = newoccupied;
printvalues = newprintvalues;
tableLength = newtableLength;
}