Skip to content

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HashSet Implementation in C

This project implements a simple HashSet in C using a hash table with separate chaining for collision handling.

Features

  • 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

Project Files

  • HashSet.c - Contains the implementation of the hash set operations
  • header.h - Declares the structures and function prototypes
  • main.c - Demonstrates basic usage of the hash set

Project Architecture

  • Core structures

    • HashSet:
      • size_t capacity — number of buckets (default 1009)
      • size_t count — current number of elements
      • Node **buckets — array of bucket heads (linked lists)
    • Node:
      • int value — stored element
      • Node *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


## How to Build
Compile the program with GCC:

```bash
gcc main.c hashSet.c -o hashSet

How to Run

./hashSet

Example Behavior

The sample program adds several key-value pairs, displays them, removes some entries, and then deletes the hash map.

Notes

  • The hash table size is defined as 1009 in the header file.
  • This implementation stores integers and uses linked lists at each table index to handle collisions.

About

Lightweight C HashSet implementation with example usage and a simple test harness.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages