| Crates.io | simd-intervaltree |
| lib.rs | simd-intervaltree |
| version | 0.1.0 |
| created_at | 2026-01-05 05:56:16.909953+00 |
| updated_at | 2026-01-05 05:56:16.909953+00 |
| description | A SIMD-accelerated interval tree with zero-allocation queries |
| homepage | |
| repository | https://github.com/bcoverston/simd-intervaltree |
| max_upload_size | |
| id | 2023200 |
| size | 92,776 |
A SIMD-accelerated interval tree with zero-allocation queries.
IntervalSet with stable IDs for insert/removeno_std compatible: Only requires allocuse simd_intervaltree::IntervalTree;
use std::ops::ControlFlow;
let tree = IntervalTree::builder()
.insert(0..10, "first")
.insert(5..15, "second")
.insert(20..30, "third")
.build();
// Iterator-based query (zero allocation)
for entry in tree.query(3..12) {
println!("{:?} => {}", entry.interval, entry.value);
}
// Callback with early termination
tree.query_with(3..12, |interval, value| {
println!("{interval:?} => {value}");
ControlFlow::Continue(())
});
// SIMD-accelerated query for i64 intervals
tree.query_simd(3..12, |interval, value| {
ControlFlow::Continue(())
});
Useful for tracking resources like SSTables in an LSM tree:
use simd_intervaltree::IntervalSet;
let mut sstables = IntervalSet::new();
// Insert returns stable ID
let id1 = sstables.insert(100..500, "sst_001.db");
let id2 = sstables.insert(300..700, "sst_002.db");
// Query returns (ID, Interval, &Value)
for (id, range, filename) in sstables.query(250..350) {
println!("{id:?}: {range:?} => {filename}");
}
// Remove by ID after compaction
sstables.remove(id1);
// Lookup by ID
if let Some(filename) = sstables.get(id2) {
println!("Found: {filename}");
}
Benchmarks vs intervaltree crate (Apple M-series):
| Size | simd-intervaltree | intervaltree | Speedup |
|---|---|---|---|
| 1K | 164ns | 216ns | 24% |
| 10K | 470ns | 1052ns | 55% |
Data is laid out contiguously per node for cache efficiency:
ends_desc array enables SIMD for descending scans| 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.
| Flag | Default | Description |
|---|---|---|
std |
yes | Standard library support |
jemalloc |
yes | Use jemalloc allocator |
Disable defaults for no_std:
[dependencies]
simd-intervaltree = { version = "0.1", default-features = false }
MIT