Skip to content

NotACat1/Thread-Safe-Lookup-Table

Repository files navigation

Modern Thread-Safe Lookup Table

C++ Build License

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.

🚀 Features

  • Fine-Grained Locking: Uses a "striping" technique with std::shared_mutex per 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.
  • Atomic Snapshots: Includes a get_snapshot() method that safely captures the entire state of the table into a std::map using 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.

🛠 Requirements

  • Compiler: GCC 7+, Clang 5.0+, or MSVC 2017+
  • Standard: C++17 or C++20
  • Libraries: Standard Template Library (STL)

🔒 Thread Safety Guarantees

  • 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.

📜 License

This project is licensed under the MIT License - feel free to use it in your own projects!

About

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.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages