Question: I need a little help with homework for c++ data structures/algorithms project. This is a Router Simulation as client of generic HashTable. There are two

I need a little help with homework for c++ data structures/algorithms project. This is a Router Simulation as client of generic HashTable. There are two files, the first I will post so you can see. Solutions needed where //TBS is seen.

file should contain implementations of Router methods. The startup file contains all of the boiler plate and some other methods already completed.

---------------------------------------------------

#include #include #include #include

void Router::Insert(const ipString& dS, const ipString& rS, bool verify) { // TBS }

void Router::Remove (const ipString& dS) { // TBS }

void Router::Go (const char* msgfile, bool verbose, const char* logfile) { std::cout << " Router simulation started "; std::ifstream fin; fin.open(msgfile); if (fin.fail()) { std::cerr << "** Router: unable to open msg file " << msgfile << ' ' << " Go() aborted "; return; } fin >> std::hex; std::ofstream fout; std::ostream * optr = &std::cout; if (verbose) { if (logfile != nullptr) { fout.open(logfile); if (fout.fail()) { std::cerr << "** Router: unable to open log file " << logfile << ' ' << " Go() aborted "; return; } optr = &fout; } } ipClass ipC; ipString dS; ipNumber dN, rN, netID, hostID; fsu::String msgID; size_t packets(0), routed(0), routedA(0), routedB(0), routedC(0), rejected(0)\ , bad(0); (*optr) << std::hex << std::uppercase; fin >> dS >> msgID; while (!fin.fail()) { ++packets;

// TBS

fin >> dS >> msgID; } // end while() fin.close(); if (logfile == nullptr) { // set cout back to normal std::cout << std::dec << std::setfill(' '); } else { // close the log file fout.clear(); fout.close(); } std::cout << " Packets processed: " << packets << ' ' << " Packets routed: " << routed << ' ' << " route class A: " << routedA << ' ' << " route class B: " << routedB << ' ' << " route class C: " << routedC << ' ' << " Packets rejected: " << rejected << ' ' << " Packets bad: " << bad << ' '; std::cout << " Router simulation stopped "; if (routedA + routedB + routedC != routed) std::cout << " ** Processing logic error: route class imbalance "; if (routed + rejected + bad != packets) std::cout << " ** Processing logic error: packets not accounted for "; if (logfile != nullptr) std::cout << " Routing log written to " << logfile << ' '; return; } // end Router::Go()

// *********************************************** // below this sign should not require modification // ***********************************************

Router::Router (size_t sizeEstimate) : tablePtr_(0) { ipHash iph; tablePtr_ = new TableType (sizeEstimate, iph); }

Router::~Router () { delete tablePtr_; }

void Router::Load (const char* loadfile) { std::ifstream in1; in1.open (loadfile); if (in1.fail()) if (in1.fail()) { std::cerr << "** Router: unable to open file " << loadfile << ' ' << " Load() aborted "; return; } in1 >> std::hex; EntryType::KeyType key; EntryType::DataType data; while (in1 >> key) { in1 >> data; tablePtr_->Insert(key, data); } in1.close(); std::cout << " Load() completed "; } // end Router::Load()

void Router::Save (const char* savefile) { std::ofstream out1; out1.open (savefile); if (out1.fail()) { std::cerr << "** Router: unable to open file " << savefile << ' ' << " Save() aborted "; return; }

TableType::Iterator i; out1 << std::uppercase << std::hex << std::setfill('0'); for (i = tablePtr_->Begin(); i != tablePtr_->End(); ++i) { out1 << std::setw(8) << (*i).key_ << ' ' << std::setw(8) << (*i).data_ << '\ '; } out1.close(); std::cout << " Save() completed "; } // end Router::Save()

void Router::Clear() { tablePtr_->Clear(); }

void Router::Dump(const char* dumpfile) { if (dumpfile == 0) { std::cout.setf(std::ios::uppercase); std::cout << " Size(): " << std::dec << tablePtr_->Size() << std::hex << " Dump(): "; std::cout.fill('0'); tablePtr_->Dump(std::cout,8,8); std::cout.fill(' '); std::cout.setf(std::ios::dec, std::ios::basefield); }

else { std::ofstream out1; out1.open(dumpfile); if (out1.fail()) { std::cerr << "** Router: failure to open dump file " << dumpfile << ' ' << " Dump() aborted "; return; } out1.setf(std::ios::uppercase); out1 << " Size(): " << std::dec << tablePtr_->Size() << std::hex << " Dump(): ";

out1.fill('0'); tablePtr_->Dump(out1,8,8); out1.close(); } } // end Router::Dump()

void Router::Analysis() { tablePtr_->Analysis(std::cout); }

void Router::Rehash(size_t numBuckets) { tablePtr_->Rehash(numBuckets); }

size_t ipHash::operator () (const ipNumber& ipn) const { return hashfunction::KISS (ipn); }

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!