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.
Asked
Active
Viewed 237 times
0

abhishek_naik
- 1,287
- 2
- 15
- 27

bb13
- 9
- 6
-
Maybe each bucket has a `bool` flag? – Galik Mar 26 '17 at 03:49
-
i thought of this....but how would you implement each bucket as contatining a bool on creation? – bb13 Mar 26 '17 at 04:02
1 Answers
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