Why does my hash table have blank fields

Posted on 2004-11-10
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
Question by:Corey_819
    LVL 16

    Accepted Solution

    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.

    LVL 10

    Expert Comment

    Please post some code so thtaw we could help in a better way


    Expert Comment

    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)

    LVL 1

    Author Comment

    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. :)

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
    Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
    The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
    The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

    755 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

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now