Simple hashmap implementation in C
Key has to be a string, but the value can be any pointer.
Map *map = malloc(sizeof(Map));
init_map(map); // initializes with NULL values
if(put_in_map(map, "key", "value") != 0) {
// error: could not place in map
}
int value = 12;
if(put_in_map(map, "key", &value) != 0) {
// error: could not place in map
}
int *value = get_from_map(map, "key");
if(value == NULL) {
// error: could not find in map
}
printf("%d\n", *value);
if(remove_from_map(map, "key") != 0){
// error: could not remove from map
}
PRINT_MAP(map //name of map, "%s" //printf symbol for value, (char*) //value data type);
delete_and_free_map(map);