From b26f6c4501200cb18b77b69b543ee7f0e54ef73c Mon Sep 17 00:00:00 2001 From: Iurii Tatishchev Date: Thu, 20 Jun 2024 17:50:59 -0700 Subject: [PATCH] mid-presentation changes --- HashTable.h | 15 +++++++++------ fio.cpp | 1 - main.cpp | 4 ---- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/HashTable.h b/HashTable.h index 4263857..9b38745 100644 --- a/HashTable.h +++ b/HashTable.h @@ -24,6 +24,8 @@ private: int hashSize; int count; + void _reHash(int h(const T &key, int size)); + public: HashTable() { count = 0; @@ -59,8 +61,6 @@ public: 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(const HashTable &hashTable, const string &filename, string visit(const T &)); }; @@ -98,8 +98,11 @@ int HashTable::getMaxCollisions() const { *~**/ template bool HashTable::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); for (int i = 0; i < hashSize; i++) { @@ -171,7 +174,7 @@ int HashTable::search(T &itemOut, const T &key, int h(const T &key, int size) } template -void HashTable::reHash(int h(const T &key, int size)) { +void HashTable::_reHash(int h(const T &key, int size)) { int nHashSize = hashSize * 2; @@ -187,7 +190,7 @@ void HashTable::reHash(int h(const T &key, int size)) { int nIndex = h(aT, nHashSize); - for (int j = 0; j < hashSize; j++) { + for (int j = 0; j < nHashSize; j++) { if (nHashAry[nIndex].getOccupied() != 1) { nHashAry[nIndex].setItem(aT); nHashAry[nIndex].setOccupied(1); diff --git a/fio.cpp b/fio.cpp index b88bd9f..5de2b5f 100644 --- a/fio.cpp +++ b/fio.cpp @@ -53,7 +53,6 @@ void insertFile(const string &filename, BinarySearchTree &bst, HashTable cout << "Duplicate CPU \"" << name << "\" found in file. Skipping...\n"; continue; } - temp.ignore(); getline(temp, strToNum, ';'); releaseYear = stoi(strToNum); diff --git a/main.cpp b/main.cpp index f15d6e6..8d40c2a 100644 --- a/main.cpp +++ b/main.cpp @@ -139,10 +139,6 @@ void processInput(char command, HashTable &cpuTable, BinarySearchTree &hashTable, BinarySearchTree &tree) { - if (hashTable.getLoadFactor() >= 75) { - cout << "Load factor is " << hashTable.getLoadFactor() << ". Rehashing...\n"; - hashTable.reHash(key_to_index); - } insertCPU(tree, hashTable); }