Algorithms_in_C++  1.0.0
Set of algorithms implemented in C++.
double_hash_hash_table.cpp File Reference

Storage mechanism using double-hashed keys. More...

#include <iostream>
#include <memory>
#include <vector>
Include dependency graph for double_hash_hash_table.cpp:

Classes

struct  double_hashing::Entry
 

Namespaces

 double_hashing
 An implementation of hash table using double hashing algorithm.
 

Typedefs

using double_hashing::Entry = struct Entry
 

Functions

bool double_hashing::putProber (const Entry &entry, int key)
 
bool double_hashing::searchingProber (const Entry &entry, int key)
 
void double_hashing::add (int key)
 
size_t double_hashing::hashFxn (int key)
 Hash a key. Uses the STL library's std::hash() function. More...
 
size_t double_hashing::otherHashFxn (int key)
 Used for second hash function. More...
 
int double_hashing::doubleHash (int key, bool searching)
 Performs double hashing to resolve collisions. More...
 
void double_hashing::display ()
 
void double_hashing::rehash ()
 
void double_hashing::remove (int key)
 
void double_hashing::addInfo (int key)
 
void double_hashing::removalInfo (int key)
 
int main ()
 

Variables

int double_hashing::notPresent
 
std::vector< Entrydouble_hashing::table
 
int double_hashing::totalSize
 
int double_hashing::tomb = -1
 
int double_hashing::size
 
bool double_hashing::rehashing
 

Detailed Description

Storage mechanism using double-hashed keys.

Author
achance6
Krishna Vedala
Note
The implementation can be optimized by using OOP style.

Function Documentation

◆ main()

int main ( void  )

Main program

Returns
0 on success
250  {
251  int cmd = 0, hash = 0, key = 0;
252  std::cout << "Enter the initial size of Hash Table. = ";
253  std::cin >> totalSize;
254  table = std::vector<Entry>(totalSize);
255  bool loop = true;
256  while (loop) {
257  std::cout << std::endl;
258  std::cout << "PLEASE CHOOSE -" << std::endl;
259  std::cout << "1. Add key. (Numeric only)" << std::endl;
260  std::cout << "2. Remove key." << std::endl;
261  std::cout << "3. Find key." << std::endl;
262  std::cout << "4. Generate Hash. (Numeric only)" << std::endl;
263  std::cout << "5. Display Hash table." << std::endl;
264  std::cout << "6. Exit." << std::endl;
265  std::cin >> cmd;
266  switch (cmd) {
267  case 1:
268  std::cout << "Enter key to add = ";
269  std::cin >> key;
271  break;
272  case 2:
273  std::cout << "Enter key to remove = ";
274  std::cin >> key;
276  break;
277  case 3: {
278  std::cout << "Enter key to search = ";
279  std::cin >> key;
280  Entry entry = table[double_hashing::doubleHash(key, true)];
281  if (entry.key == double_hashing::notPresent) {
282  std::cout << "Key not present";
283  }
284  break;
285  }
286  case 4:
287  std::cout << "Enter element to generate hash = ";
288  std::cin >> key;
289  std::cout << "Hash of " << key
290  << " is = " << double_hashing::hashFxn(key);
291  break;
292  case 5:
294  break;
295  default:
296  loop = false;
297  break;
298  // delete[] table;
299  }
300  std::cout << std::endl;
301  }
302  return 0;
303 }
double_hashing::Entry
Definition: double_hash_hash_table.cpp:36
double_hashing::addInfo
void addInfo(int key)
Definition: double_hash_hash_table.cpp:212
double_hashing::removalInfo
void removalInfo(int key)
Definition: double_hash_hash_table.cpp:227
std::vector
STL class.
std::cout
double_hashing::hashFxn
size_t hashFxn(int key)
Hash a key. Uses the STL library's std::hash() function.
Definition: double_hash_hash_table.cpp:47
double_hashing::display
void display()
Definition: double_hash_hash_table.cpp:143
std::endl
T endl(T... args)
double_hashing::doubleHash
int doubleHash(int key, bool searching)
Performs double hashing to resolve collisions.
Definition: double_hash_hash_table.cpp:71
double_hashing::Entry::key
int key
key value
Definition: double_hash_hash_table.cpp:38
std::cin