Skip to main content

Practice ยท 1 of 2

Build an Opaque Handle

Implement an opaque multi-counter. The boilerplate declares: ``c typedef struct MCounter MCounter; MCounter *mc_create(void); /* NULL on oom */ int mc_bump(MCounter *m, const char *key, int by); /* 0 ok, -1 args/oom */ int mc_get(const MCounter *m, const char *key); /* count, 0 if absent */ size_t mc_keys(const MCounter *m); /* number of distinct keys */ void mc_destroy(MCounter *m); ` Keys are short (<= 15 chars). Store them however you like โ€” the tests only see the API. The constructor must leave a valid object for mc_keys() == 0 and mc_get(...) == 0`; every function must tolerate NULL handles.

Difficulty: intermediate

Back to lesson: Practice: Modeling & Ownership Gym