Question: Im having problems with a seg fault i cannot locate. The add, remove and best hashing functions need attn #include #include #include #include #include GlassesDisplay.hpp
Im having problems with a seg fault i cannot locate. The add, remove and best hashing functions need attn
#include
#include
#include
#include
#include "GlassesDisplay.hpp
using std::string;
using std::ifstream;
using std::cout;
using std::endl;
unsigned int hashfctunsigned int barcode
return barcode ;
unsigned int hashfctunsigned int barcode
return barcode ;
unsigned int hashfctunsigned int barcode
return barcode ;
unsigned int hashfctunsigned int barcode
return barcode ;
unsigned int hashfctunsigned int barcode
return barcode ;
unsigned int hashfctunsigned int barcode
return barcode ;
unsigned int hashfctunsigned int barcode
return barcode ;
Glasses::Glassesstring glassesColor, string glassesShape, string glassesBrand, unsigned int barcode: glassesColorglassesColor glassesShapeglassesShape glassesBrandglassesBrand barcodebarcode
;
void GlassesDisplay::readTextfilestring filename
ifstream myfilefilename;
if myfileisopen
cout "Successfully opened file filename endl;
string glassesColor;
string glassesShape;
string glassesBrand;
unsigned int barcode;
while myfile glassesColor glassesShape glassesBrand barcode
if glassesColorsize
addGlassesglassesColor glassesShape, glassesBrand, barcode;
myfile.close;
else
throw std::invalidargumentCould not open file filename;
void GlassesDisplay::addGlassesstring glassesColor, string glassesShape, string glassesBrand, unsigned int barcode
Glasses newglassesglassesColor glassesShape, glassesBrand, barcode;
hThashfctbarcode newglasses;
hThashfctbarcode newglasses;
hThashfctbarcode newglasses;
hThashfctbarcode newglasses;
hThashfctbarcode newglasses;
hThashfctbarcode newglasses;
hThashfctbarcode newglasses;
bool GlassesDisplay::removeGlassesunsigned int barcode
if hTfindbarcode hTend
hTerasebarcode;
hTerasebarcode;
hTerasebarcode;
hTerasebarcode;
hTerasebarcode;
hTerasebarcode;
hTerasebarcode;
return true;
return false;
sizet GlassesDisplay::size
if hTsize hTsizehTsize hTsizehTsize hTsizehTsize hTsizehTsize hTsizehTsize hTsize
throw std::lengtherrorHash table sizes are not the same";
return hTsize;
unsigned int GlassesDisplay::bestHashing
Array of pointers to each of the hash tables
CustomHashTable hashTables&hT &hT &hT &hT &hT &hT &hT;
unsigned int bestHashTableIndex ;
sizet minBalance staticcast; Equivalent to std::numericlimits::max
Iterate through each hash table
for unsigned int i ; i ; i
sizet maxBucketSize ;
sizet minBucketSize staticcast; Initialize to the maximum possible value
Check only the first buckets, or fewer if the hash table is smaller
unsigned int numBucketsToCheck staticcaststd::minstaticcast hashTablesibucketcount;
for unsigned int j ; j numBucketsToCheck; j
sizet bucketSize hashTablesibucketsizej;
if bucketSize maxBucketSize
maxBucketSize bucketSize; Update max bucket size found
if bucketSize minBucketSize
minBucketSize bucketSize; Update min bucket size found
sizet currentBalance maxBucketSize minBucketSize; Compute the balance for the current hash table
if currentBalance minBalance
minBalance currentBalance;
bestHashTableIndex i ; Store the index of the best hash table based index
return bestHashTableIndex;
#pragma once
#include
#include
using std::string;
struct Glasses
string glassesColor;
string glassesShape;
string glassesBrand;
unsigned int barcode;
Glassesstring glassesColor string glassesShape string glassesBrand unsigned int barcode ;
;
unsigned int hashfctunsigned int;
unsigned int hashfctunsigned int;
unsigned int hashfctunsigned int;
unsigned int hashfctunsigned int;
unsigned int hashfctunsigned int;
unsigned int hashfctunsigned int;
unsigned int hashfctunsigned int;
typedef std::unorderedmap CustomHashTable;
class GlassesDisplay
public:
hpp file does not fit but is complete
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
