cis22c/06-hash-tables/HashTable.h
Iurii Tatishchev b43f08aacc
9.13 Lab: Hashing - Linear Probe (insert, search, delete)
Reuse code from the previous lab and write new code as described below:

- search hash: Modify this function to return -1 if the target key is not found or the number of collisions for that key if found.

`int search(Student &target, string key);`

- remove hash: Create a new function to delete an item from the hash table.
- insert manager: inserts user provided data into the hash table and rejects duplicates.
2024-05-11 16:16:27 -07:00

52 lines
958 B
C++

// Specification file for the Hash class
#ifndef HASHTABLE_H_
#define HASHTABLE_H_
#include "HashNode.h"
using std::string;
class HashTable {
private:
HashNode *hashAry;
int hashSize;
int count;
public:
HashTable() {
count = 0;
hashSize = 53;
hashAry = new HashNode[hashSize];
}
HashTable(int n) {
count = 0;
hashSize = n;
hashAry = new HashNode[hashSize];
}
~HashTable() { delete[] hashAry; }
int getCount() const { return count; }
int getSize() const { return hashSize; }
double getLoadFactor() const { return 100.0 * count / hashSize; }
bool isEmpty() const { return count == 0; }
bool isFull() const { return count == hashSize; }
bool insert(const Student &itemIn);
bool remove(Student &itemOut, string key);
int search(Student &itemOut, string key) const;
private:
int _hash(string key) const;
};
#endif // HASHTABLE_H_