This project is a high-performance, thread-safe in-memory key-value store implemented in modern C++. It uses a Radix Trie as its core data structure to efficiently store key-value pairs while also supporting lexicographical ordering operations.
The primary goal of this project is to demonstrate advanced C++ concepts, including multi-threading, modern memory management, and complex data structure implementation.
- Thread-Safe Operations: All public APIs—
put,get, anddel—are fully thread-safe, allowing for concurrent access from multiple threads. - High-Performance Concurrency: Utilizes a
std::shared_mutex(reader-writer lock) to allow multiple threads to read data simultaneously, dramatically increasing performance in read-heavy workloads. - Efficient Radix Trie Structure: Employs a space-optimized Radix Trie, which provides fast lookups and enables unique features like Nth-element searching.
- Modern C++ Implementation: Written in C++17, the project leverages modern features for safety and performance:
- RAII & Smart Pointers: Automatic memory management with
std::unique_ptrto prevent memory leaks. - RAII-Style Locking: Exception-safe mutex handling with
std::unique_lockandstd::shared_lock. - Performance-Oriented Types: Use of
std::string_viewto avoid unnecessary string copies in API calls.
- RAII & Smart Pointers: Automatic memory management with
- Cross-Platform Build System: Uses CMake for easy, cross-platform project configuration and compilation.
This project is an excellent showcase of the following skills:
- Concurrency and Parallelism:
- Deep understanding of race conditions and data protection.
- Implementation of reader-writer locks for performance optimization.
- Use of the C++17 threading library (
std::thread,std::shared_mutex).
- Advanced Data Structures:
- Custom implementation of a Radix Trie, including complex operations like node splitting.
- Understanding of tree traversal and manipulation algorithms.
- Modern C++ Best Practices:
- Resource Acquisition Is Initialization (RAII) for managing resources like memory and locks.
- Automatic memory management with smart pointers.
- Object-Oriented Design with clear separation of concerns (data structure vs. thread-safe wrapper).
The codebase is organized to be modular and easy to understand.
├── CMakeLists.txt # The build script for CMake
├── main.cpp # Example usage and multi-threading demonstration
├── kv_store.hpp # Header for the public-facing thread-safe KVStore class
├── kv_store.cpp # Implementation of public-facing thread-safe KVStore class
├── trie.hpp # Header for the core Trie data structure
└── trie.cpp # Implementation of the Trie logic
This project uses CMake, which makes it easy to build on any platform.
- A C++17 compliant compiler (e.g., GCC 7+, Clang 5+, MSVC 2017+).
- CMake (version 3.10 or newer).
-
Clone the repository:
git clone <your-repository-url> cd <your-repository-name>
-
Create a build directory:
mkdir build cd build -
Configure the project with CMake:
cmake ..
-
Compile the project:
cmake --build .(On Linux/macOS, you can also just run
makeinside thebuilddirectory). -
Run the application: The compiled executable will be in the
builddirectory../kv_app