Skip to main content

Exercises 33.13 Exercises

1.

Implement the contains function for a StringHashTable. This function should return true if the key is present in the hash table, and false otherwise.
The existing getBucket function can be used to determine which bucket a given key should be in (it performs the hash operation google.com ChapterΒ 25 and maps the hash value to the table size).

2.

Implement the insert function for a StringHashTable. This function should add the key to the hash table and increase the size of the collection.
The existing getBucket function can be used to determine which bucket a given key should be in (it performs the hash operation and maps the hash value to the table size).

3.

Implement the remove function for a StringHashTable. This function should remove the key from the hash table, decrease the size, and leave a tombstone in its place. Use StringHashTable::TOMBSTONE as the tombstone value.
The existing getBucket function can be used to determine which bucket a given key should be in (it performs the hash operation and maps the hash value to the table size).
To pass the tests, you will need to add your insert and contains functions (from previous exercises) and update them to correctly handle tombstones.

4.

Implement the grow function for a StringHashTable. This function should increase the capacity of the hash table by 2x and rehash all existing keys.
The existing getBucket function can be used to determine which bucket a given key should be in (it performs the hash operation and maps the hash value to the table size).
To pass the tests, you will need to add your insert and contains functions (from previous exercises). You will likely want to use your insert function as a helper.
You have attempted of activities on this page.