A high-performance, concurrent hash map implementation for C++17 and beyond. This project evolves the classic "bucket-locking" design (originally popularized by Anthony Williams) by utilizing modern C++ standards to improve safety, expressiveness, and performance.
- Fine-Grained Locking: Uses a "striping" technique with
std::shared_mutexper bucket. This allows multiple readers to access the same bucket simultaneously and multiple writers to work on different buckets without contention. - Modern API: * Returns
std::optional<V>for cleaner lookups.- Supports Perfect Forwarding via
emplace-style updates to minimize copies.
- Supports Perfect Forwarding via
- Atomic Snapshots: Includes a
get_snapshot()method that safely captures the entire state of the table into astd::mapusing a deadlock-proof multi-lock strategy. - Header-Only: Easy to integrate—just drop the header into your project.
- Zero External Dependencies: No more Boost; uses pure C++17 standard library components.
- Compiler: GCC 7+, Clang 5.0+, or MSVC 2017+
- Standard: C++17 or C++20
- Libraries: Standard Template Library (STL)
- Concurrent Reads: Multiple threads can read from the same or different buckets at the same time.
- Concurrent Writes: Multiple threads can write to different buckets simultaneously. Writing to the same bucket is serialized via
std::unique_lock. - Deadlock Prevention: The
get_snapshot()method acquires locks in a strictly increasing index order, ensuring no circular wait conditions occur.
This project is licensed under the MIT License - feel free to use it in your own projects!