← All projectsCOSC 50 / Systems

Data structures in C

Bags, sets, counters, and hash tables with tests.

Four reusable containers

This COSC 50 lab implements a bag, set, counters collection, and hash table in C. The bag stores unordered items. The set maps unique string keys to items. Counters map integer keys to counts. The hash table uses an array of sets to store unique key-item pairs by hash slot.

Memory ownership and callbacks

Each container exposes creation, insertion, lookup or extraction, iteration, printing, and deletion functions. The generic containers store void pointers and receive callbacks for printing, iteration, and cleanup, so callers retain control over the items stored in each structure.

What the local tests exercised

In an isolated build, all four original test targets completed successfully. The bag test inserted seven names, moved them into a second bag, and checked both counts. The counters test checked increment, lookup, set, print, iteration, and deletion. Set and hash-table tests checked lookup, duplicate-key rejection, iteration, and cleanup.

Actual output from local counters and hash-table test programs.
The compiled tests exercise counts, lookups, duplicate rejection, bucket placement, iteration, and cleanup. View full size (new tab): Actual output from local counters and hash-table test programs.
Mithun RameshkumarDartmouth College