Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Algorithms
Expertise: Beginner
Apr 1, 1999

Hash Tables

Question:
How can I implement a hash table such that each "bucket" is associated with two independent keys? I need to be able to store two data per bucket that are associated with each other. In one case, I'm given one of the values and will need to return it's corresponding value. In the other case, it's just the opposite. So, I need to be able to search with each of the two datum at one point acting as the key. Is this possible with a hash table? And if so, I how do I implement this? I have already consulted the recommended texts (Algorithms in C++ by Robert Sedgewick and Practical Algorithms in C++ by Brian Flamig). Neither seem to address this issue.

Answer:
This is not possible unless you know in advance what your data set will be. If you knew that, you might get by without using a hash table at all.

It sounds like what you really want is a simple structure that contains both a key and value, and then find an algorithm for looking up the key and return the corresponding value.

I can't very well provide more details, however, without knowing the nature of the data you want to store.

DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date