Header-only C++14 lock-free ring-buffer queues for passing messages between threads with minimal push-to-pop latency.
greg7mdp/parallel-hashmap
A header-only C++ library of fast, memory-friendly hash maps, sets, and B-tree containers that can replace the std unordered and ordered containers.
- Stars
- 3,223
- Forks
- 313
- Open issues
- 4
- Last commit
- last month
What is it?
Parallel Hashmap (phmap) is a C++ library of hash map and set implementations, plus B-tree based ordered containers that serve as alternatives to std::map and std::set. It is header-only: you copy the parallel_hashmap directory into a project and include it, with no build step. The hash tables are drop-in replacements for std::unordered_map and std::unordered_set, and the B-trees for std::map and std::set.
The hash tables use closed hashing with values stored directly in a memory array, which reduces indirection. The library is built on code adapted from Abseil's swiss table and B-tree implementations. Parallel variants split a table into submaps, which lowers peak memory during resizing and allows internal locking for concurrent reads and writes when a mutex type is supplied.
The flat hash maps can also be dumped to disk and restored as a single array when stored types are trivially copyable. Forward declaration headers are provided, and the library supports heterogeneous lookup and C++11 through C++17 APIs.
Key features
- 01Header-only, with no build required beyond the include path.
- 02Drop-in replacements for std::unordered_map, std::unordered_set, std::map and std::set.
- 03Parallel hash maps split into submaps, with optional internal locking for concurrent access.
- 04Flat tables can be dumped to disk and restored as a single array for trivially copyable types.
- 05Supports heterogeneous lookup and C++11 through C++17 APIs such as try_emplace.
Use cases
- Replacing std::unordered_map in performance-sensitive C++ code.
- Storing very large numbers of entries where lower memory use matters.
- Building multithreaded services that share a hash table across threads with internal locking.
- Persisting large lookup tables quickly by dumping them to disk as a binary array.
Quick start
- 1
Copy the parallel_hashmap directory into your project and add it to the include path
- 2
Build and run the tests and examples with CMake
cmake -DPHMAP_BUILD_TESTS=ON -DPHMAP_BUILD_EXAMPLES=ON -B build && cmake --build build && ctest --test-dir build
Things to know
- The README recommends migrating to the gtl project, which requires C++20, and future feature work moves there.
- Flat hash maps move values in memory, so pointers and iterators into them can be invalidated on mutation.
- It is a C++11 header-only library with no packaged install; you must copy the directory manually.
Topics
FAQ
- What is parallel-hashmap?
- A header-only C++ library of fast, memory-friendly hash maps, sets, and B-tree containers that can replace the std unordered and ordered containers. Parallel Hashmap (phmap) is a C++ library of hash map and set implementations, plus B-tree based ordered containers that serve as alternatives to std::map and std::set. It is header-only: you copy the parallel_hashmap directory into a project and include it, with no build step. The hash tables are drop-in replacements for std::unordered_map and std::unordered_set, and the B-trees for std::map and std::set.
- Is parallel-hashmap free to use? What license does it have?
- parallel-hashmap is open source under the Apache-2.0 license. Check the license terms before using it in commercial products.
- Is parallel-hashmap still maintained?
- Updated within 6 months. The last commit to parallel-hashmap was on Sep 10, 2026.
- What can I use parallel-hashmap for?
- Replacing std::unordered_map in performance-sensitive C++ code. Storing very large numbers of entries where lower memory use matters. Building multithreaded services that share a hash table across threads with internal locking. Persisting large lookup tables quickly by dumping them to disk as a binary array.
- How do I install parallel-hashmap?
- Copy the parallel_hashmap directory into your project and add it to the include path Build and run the tests and examples with CMake: cmake -DPHMAP_BUILD_TESTS=ON -DPHMAP_BUILD_EXAMPLES=ON -B build && cmake --build build && ctest --test-dir build
- Where can I get parallel-hashmap?
- The source code and installation instructions are on GitHub: https://github.com/greg7mdp/parallel-hashmap
Summary generated by AI from the project's README. GitHub stats refresh daily.
Related projects
A C++11 single-header library for building HTTP/HTTPS servers and clients with blocking socket I/O.
A fast, Flask-style C++ microframework for building HTTP and WebSocket web services, header-only and easy to use.
Header-only C++ library for fast, exact parsing of float, double and integer values from strings, a drop-in style from_chars implementation.
A SIMD- and SWAR-accelerated string library for C, C++, Python, Rust, JavaScript, Go and more, covering search, hashing, sorting and edit distances.
A header-only C++11 library that lets C++ code parse, build, manipulate and serialize JSON with STL-like syntax.