Confusion about writting an insert() for a Hash Table...

J

joenchinghkg

I am going to create an method to insert Items inside the hash table,
However, i don't really know what I should code inside the method.

Should I use push or pop because it is based on a list container for my
private attribute.

Here is my code.
hashtable.h
Code:

//HashTable.h
#ifndef HASHTABLE_H
#define HASHTABLE_H

#include <list>

using namespace std;

template <typename KEYTYPE, typename VALUETYPE>
class HashTable
{
public:

void insertItem( const string& key, const VALUETYPE& value
);
VALUETYPE getItem( const string& key ) const;

void dump() const;

private:


enum { TABLESIZE = 20 };

struct KeyValuePair {
KEYTYPE key;
VALUETYPE value;
};


list<KeyValuePair> hashTable[ TABLESIZE ];


unsigned getIndex( const char* key ) const; // Hash Function


};

#include "hashtable.tem"

#endif



hashtable.tem
Code:

//hashtable.tem
template <typename KEYTYPE, typename VALUETYPE>
void HashTable<KEYTYPE,VALUETYPE>::insertItem( const string& key, const
VALUETYPE& value ) {


}

template <typename KEYTYPE, typename VALUETYPE>
void HashTable<KEYTYPE,VALUETYPE>::dump() const {

for( unsigned iCtr = 0; iCtr < TABLESIZE; iCtr++ ) {

cout << "Bucket #" << iCtr << " contains: ";

list<KeyValuePair>::const_iterator iter;
for( iter = hashTable[ iCtr ].begin(); iter != hashTable[ iCtr
].end(); ++iter ) {
cout << '[' << iter->key.c_str() << ',' << iter->value << ']'
<< ' ';
}

cout << endl;
}
}

// End of file

;)



Thanks for advice
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,125
Latest member
VinayKumar Nevatia_
Top