// CMSC 341 - Fall 2026 - Project 4 #ifndef DEALER_H #define DEALER_H #include #include #include "math.h" using namespace std; class Grader; class Tester; class Car; class CarDB; const int MINID = 100000; // dealer ID const int MAXID = 999999; // dealer ID const int MINQUANTITY = 1; const int MAXQUANTITY = 10; const int MINPRIME = 101; // Min size for hash table const int MAXPRIME = 99991; // Max size for hash table #define EMPTY Car("",0,0,false) #define DELETED Car("DELETED") #define DELETEDKEY "DELETED" typedef unsigned int (*hash_fn)(string); // declaration of hash function enum prob_t {QUADRATIC, DOUBLEHASH, LINEAR}; // types of collision handling policy #define DEFPOLCY QUADRATIC class Car{ friend class Tester; friend class Grader; friend class CarDB; public: Car(string model = "", int quantity = 0, int dealer = 0, bool used = false) { m_model = model; m_quantity = quantity; m_dealer = dealer; m_used = used; } void setModel(string model){m_model=model;} void setQuantity(int quantity){m_quantity=quantity;} void setDealer(int dealer){m_dealer=dealer;} void setUsed(bool used){m_used=used;} string getModel() const {return m_model;} int getQuantity() const {return m_quantity;} int getDealer() const {return m_dealer;} bool getUsed() const {return m_used;} // overloaded assignment operator const Car& operator=(const Car& rhs){ if (this != &rhs){ m_model = rhs.m_model; m_quantity = rhs.m_quantity; m_dealer = rhs.m_dealer; m_used = rhs.m_used; } return *this; } // the following function is a friend function friend ostream& operator<<(ostream& sout, const Car *car ){ if ((car != nullptr) && !(car->getModel().empty())) sout << car->getModel() << " (" << car->getDealer() << ", "<< car->getUsed() << ")"; else sout << ""; return sout; } // the following function is a friend function friend bool operator==(const Car& lhs, const Car& rhs){ // since the uniqueness of an object is defined by key and ID // the equality operator considers only those two criteria return ((lhs.getModel() == rhs.getModel()) && (lhs.getDealer() == rhs.getDealer())); } // the following function is a class function bool operator==(const Car* & rhs){ // since the uniqueness of an object is defined by sequence and ID // the equality operator considers only those two criteria return ((getModel() == rhs->getModel()) && (getDealer() == rhs->getDealer())); } private: string m_model; // car type, the search string used as key in the hash table int m_quantity; // number of card delivered to the dealer int m_dealer; // dealer information, car model and dealer together determine uniqueness of a Car object // the following variable is used for lazy delete scheme in hash table // if it is set to false, it means the bucket in the hash table is free for insert // if it is set to true, it means the bucket contains live data, and we cannot overwrite it bool m_used; }; class CarDB{ public: friend class Grader; friend class Tester; CarDB(int size, hash_fn hash, prob_t probing); ~CarDB(); // Returns Load factor of the new table float lambda() const; // Returns the ratio of deleted slots in the new table float deletedRatio() const; // insert only happens in the new table bool insert(Car car); // remove can happen from either table bool remove(Car car); // find can happen in either table const Car getCar(string model, int dealer) const; // update the information bool updateDealer(Car car, int dealer); void changeProbPolicy(prob_t policy); void dump() const; private: hash_fn m_hash; // hash function prob_t m_newPolicy; // stores the change of policy request Car** m_currentTable; // hash table int m_currentCap; // hash table size (capacity) int m_currentSize; // current number of entries // m_currentSize includes deleted entries int m_currNumDeleted;// number of deleted entries prob_t m_currProbing; // collision handling policy Car** m_oldTable; // hash table int m_oldCap; // hash table size (capacity) int m_oldSize; // current number of entries // m_oldSize includes deleted entries int m_oldNumDeleted; // number of deleted entries prob_t m_oldProbing; // collision handling policy int m_transferIndex; // this can be used as a temporary place holder // during incremental transfer to scanning the table //private helper functions bool isPrime(int number); int findNextPrime(int current); /****************************************** * Private function declarations go here! * ******************************************/ }; #endif