Skip to content

Latest commit

Β 

History

History
120 lines (84 loc) Β· 2.79 KB

File metadata and controls

120 lines (84 loc) Β· 2.79 KB

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

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

# 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:

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.


🀝 Contributing

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