#include #include #include "Counter.h" #include "HashTable.h" struct counter { // TODO HashTable ht; }; Counter CounterNew(void) { Counter c = malloc(sizeof(*c)); if (c == NULL) { fprintf(stderr, "error: out of memory\n"); exit(EXIT_FAILURE); } // TODO c->ht = HashTableNew(); return c; } void CounterFree(Counter c) { // TODO HashTableFree(c->ht); free(c); } void CounterAdd(Counter c, int item) { // TODO int count = HashTableGetOrDefault(c->ht, item, 0); HashTableInsert(c->ht, item, count + 1); //if (!HashTableContains(c->ht, item)) { // HashTableInsert(c->ht, item, 1); //} else { // int count = HashTableGet(c->ht, item); // HashTableInsert(c->ht, item, count + 1); //} } int CounterGet(Counter c, int item) { // TODO return HashTableGetOrDefault(c->ht, item, 0); //if (HashTableContains(c->ht, item)) { // return HashTableGet(c->ht, item); //} else { // return 0; //} }