473,398 Members | 2,120 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

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

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

Jul 23 '05 #1
0 1698

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Randell D. | last post by:
Folks, I use PHP to write my form data to MySQL. I have a database with about ten tables. I'm trying to fill one table with some dummy data (its a contact manager table holding names of...
11
by: Randell D. | last post by:
Folks, I have a table of addresses and a seperate table with contact names - All addresses tie to one or more names - I would like to keep track of the number of names 'belonging' to an address...
0
by: Rajesh Kapur | last post by:
I have a master slave configuration on linux machines running MySQL 4.0.21. Once every hour, a process deletes about 9000 rows and re-inserts fresh data on the master. The master process completes...
2
by: Richard Hollenbeck | last post by:
In a gradebook database, every new semester, several classes will have identical groups of activities (i.e. "Participation," "Essays," "Exams, etc.) They will also have the same weights as in...
2
by: John Carnahan | last post by:
I have a problem writing the text from a multi-line textbox to the Sql Server db. If the user sends a vbcrlf (enter key) in the middle of the entered text, the text gets truncated at the vbcrlf...
11
by: Sezai YILMAZ | last post by:
Hello I need high throughput while inserting into PostgreSQL. Because of that I did some PostgreSQL insert performance tests. ------------------------------------------------------------ --...
46
by: dunleav1 | last post by:
I have a process that does inserts that runs 50% slower that Oracle and Mssql. Queries normally take 50% slower than normal. DB2, Oracle, Mssql all are configured on same os, same disk array...
3
by: Beta What | last post by:
Hello, I have a question about casting a function pointer. Say I want to make a generic module (say some ADT implementation) that requires a function pointer from the 'actual/other modules'...
2
by: Dinesh | last post by:
Hi experts, I am working on SQL Server 2005. Now i have to write a query which will extract some information from a table. My main table is having few columns supose 3 columns. EmpID ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.