A lock-free concurrent table for Rust.
ptab provides a fixed-capacity table optimized for read-heavy concurrent workloads. Inspired by Erlang's BEAM process table, lookups scale linearly with CPU count by avoiding all shared memory writes.
- Zero-contention reads - Atomic loads for lock-free lookups.
- Cache-line distribution - Prevents false sharing with no memory overhead.
- Generational indices - Slot reuse mitigates ABA problems.
Add the following to your Cargo.toml:
[dependencies]
ptab = "0.1"use ptab::PTab;
use std::sync::Arc;
let table = Arc::new(PTab::<&str>::new());
let handle = std::thread::spawn({
let table = Arc::clone(&table);
move || table.insert("world").unwrap()
});
let index_a = table.insert("hello").unwrap();
let index_b = handle.join().unwrap();
assert_eq!(table.read(index_a).unwrap(), "hello");
assert_eq!(table.read(index_b).unwrap(), "world");See IMPLEMENTATION.md for detailed design notes.
Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.