cis22c/06-hash-tables/HashTable.h
Iurii Tatishchev 3d112946f5
9.12 Lab: Hashing - Linear Probe (insert, search)
Hash Function: Add the ASCII values of all characters in the key string and return the reminder obtained when divided by the size of the table.

Example: If key = "Bob", and size = 53, we get (66 + 111 + 98) % 53 => 275 % 53 => 10.

Collision Resolution Method: Linear Probe.

The assignment consists of the following classes/files:

- main.cpp (incomplete)
- Student.h (given)
- HashNode.h (given)
- HashTable.h (given)
- HashTable.cpp (incomplete)

Read and understand the given code then write two functions:

- insert hash
- search hash
2024-05-11 15:43:39 -07:00

52 lines
953 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);
bool search(Student &itemOut, int &noCol, string key);
private:
int _hash(string key) const;
};
#endif // HASHTABLE_H_