Complete the code to declare a hash map that stores integer keys and values.
typedef struct {
int key;
int value;
} HashMapEntry;
HashMapEntry map[[1]];The hash map is declared as an array of entries with a fixed size, here 100.
Complete the code to compute the hash index for a given key.
int hashFunction(int key) {
return key [1] 100;
}The modulo operator (%) is used to ensure the hash index fits within the array size.
Fix the error in the code that inserts a key-value pair into the hash map.
void insert(HashMapEntry map[], int key, int value) {
int index = hashFunction(key);
map[index].key = key;
map[index].[1] = value;
}The value field of the map entry must be assigned the given value.
Fill both blanks to complete the code that retrieves a value by key from the hash map.
int getValue(HashMapEntry map[], int key) {
int index = hashFunction(key);
if (map[index].key == [1]) {
return map[index].[2];
}
return -1; // not found
}Check if the stored key matches the requested key, then return the stored value.
Fill all three blanks to complete the code that handles collision by linear probing in the hash map insertion.
void insert(HashMapEntry map[], int key, int value) {
int index = hashFunction(key);
while (map[index].key != -1 && map[index].key != [1]) {
index = (index [2] 1) [3] 100;
}
map[index].key = key;
map[index].value = value;
}Check if the slot is occupied by a different key, then move to the next index using addition and modulo to wrap around.
