quadractic probing in hash function
I am trying to do the quadractic probing in hashing function. I want to know if this is right? and how do I check if the table is full?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
//
// hash_func.h
// hash_function
//
//
#ifndef hash_func_h
#define hash_func_h
#include <iostream>
//template <typename T>
class hash_entry
{
private:
int value;
int key;
public:
hash_entry(int m_value,int m_key)
{
this->value = m_value;
this->key = m_key;
}
};
class hashMap
{
private:
hash_entry ** myTable;
public:
hashMap()
{
myTable = new hash_entry *[128];
for (int i = 0; i < 128; i++)
{
myTable[i] = NULL;
}
}
void putIntoHash(int m_value, int m_key)
{
int i = 0;
int hash = m_key % 128;
if (myTable[hash] == NULL)
{
myTable[hash] = new hash_entry(m_value, m_key);
return;
}
while (myTable[hash] != NULL)
{
i++;
hash += (i * i) % 128;
if (myTable[hash] == NULL)
{
myTable[hash] = new hash_entry(m_value, m_key);
break;
}
}
}
};
#endif /* hash_func_h */
|
Last edited on
Topic archived. No new replies allowed.