This project implements a simple HashSet in C using a hash table with separate chaining for collision handling.
- Creates a HashSet
- Adds elements to the set
- Removes elements from the set
- Checks whether an element exists
- Displays all stored elements
- Deletes the hash set and frees memory
HashSet.c- Contains the implementation of the hash set operationsheader.h- Declares the structures and function prototypesmain.c- Demonstrates basic usage of the hash set
-
Core structures
HashSet:size_t capacity— number of buckets (default 1009)size_t count— current number of elementsNode **buckets— array of bucket heads (linked lists)
Node:int value— stored elementNode *next— pointer to next node in the chain
-
Hashing & collisions
- Hash function maps integers into
[0, capacity)(modulo-based). - Collisions are handled with separate chaining (linked lists per bucket).
Header -->|implements| HS["HashSet\n(capacity, count, buckets[])"] HS --> Buckets["buckets[]\n(array of Node*)"] subgraph Chain[Bucket chain] Buckets --> Node["Node\n(value, next)"] Node --> NodeNext["next -> Node (link)"] end Note["Hash function: set int -> bucket index\nCollision handling: separate chaining"] HS --- Note
- Hash function maps integers into
## How to Build
Compile the program with GCC:
```bash
gcc main.c hashSet.c -o hashSet
./hashSetThe sample program adds several key-value pairs, displays them, removes some entries, and then deletes the hash map.
- The hash table size is defined as
1009in the header file. - This implementation stores integers and uses linked lists at each table index to handle collisions.