Expand description
§MassTree
A high-performance concurrent ordered map for Rust. Stores keys as &[u8] and
supports variable-length keys by building a trie of B+trees.
§Features
- Ordered map for byte keys (lexicographic ordering)
- Lock-free reads with version validation
- Concurrent inserts and deletes with fine-grained leaf locking
- Range scans with
scanandscan_prefix - Memory reclamation via epoch-based deferred cleanup
- Lazy leaf coalescing for deleted entries
- High-performance inline variant
MassTree15Inline(the defaultMassTreealias)
§Quick Start
use masstree::{MassTree, RangeBound};
let tree: MassTree<u64> = MassTree::new();
let guard = tree.guard();
// Insert
tree.insert_with_guard(b"hello", 123, &guard);
// Point lookup (lock-free, returns copy for inline storage)
assert_eq!(tree.get_with_guard(b"hello", &guard), Some(123));
// Remove
tree.remove_with_guard(b"hello", &guard).unwrap();
// Range scan
tree.scan(RangeBound::Included(b"a"), RangeBound::Excluded(b"z"), |_key, _value| {
true // continue scanning
}, &guard);§Thread Safety
MassTree<V> is Send + Sync when V: Send + Sync. Concurrent access
requires using the guard-based API. The guard ties operations to an epoch
for safe memory reclamation.
use masstree::MassTree;
let tree: MassTree<u64> = MassTree::new();
let guard = tree.guard();
// Concurrent get (lock-free)
let value = tree.get_with_guard(b"key", &guard);
// Concurrent insert (fine-grained locking)
let old = tree.insert_with_guard(b"key", 42, &guard);§Key Constraints
- Keys must be 0-256 bytes. Longer keys will panic.
- Keys are byte slices (
&[u8]), not generic types.
Modules§
- batch
- Batch insert utilities and helpers.
Structs§
- Atomic
Permuter - Atomic wrapper for
Permuter<WIDTH>where WIDTH <= 15. - Batch
Entry - A single entry in a batch insert operation.
- Batch
Insert Result - Result of a batch insert operation.
- Batched
Retire - Value retirement utilities.
- BoxPolicy
- Box-based value storage with lazy sidecar suffix.
- Internode
Node - An internal routing node in the
MassTree. - Key
- A key for
crate::MassTreeoperations. - Keys
Iter - Iterator adapter that yields only keys.
- Leaf
Node15 - B-link leaf node with 15 slots, parameterized over
LeafPolicy. - Mass
Tree Generic - A high-performance generic trie of B+trees.
- Node
Version - A versioned lock for tree nodes.
- Occupied
Entry - A view into an occupied entry in a tree.
- Permuter
- A permutation of slot indices for a leaf node.
- Range
Iter - Iterator over a key range in a
crate::MassTree. - Scan
Entry - Contains an owned copy of the key and the value output.
- Seize
Allocator - Unified seize-based allocator for all leaf policies.
- Suffix
Bag - Contiguous storage for key suffixes.
- Vacant
Entry - A view into a vacant entry in a tree.
- Value
Ptr - A lightweight,
Copypointer to a heap-allocated value. - Values
Iter - Iterator adapter that yields only values.
Enums§
- Entry
- A view into a single entry in a tree, which may either be vacant or occupied.
- Insert
Error - Errors that can occur during insert operations.
- Range
Bound - Range bound for scan operations.
- Remove
Error - Errors that can occur during removal.
- Value
Ref - Cow-like value handle: either a borrowed reference or an owned copy.
Constants§
- IKEY_
SIZE - Size of an ikey in bytes.
- MAX_
KEY_ LENGTH - Maximum supported key length in bytes (32 layers * 8 bytes).
- MAX_
WIDTH - Maximum allowed WIDTH for u64 permuter encoding.
Traits§
- Inline
Bits - Trait for values that can be stored inline as 64 bits.
- Leaf
Policy - Bundles value storage, suffix storage, and type conversion for a leaf node.
- Permutation
Provider - Trait for types that can provide permutation information.
- RefLeaf
Policy - Marker trait for policies that support zero-copy reference returns.
- Tree
Allocator - Trait for allocating and deallocating tree nodes generically.
- Tree
Internode - Trait for internode types used in a
MassTree. - Tree
Leaf Node - Trait for abstracting over leaf node WIDTH variants.
- Tree
Permutation - Trait for permutation types used in leaf nodes.
Functions§
- init_
tracing - No-op when the
tracingfeature is disabled.
Type Aliases§
- Atomic
Permuter15 - Type alias for the standard 15-slot atomic permuter.
- Mass
Tree - High-performance inline storage variant for
Copytypes (default tree type). - Mass
Tree15 - Box-based storage for non-Copy types (String, Vec
, etc.). - Mass
Tree15 Inline - True-inline storage for Copy types (u64, i32, *const T, etc.).
- Permuter15
- Type alias for standard 15-slot permuter.