A Basic Hashmap (Key-Value Store) Implementation in C
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
- 🛠 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
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- GCC or any C compiler
- Basic familiarity with terminal commands
# Clone the repository
git clone https://github.com/Chaganti-Reddy/maps_C.git
cd maps_C
# Compile using Makefile
make
# Run the executable
./mapsAlternatively, compile manually:
gcc main.c map.c -o maps
./mapsOn 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
- Hashing with modulus operator
- Collision resolution with chaining (linked lists)
- Dynamic memory allocation with
malloc,calloc, andfree - Modular programming in C (
.hand.cseparation) - Basic CLI-based interface
- Fixed array size (
SIZE = 100), no dynamic resizing - Only supports integer keys and integer values
- Not thread-safe (designed for single-threaded environments)
This project is licensed under the MIT License.
Feel free to open issues or submit pull requests!
Improvements, optimizations, and feature additions are very welcome.