Updating Hash Container Implementation
Lab Assignment
Use the implementation of the
basic
hashmap template that we studied and do the following
modifications:
- modify the implementation of insert() so that it
provides "safe insert", i.e.: returns a pair: <pointer,
result>, where
- pointer is a pointer to the newly inserted value
or the old value with the same key
- result is a boolean value which is true
if the element is inserted
- on the basis of your updated insert() implementation,
modify the implementation of the overloaded indexing
operator [] to eliminate inefficient second invocation
of find(). That is, in your
implementation, find() should only be invoked once.
- modify the implementation of erase() so that it
returns a pair <pointer, result>, where
- pointer is a pointer to the element past the one
erased. Note that if the next element in a different bucket, it
should still be returned. In case the element with the key
specified to erase() does not exist, the value of the
returned pointer is unspecified. If there are no elements following
the erased element, erase() should
return nullptr.
- result is a boolean value which is true
if the element is successfully erased; result is
false if the element with the specified key is not present
in the container.
- implement void rehash(size_t n) sets the number of
buckets in the container to n. Note that the existing
elements need to be re-arranged according to their new hash
value. Note also that Hash: the object that provides
hashing, needs to be updated to contain the new number of
buckets. If the parameter n is smaller than the current
number of buckets, no actions need to be taken.
Here is example test code that your implementation should work with.
Milestone: insert() modification.