Question: In c + + , please complete the following functions implementing a Hash Table for Quadratic Probing closed hashing table in a Snake Game. Your
In cplease complete the following functions implementing a Hash Table for Quadratic Probing closed hashing table in a Snake Game. Your hash table will be used to keep a small collection of selected treasures from the ItemBin as the bingo conditionfor each player instance, and upon collecting each treasure, the matched treasure will be lazydeleted from the hash table. As soon as one of the player instances reaches a hash table load factor lambda the player completes the bingo condition and wins the game. Refer to attached image for function requirements. Below is the objPosDoubleHashing class that needs filling based on the attached image requirements and header files.
#include "objPosDoubleHashing.h
#include "MacUILib.h
#include
using namespace std;
objPosDoubleHashing::objPosDoubleHashing
Instantiate the objPos Hash Table of the default size TABLESIZE defined in the objPosHashTable abstract class
Should also initialize tableSize field with the default size TABLESIZE
objPosDoubleHashing::objPosDoubleHashingint size
Instantiate the objPos Hash Table of the specified size
Should also initialize tableSize field with specified size
objPosDoubleHashing::~objPosDoubleHashing
delete the Hash Table
int objPosDoubleHashing::calculateHashingint prefix, int numberconst hashing function
Implementing the primary hashing function
Add all the decimal integer digits of the Prefix ASCII char and the Number together
For example, given objPos.prefix Aand objPos.number then
hxsum of all decimal digits of prefix and number
return the sum as the hashing key.
int objPosDoubleHashing::calculateSecondaryHashingint inputconst
Implementing the secondary hashing function
Sum up all digits of input
return sum mod
eg input
sum
return value
bool objPosDoubleHashing::insertconst objPos &thisPos
Algorithm similar to the one discussed in class
Calculate the initial hashing key using calculateHashingprivate helper function iethe hx
Check symbol field to see whether the indexed slot is empty
If yes, insert data, set symbol to vthen return true indicating successful insertion
Otherwise, proceed to collision resolution
Collision resolution strategy Double Probing
hxhxihxmod tableSize i is the probing count
where hxsum of all digits of hxmod
For every newly calculated key using quadratic probing, check for empty slot for insertion
If empty slot is found, insert data, set symbol to vthen return true indicating successful insertion
If element is already inserted, return false indicating failed insertion
If probing count exceeds MAXPROBINGCOUNT defined in objPosHash.hreturn false
too many probing attempts, may lead to integer overflow
#ifndef OBJPOSDOUBLEHASHINGH
#define OBJPOSDOUBLEHASHINGH
#include "objPosHash.h
#include "objPos.h
class objPos;
class objPosDoubleHashing : public objPosHashTable
private:
objPosmyHashTable;
int calculateHashingint prefix, int numberconst; hashing function
int calculateSecondaryHashingint inputconst; secondary hashing function
signature subject to change
public:
objPosDoubleHashing;
objPosDoubleHashingint;
virtual ~objPosDoubleHashing;
bool insertconst objPos &thisPos;
bool removeconst objPos &thisPos; lazy delete
bool isInTableconst objPos &thisPosconst;
double getLambdaconst;
void printMeconst;
;
#endif
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
