1
1
mirror of https://github.com/theoludwig/libcproject.git synced 2025-05-21 23:21:15 +02:00

feat: add hash_map data structure

fixes #3
This commit is contained in:
2023-06-25 19:32:45 +02:00
parent 931a0b69ce
commit 4a11a096fa
8 changed files with 275 additions and 0 deletions

View File

@ -109,3 +109,21 @@ void terminal_print_dictionary(struct dictionary* dictionary, void (*print_eleme
}
printf("}\n");
}
void terminal_print_hash_map(struct hash_map* hash_map, void (*print_element)(void*)) {
if (hash_map == NULL) {
exit(EXIT_FAILURE);
}
printf("{\n");
string_t* keys = hash_map_get_keys(hash_map);
for (size_t index = 0; index < hash_map->length; index++) {
string_t key = keys[index];
void* value = hash_map_get(hash_map, key);
printf("\t\"");
terminal_print_string(key);
printf("\" -> ");
print_element(&value);
printf("\n");
}
printf("}\n");
}