Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // File:hashTable.cpp
- // hashTable Class implementation file
- #include <iostream>
- using namespace std;
- // Constructor with argument, size is nelements, default is 11
- template <class keyType, class dataType>
- hashTable<keyType, dataType>::hashTable(int nelements)
- {
- //Set Maximum Size = nelemts
- //Allocate memory
- //Initialize h (the index to a slot) to -1
- //Initialize csize (current size)
- }
- // Destructor
- template <class keyType, class dataType>
- hashTable<keyType, dataType>::~hashTable()
- { //Free allocated memory
- }
- // Empty all slots in the table (Fill table with Empty key)
- template <class keyType, class dataType>
- void hashTable<keyType, dataType>::emptyTable(const keyType &k)
- {
- //Set the empty value = k
- //Loop to put the Empty (k) value in all table slots
- //Initialize h (index to a slot) to -1
- //Initialize current size csize to 0
- }
- // return True if table is empty
- template <class keyType, class dataType>
- bool hashTable<keyType, dataType>::tableIsEmpty() const
- {
- //Test current size (csize)
- }
- // return True if table is full
- template <class keyType, class dataType>
- bool hashTable<keyType, dataType>::tableIsFull() const
- {
- //Test current size (csize)
- }
- // insert key and data at a hashed slot
- template <class keyType, class dataType>
- bool hashTable<keyType, dataType>::insert(const keyType &k, const dataType &d)
- {
- /*if table is not full
- find (h) using the hash function passing to it (k)
- loop until find an empty slot (circular array: h = (h+1) % MaxSize)
- insert key and data at the found empty slot (h)
- return true;
- else return false;
- */
- }
- // Search the table for the slot that matches key.
- // If found, return True, set current position to slot
- template <class keyType, class dataType>
- bool hashTable<keyType, dataType>::search(const keyType &k)
- {
- /*if table is not empty
- {
- find h by calling the hash function passing to it k
- int start = h; //keep the starting point
- for ( ; ; ) loop until either found or reach empty slot or reach start again
- {
- if slot h is empty return false; //not found
- if there is a match at h return true; //found
- h = (h+1) % MaxSize; //move to next slot
- if (h == start) return false; //Back to start again
- }
- }
- else return false;
- */
- }
- // Private Hashing Function
- template <class keyType, class dataType>
- int hashTable<keyType, dataType>::hash(const keyType &k) const
- {
- return (k % MaxSize);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement