#include<cstdio>
#include<map>
#include<vector>
#include<cstdlib>
using namespace std;
// It is not advisable to list all elements in this hash table.
#define HASH_SIZE 51439
class HashTable
{
public:
vector< map<long long,int> > table;
HashTable()
{
table = vector< map<long long,int> >(HASH_SIZE);
}
int hashF(long long key)
{
if( key < 0)
{
key = key + HASH_SIZE*( abs(key)/HASH_SIZE + 1);
}
return key%HASH_SIZE;
}
pair< map<long long,int>::iterator, bool > insert(long long key, int
value)
{
int index = hashF(key);
return table[index].insert(pair<long long,int>(key,value));
}
int getCount(long long key)
{
int index = hashF(key);
int count = table[index].count(key);
return count;
}
int getValue(long long key)
{
int index = hashF(key);
return table[index][key];
}
};
On Sat, Sep 3, 2011 at 10:44 AM, Rahul Verma <[email protected]>wrote:
> I am facing some difficulty in the implementation of Hash Table. Anyone can
> please share the good resources for Hash Table?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/algogeeks/-/DmcDxyNXfwEJ.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.