linear_probing_hash_table.cpp File Reference

Storage mechanism using linear probing hash keys. More...

`#include <iostream>`
`#include <vector>`
Include dependency graph for linear_probing_hash_table.cpp:

## Classes

struct | linear_probing::Entry

## Namespaces

| linear_probing
| An implementation of hash table using linear probing algorithm.

## Typedefs

using | linear_probing::Entry = struct Entry

## Functions

bool | linear_probing::putProber (const Entry &entry, int key)
bool | linear_probing::searchingProber (const Entry &entry, int key)
void | linear_probing::add (int key)
size_t | linear_probing::hashFxn (int key)
| Hash a key. Uses the STL library's `std::hash()` function. More...
int | linear_probing::linearProbe (int key, bool searching)
void | linear_probing::display ()
void | linear_probing::rehash ()
void | linear_probing::remove (int key)
void | linear_probing::addInfo (int key)
void | linear_probing::removalInfo (int key)
int | main ()

## Variables

int | linear_probing::notPresent
std::vector< Entry > | linear_probing::table
int | linear_probing::totalSize
int | linear_probing::tomb = -1
int | linear_probing::size
bool | linear_probing::rehashing

## Detailed Description

Storage mechanism using linear probing hash keys.

Author
  achance6
  Krishna Vedala

Note
  The implementation can be optimized by using OOP style.

## Function Documentation

## main()

int main | ( | void |  | ) |

Main function

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;
linear_probing::addInfo(key);
break;
case 2:
std::cout << "Enter key to remove = ";
std::cin >> key;
linear_probing::removalInfo(key);
break;
case 3: {
std::cout << "Enter key to search = ";
std::cin >> key;
Entry entry = table[linear_probing::linearProbe(key, true)];
if (entry.key == linear_probing::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 = " << linear_probing::hashFxn(key);
break;
case 5:
linear_probing::display();
break;
default:
loop = false;
break;
// delete[] table;
}
std::cout << std::endl;
}
return 0;
}
std::cin
std::cout
std::endl
T endl(T... args)
linear_probing::addInfo
void addInfo(int key)
Definition: linear_probing_hash_table.cpp:186
linear_probing::hashFxn
size_t hashFxn(int key)
Hash a key. Uses the STL library's std::hash() function.
Definition: linear_probing_hash_table.cpp:46
linear_probing::linearProbe
int linearProbe(int key, bool searching)
Definition: linear_probing_hash_table.cpp:55
linear_probing::removalInfo
void removalInfo(int key)
Definition: linear_probing_hash_table.cpp:201
linear_probing::display
void display()
Definition: linear_probing_hash_table.cpp:120
linear_probing::Entry
Definition: linear_probing_hash_table.cpp:35
linear_probing::Entry::key
int key
key value
Definition: linear_probing_hash_table.cpp:37
std::vector