simd-intervaltree
A SIMD-accelerated interval tree with zero-allocation queries.
Features
- SIMD acceleration: AVX-512, AVX2, and NEON for fast sorted-array scans
- Zero-allocation queries: Iterator-based API with stack-based traversal
- Mutable collections:
IntervalSetwith stable IDs for insert/remove no_stdcompatible: Only requiresalloc- jemalloc: Optional (default on) for allocation performance
Usage
Immutable Tree
use IntervalTree;
use ControlFlow;
let tree = builder
.insert
.insert
.insert
.build;
// Iterator-based query (zero allocation)
for entry in tree.query
// Callback with early termination
tree.query_with;
// SIMD-accelerated query for i64 intervals
tree.query_simd;
Mutable Set with Stable IDs
Useful for tracking resources like SSTables in an LSM tree:
use IntervalSet;
let mut sstables = new;
// Insert returns stable ID
let id1 = sstables.insert;
let id2 = sstables.insert;
// Query returns (ID, Interval, &Value)
for in sstables.query
// Remove by ID after compaction
sstables.remove;
// Lookup by ID
if let Some = sstables.get
Performance
Benchmarks vs intervaltree crate (Apple M-series):
| Size | simd-intervaltree | intervaltree | Speedup |
|---|---|---|---|
| 1K | 164ns | 216ns | 24% |
| 10K | 470ns | 1052ns | 55% |
Architecture
Data Layout
Data is laid out contiguously per node for cache efficiency:
- Each node's intervals are stored contiguously, sorted by start
- SIMD scans find early-termination cutoffs in O(n/lanes) time
- Separate
ends_descarray enables SIMD for descending scans
SIMD Support
| Architecture | Instruction Set | Elements/Op |
|---|---|---|
| x86_64 | AVX-512 | 8 × i64 |
| x86_64 | AVX2 | 4 × i64 |
| aarch64 | NEON | 2 × i64 |
| fallback | scalar | 1 × i64 |
Runtime detection selects the best available.
Feature Flags
| Flag | Default | Description |
|---|---|---|
std |
yes | Standard library support |
jemalloc |
yes | Use jemalloc allocator |
Disable defaults for no_std:
[]
= { = "0.1", = false }
License
MIT