An open API service indexing awesome lists of open source software.

https://github.com/chaganti-reddy/maps_c

Hashmaps implementation in C language
https://github.com/chaganti-reddy/maps_c

c data-structures hashmap-c

Last synced: 11 months ago
JSON representation

Hashmaps implementation in C language

Awesome Lists containing this project

README

          

# maps_C

**A Basic Hashmap (Key-Value Store) Implementation in C**

---

## ๐Ÿ“š Overview

`maps_C` is a simple and lightweight **hash map** (key-value store) built using C.
It supports **insertion**, **retrieval**, **deletion**, **updating**, and **printing** of key-value pairs with dynamic memory management. Collision handling is managed through **chaining** using **linked lists**.

Perfect for:
- Practicing C programming and pointers
- Learning how basic data structures work internally
- Exploring hashing, collisions, and memory handling

---

## โš™๏ธ Features

- ๐Ÿ›  Insert a key-value pair
- ๐Ÿ”Ž Retrieve a value by key
- ๐Ÿงน Delete a key
- โœ๏ธ Update a keyโ€™s value
- ๐Ÿ“œ Print the entire hashmap
- ๐Ÿ“ Get the number of entries
- ๐Ÿงน Proper memory cleanup

---

## ๐Ÿ—‚๏ธ Project Structure

```bash
maps_C/
โ”œโ”€โ”€ LICENSE # License file (MIT)
โ”œโ”€โ”€ main.c # Program with interactive menu to use the hashmap
โ”œโ”€โ”€ map.c # Implementation of hashmap functions
โ”œโ”€โ”€ map.h # Header file (definitions and function declarations)
โ”œโ”€โ”€ Makefile # For easy compilation
โ”œโ”€โ”€ maps # Compiled executable
โ”œโ”€โ”€ README.md # Project documentation (this file)
โ”œโ”€โ”€ map.o # Object file for map.c
โ”œโ”€โ”€ main.o # Object file for main.c
```

---

## ๐Ÿš€ Getting Started

### Prerequisites
- GCC or any C compiler
- Basic familiarity with terminal commands

### Building and Running

```bash
# Clone the repository
git clone https://github.com/Chaganti-Reddy/maps_C.git
cd maps_C

# Compile using Makefile
make

# Run the executable
./maps
```

Alternatively, compile manually:
```bash
gcc main.c map.c -o maps
./maps
```

---

## ๐Ÿ“– Example Usage (Menu Options)

On running the program, you can:

```
1. Insert โ†’ Add a key-value pair
2. Get โ†’ Retrieve the value for a given key
3. Delete โ†’ Remove a key and its value
4. Print โ†’ Display all key-value pairs
5. Length โ†’ Show the number of stored pairs
6. Update โ†’ Modify the value of an existing key
7. Exit โ†’ Free memory and exit
```

---

## ๐Ÿง  Core Concepts Demonstrated

- Hashing with modulus operator
- Collision resolution with **chaining** (linked lists)
- Dynamic memory allocation with `malloc`, `calloc`, and `free`
- Modular programming in C (`.h` and `.c` separation)
- Basic CLI-based interface

---

## ๐Ÿ“‹ Limitations

- Fixed array size (`SIZE = 100`), no dynamic resizing
- Only supports integer keys and integer values
- Not thread-safe (designed for single-threaded environments)

---

## ๐Ÿ“ License

This project is licensed under the [MIT License](LICENSE).

---

## ๐Ÿค Contributing

Feel free to open issues or submit pull requests!
Improvements, optimizations, and feature additions are very welcome.