?
Solved

Why does my hash table have blank fields

Posted on 2004-11-10
4
Medium Priority
?
250 Views
Last Modified: 2010-04-01
Good afternoon, I am sorry to bother and I am just stuck and not sure of something. I am creating a hash table with with my load factor a prime number and I am loading it into a vector. Now when I search for a value in my hash table. It is saying it isn't found because once it finds a blank field it thinks it is done. Now is my hash table supposed to have blank spots and if so how do I get pass that in my search knowing that I have not looked through the entire hash table? Thanks for the help
0
Comment
Question by:Corey_819
4 Comments
 
LVL 16

Accepted Solution

by:
PaulCaswell earned 120 total points
ID: 12553400
There should be blank spots in your table but they should signify that the search has failed.

When adding items, the hash function calculates a 'first' location to look in for the item. If that location is already occupied with a different record, the next free location is taken.

When searching for items, the same hash function should generate the same location to begin searching.

I would suggest that your implementation is incorrect for adding items.

Paul
0
 
LVL 10

Expert Comment

by:Sys_Prog
ID: 12553402
Please post some code so thtaw we could help in a better way

Amit
0
 

Expert Comment

by:eranif
ID: 12572927
You said that you are using vector is this the STL vector ?
What data type are you using to hold the raws?

is it something like this?

typedef std::vector<std::string> myRaw;
std::map<unsigned long,myRaw*> myHash

// lets say you want to remove element with value 1234566767:

keyToRemove = 1234566767
myRaw *raw = myHash[keyToRemove ];//return the vector with this value

while ( /* iterate the raw*/ )
{
    if( *raw[i] == value_to_remove)
    {
        raw->erase(i);
    }
}
 

0
 
LVL 1

Author Comment

by:Corey_819
ID: 12583979
Thanks PaulCaswell I did figure it out I was not realizing but after I displayed my vector it was getting cleared out with all my data. And I didn't see it because I saw it being displayed when I was running my program. Thanks for the help though. :)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question