Now that you have a working implementation of the HashNode and HashTable classes, you can convert them to templates, and update main.cpp to match with the new template classes. In order for everything to work you will also have to: - overload the == operator for the Student class - declare the hash function a friend function of the Student class - send the hash function as an argument to insert, remove, and search functions.
51 lines
1.0 KiB
C++
51 lines
1.0 KiB
C++
// Specification file for the HashNode class
|
|
// Written By: Iurii Tatishchev
|
|
// Changed by: Iurii Tatishchev
|
|
|
|
#ifndef _HASH_NODE
|
|
#define _HASH_NODE
|
|
|
|
// To do: convert to a template
|
|
template<typename T>
|
|
class HashNode {
|
|
private:
|
|
T item;
|
|
int occupied; // 1 -> occupied, 0 -> empty from start, -1 -> empty after removal
|
|
int noCollisions;
|
|
|
|
public:
|
|
// constructors
|
|
HashNode() {
|
|
occupied = 0;
|
|
noCollisions = 0;
|
|
}
|
|
|
|
HashNode(T anItem) {
|
|
item = anItem;
|
|
occupied = 1;
|
|
noCollisions = 0;
|
|
}
|
|
|
|
HashNode(T anItem, int ocp, int nCol) {
|
|
item = anItem;
|
|
occupied = ocp;
|
|
noCollisions = nCol;
|
|
}
|
|
|
|
// setters
|
|
void setItem(const T &anItem) { item = anItem; }
|
|
|
|
void setOccupied(int ocp) { occupied = ocp; }
|
|
|
|
void setNoCollisions(int nCol) { noCollisions = nCol; }
|
|
|
|
// getters
|
|
T getItem() const { return item; }
|
|
|
|
int getOccupied() const { return occupied; }
|
|
|
|
int getNoCollisions() const { return noCollisions; }
|
|
};
|
|
|
|
#endif
|