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< Entry > | double_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

{
int cmd = 0, hash = 0, key = 0;
std::cout << "Enter the initial size of Hash Table. = ";
std::cin >> totalSize;
table = std::vector<Entry>(totalSize);
bool loop = true;
while (loop) {
std::cout << std::endl;
std::cout << "PLEASE CHOOSE -" << std::endl;
std::cout << "1. Add key. (Numeric only)" << std::endl;
std::cout << "2. Remove key." << std::endl;
std::cout << "3. Find key." << std::endl;
std::cout << "4. Generate Hash. (Numeric only)" << std::endl;
std::cout << "5. Display Hash table." << std::endl;
std::cout << "6. Exit." << std::endl;
std::cin >> cmd;
switch (cmd) {
case 1:
std::cout << "Enter key to add = ";
std::cin >> key;
double_hashing::addInfo(key);
break;
case 2:
std::cout << "Enter key to remove = ";
std::cin >> key;
double_hashing::removalInfo(key);
break;
case 3: {
std::cout << "Enter key to search = ";
std::cin >> key;
Entry entry = table[double_hashing::doubleHash(key, true)];
if (entry.key == double_hashing::notPresent) {
std::cout << "Key not present";
}
break;
}
case 4:
std::cout << "Enter element to generate hash = ";
std::cin >> key;
std::cout << "Hash of " << key
<< " is = " << double_hashing::hashFxn(key);
break;
case 5:
double_hashing::display();
break;
default:
loop = false;
break;
// delete[] table;
}
std::cout << std::endl;
}
return 0;
}
std::cin
std::cout
std::endl
T endl(T... args)
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
double_hashing::removalInfo
void removalInfo(int key)
Definition: double_hash_hash_table.cpp:227
double_hashing::doubleHash
int doubleHash(int key, bool searching)
Performs double hashing to resolve collisions.
Definition: double_hash_hash_table.cpp:71
double_hashing::addInfo
void addInfo(int key)
Definition: double_hash_hash_table.cpp:212
double_hashing::Entry
Definition: double_hash_hash_table.cpp:36
double_hashing::Entry::key
int key
key value
Definition: double_hash_hash_table.cpp:38
std::vector