<分区>
我正在为我的数据结构类(class)开发哈希表实验室。当我在插入函数中使用 push_back() 函数时,我不断收到一个我认为会发生的设置错误。但是,我不确定是什么导致了这个错误。
using namespace std;
HashTable::HashTable(int buckets) {
this->buckets = buckets;
vector<Entry>* table = new vector<Entry>[buckets];
}
Entry HashTable::insert(GameBoard board, int number) {
int index = compress(board.hashCode());
Entry entry = Entry(board, number);
table[index].push_back(entry);
return entry;
}
int HashTable::compress(int hashCode) {
return (hashCode % buckets);
}
Entry::Entry(GameBoard board, int value) {
this->board = board;
this->value = value;
}
int GameBoard::hashCode() {
int hashVal = 0;
for (int r = 0; r < DIMENSION; r++) {
for (int c = 0; c < DIMENSION; c++) {
hashVal = ((127 * hashVal) + board[r][c]) % 16908799;
}
}
return hashVal;
}