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.