TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
Loading...
Searching...
No Matches
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:

Go to the source code of this file.

Classes

struct  double_hashing::Entry
 

Namespaces

namespace  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.
 
size_t double_hashing::otherHashFxn (int key)
 Used for second hash function.
 
int double_hashing::doubleHash (int key, bool searching)
 Performs double hashing to resolve collisions.
 
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.

Definition in file double_hash_hash_table.cpp.

Function Documentation

◆ main()

int main ( void )

Main program

Returns
0 on success

Definition at line 250 of file double_hash_hash_table.cpp.

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}
void * hash(const std::string &message)
Converts the string to bytestring and calls the main algorithm.
Definition md5.cpp:288
size_t hashFxn(int key)
Hash a key. Uses the STL library's std::hash() function.
int doubleHash(int key, bool searching)
Performs double hashing to resolve collisions.
int key
key value