11int main(
int argc,
char *argv[]) {
13 printf(
"Usage: %s <word1> <word2> ...\n", argv[0]);
14 printf(
"Counts occurrences of each word.\n");
15 printf(
"Example: %s the quick brown fox the lazy dog the\n", argv[0]);
20 if (!ht)
return EXIT_FAILURE;
22 for (
int i = 1; i < argc; i++) {
24 ht_get(ht, argv[i], ¤t);
25 if (!
ht_set(ht, argv[i], current + 1)) {
26 fprintf(stderr,
"out of memory\n");
32 printf(
"Counts (size=%zu, capacity=%zu):\n",
34 for (
int i = 1; i < argc; i++) {
36 if (
ht_get(ht, argv[i], &count)) {
37 printf(
" %-20s %d\n", argv[i], count);
size_t ht_capacity(const hash_table_t *ht)
bool ht_set(hash_table_t *ht, const char *key, int value)
bool ht_remove(hash_table_t *ht, const char *key)
hash_table_t * ht_create(void)
bool ht_get(const hash_table_t *ht, const char *key, int *out)
size_t ht_size(const hash_table_t *ht)
void ht_destroy(hash_table_t *ht)
Open-addressing string→int hash table with linear probing.