0

I have been having some trouble finding a decent explanation on this. I am writing a linear probing hash table using C++, but I am having trouble with the remove() operation. I am hashing a dictionary collection of strings, and I am wondering how I would set the index i remove from as deleted, so the search() and insert() work properly. Any help/pseudocode would be great, thank you. My best guess right now, is to make some sort of struct object called deleted and place it there.

abhishek_naik
  • 1,287
  • 2
  • 15
  • 27
bb13
  • 9
  • 6

1 Answers1

0

Each bucket could be a struct containing the key, value and a flag to indicate if the bucket is empty like this:

struct bucket
{
    std::string key;
    std::string value;
    bool empty = true;
};

Then you could have a std::vector of such buckets:

class hash_table
{
public:
    hash_table(): buckets(100) {} // hash table has 100 buckets

    void put(std::string const& key, std::string const& value)
    {
        // ...
    }

    // etc...

private:
    std::vector<bucket> buckets; // the table
};
Galik
  • 47,303
  • 4
  • 80
  • 117