Question: Hello, can someone help me with this program? The header file below defines a class for a simple hash table: hashMap.h Write a driver program

Hello, can someone help me with this program?

The header file below defines a class for a simple hash table:

hashMap.hHello, can someone help me with this program? The header file below

Write a driver program to test the class with the following data:

(520, "3100 Main St, Houston TX ");

(37, "2200 Hayes Rd, Austin TX");

(226, "1775 West Airport St, San Antonio TX");

(273, "3322 Walnut Bend, Houston TX");

(491, "5778 Alabama, Waco TX");

(94, "3333 New St, Paris TX");

Make sure to also test the find function for exiting and non-existing data

2. Modify the key type in the class definition to a string, e.g. phone number or e-mail address. Use the string hash function discussed in class or search online for alternative functions that work on strings.

3. Modify collision strategy of class HashMap to do separate chaining instead of linear probing. Be sure to modify the display function so that items in the buck chains are also displayed in a pre-defined order for debugging purpose.

4. Add a delete function to class HashMap.

Deliverables:

1) Indicate which tasks you completed.

2) Since the tasks above are cumulative, you only need to submit/demo your code for the last task indicated in (1). Submit screenshots of your program execution showing your program meets the specs of the last task completed.

Be ready (i.e. have your test cases ready to run) to demo your program.

hashmap.h

#ifndef hashMap_h

#define hashMap_h

using namespace std;

class HashEntry {

public:

int key;

string value;

HashEntry(int key, string value) {

this->key = key;

this->value = value;

}

};

//============================================

const int TABLE_SIZE = 11;

class HashMap {

private:

HashEntry **table;

public:

HashMap() {

table = new HashEntry*[TABLE_SIZE];

for (int i = 0; i

table[i] = NULL;

}

bool find(int key, string& value) {

// return value associated with key

// return -1 if not found

int hash = (key % TABLE_SIZE);

while (table[hash] != nullptr && table[hash]->key != key)

hash = (hash + 1) % TABLE_SIZE; //linear probe

if (table[hash] == nullptr)

return false; // not found

else //table[hash]->key != key

{

value = table[hash]->value;

return true;

}

}

void insert(int key, string value) {

//Insert pair using hassh function

int hash = (key % TABLE_SIZE);

int count = 1;

while (count

table[hash]->key != key)

{

hash = (hash + 1) % TABLE_SIZE;

++count;

}

if (count >= TABLE_SIZE)

{

cout

return;

}

if (table[hash] != nullptr)

delete table[hash];

table[hash] = new HashEntry(key, value);

}

void display() {

// used for debugging purpose only to inspect what's in the map

for (int i=0; i

if (table[i] == nullptr)

cout

else

cout key

table[i]->value

cout

}

~HashMap() {

for (int i = 0; i

if (table[i] != NULL)

delete table[i];

delete[] table;

}

};

#endif /* hashMap_h */

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!