CS 70

Erasing Elements

In this part, you'll implement the erase method for your HashMultiset<T>. This method removes a key from the multiset, if it's there.

What erase Means for a Multiset

Your erase should remove the key and its whole count, the way std::unordered_multiset's erase(key) does: afterwards count(key) is 0, size() has dropped by the key's old count, and there's one fewer distinct key (so the load factor drops too). If the key isn't there, erase does nothing.

Your Task

Implement the erase member function for your HashMultiset<T> class template, with this signature:

void erase(const T& key);

Find the key's bucket the same way count does. Your chains hold KeyCounts, not Ts, so std::forward_list's remove(value) won't do: either use remove_if with a lambda that compares each KeyCount's key, or walk the chain yourself with before_begin() and erase_after. Either way, you'll need the key's count before it's gone, to fix up size.

When You're Done

Don't forget to add some details about what you did to Fun.md. The sample solution doesn't have erase, so before you submit, comment out any tests in hashmultiset-test.cpp that use it (our tests of your tests run them against the sample solution).

(When logged in, completion status appears here.)