mid-presentation changes

This commit is contained in:
Iurii Tatishchev 2024-06-20 17:50:59 -07:00
parent 0e1424ea3f
commit b26f6c4501
Signed by: CaZzzer
GPG Key ID: 28BE602058C08557
3 changed files with 9 additions and 11 deletions

View File

@ -24,6 +24,8 @@ private:
int hashSize; int hashSize;
int count; int count;
void _reHash(int h(const T &key, int size));
public: public:
HashTable() { HashTable() {
count = 0; count = 0;
@ -59,8 +61,6 @@ public:
int search(T &itemOut, const T &key, int h(const T &key, int size)) const; int search(T &itemOut, const T &key, int h(const T &key, int size)) const;
void reHash(int h(const T &key, int size));
friend void writeToFile<T>(const HashTable<T> &hashTable, const string &filename, string visit(const T &)); friend void writeToFile<T>(const HashTable<T> &hashTable, const string &filename, string visit(const T &));
}; };
@ -98,8 +98,11 @@ int HashTable<T>::getMaxCollisions() const {
*~**/ *~**/
template<typename T> template<typename T>
bool HashTable<T>::insert(const T &itemIn, int h(const T &key, int size)) { bool HashTable<T>::insert(const T &itemIn, int h(const T &key, int size)) {
if (count == hashSize)
return false; if (getLoadFactor() >= 75) {
cout << "Load factor is " << getLoadFactor() << ". Rehashing...\n";
_reHash(key_to_index);
}
int ind = h(itemIn, hashSize); int ind = h(itemIn, hashSize);
for (int i = 0; i < hashSize; i++) { for (int i = 0; i < hashSize; i++) {
@ -171,7 +174,7 @@ int HashTable<T>::search(T &itemOut, const T &key, int h(const T &key, int size)
} }
template<class T> template<class T>
void HashTable<T>::reHash(int h(const T &key, int size)) { void HashTable<T>::_reHash(int h(const T &key, int size)) {
int nHashSize = hashSize * 2; int nHashSize = hashSize * 2;
@ -187,7 +190,7 @@ void HashTable<T>::reHash(int h(const T &key, int size)) {
int nIndex = h(aT, nHashSize); int nIndex = h(aT, nHashSize);
for (int j = 0; j < hashSize; j++) { for (int j = 0; j < nHashSize; j++) {
if (nHashAry[nIndex].getOccupied() != 1) { if (nHashAry[nIndex].getOccupied() != 1) {
nHashAry[nIndex].setItem(aT); nHashAry[nIndex].setItem(aT);
nHashAry[nIndex].setOccupied(1); nHashAry[nIndex].setOccupied(1);

View File

@ -53,7 +53,6 @@ void insertFile(const string &filename, BinarySearchTree<string> &bst, HashTable
cout << "Duplicate CPU \"" << name << "\" found in file. Skipping...\n"; cout << "Duplicate CPU \"" << name << "\" found in file. Skipping...\n";
continue; continue;
} }
temp.ignore(); temp.ignore();
getline(temp, strToNum, ';'); getline(temp, strToNum, ';');
releaseYear = stoi(strToNum); releaseYear = stoi(strToNum);

View File

@ -139,10 +139,6 @@ void processInput(char command, HashTable<CPU> &cpuTable, BinarySearchTree<strin
} }
void handleInsert(HashTable<CPU> &hashTable, BinarySearchTree<string> &tree) { void handleInsert(HashTable<CPU> &hashTable, BinarySearchTree<string> &tree) {
if (hashTable.getLoadFactor() >= 75) {
cout << "Load factor is " << hashTable.getLoadFactor() << ". Rehashing...\n";
hashTable.reHash(key_to_index);
}
insertCPU(tree, hashTable); insertCPU(tree, hashTable);
} }