concurrent_avl_tree 0.1.0

Lock-free readable AVL tree with epoch-based reclamation and background batch rebalancing.
Documentation
  • Coverage
  • 100%
    45 out of 45 items documented2 out of 20 items with examples
  • Size
  • Source code size: 61.44 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 828.57 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 15s Average build duration of successful builds.
  • all releases: 15s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • da578

Concurrent AVL Tree

Crates.io Documentation License Rust Version CI

Lock-free readable AVL tree with epoch-based memory reclamation and background batch rebalancing. Designed for high-concurrency, high-read workloads with deterministic traversal latency.

Table of Contents

Features

  • Lock-Free Reads
    Readers traverse without acquiring mutexes or spinlocks.
  • Epoch-Based Reclamation
    Zero use-after-free guarantees via deferred memory disposal.
  • Batched Rebuilds
    Writes are collected, sorted, and applied by a background thread that atomically swaps the root pointer.
  • Generational Arena
    Double-buffered, cache-line aligned allocator eliminates dynamic allocation during rebuilds.
  • Production-Ready Documentation
    Strict rustdoc compliance, exhaustive examples, and CI-enforced lints.

Installation

Add to Cargo.toml:

[dependencies]

concurrent_avl_tree = "0.1.0"

Or via CLI:

cargo add concurrent_avl_tree

Requires Rust 1.91.1 or newer.

Quick Start

use concurrent_avl_tree::concurrent_avl_tree::ConcurrentAVLTree;

fn main() {
    let tree = ConcurrentAVLTree::new();
    tree.insert_key_value(42, "hello".to_string());
    tree.insert_key_value(10, "world".to_string());

    // Allow background rebuild to complete
    std::thread::sleep(std::time::Duration::from_millis(50));

    let value = tree.get_value(42);
    assert_eq!(value, Some("hello".to_string()));
}

Architecture Overview

┌─────────────┐       ┌──────────────┐        ┌───────────────────┐
│   Writers   │──────▶│ Batch Queue  │──────▶│ Background Thread │
└─────────────┘       └──────────────┘        └─────────┬─────────┘
                                                        │
                                                        ▼
┌─────────────┐       ┌──────────────┐        ┌───────────────────┐
│   Readers   │◀──────│ Root Pointer │◀──────│    Arena Swap     │
└─────────────┘       └──────────────┘        └───────────────────┘
  1. Append Phase
    Writers push BatchEntry to a mutex-protected collector.
  2. Rebuild Phase
    Background thread extracts, sorts, and constructs a new AVL tree in the inactive arena buffer.
  3. Swap Phase
    Root AtomicPtr is exchanged. Previous root is queued for epoch-based disposal.
  4. Reclaim Phase
    EBR tracks active reader epochs. After a two-epoch grace period, queued callbacks free memory safely.

Benchmarking & Testing

Run unit & doc tests:

cargo test

cargo test --doc

Execute benchmarks (headless safe):

cargo bench -- --noplot

Generate coverage report:

cargo install cargo-llvm-cov

cargo llvm-cov --all-features --open

Contributing & Changelog

License

SPDX-License-Identifier: MIT
© 2026 Dzulkifli Anwar
See LICENSE for full terms.