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

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


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

WEBINAR:

On-Demand

Application Security Testing: An Integral Part of DevOps


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