Skip to content

l1h3r/ptab

Repository files navigation

ptab

github crates.io docs.rs build status

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.

Features

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

Usage

Add the following to your Cargo.toml:

[dependencies]
ptab = "0.1"

Example

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");

Design

See IMPLEMENTATION.md for detailed design notes.


License

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.

About

Lock-free concurrent table optimized for read-heavy workloads.

Topics

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Contributors