OxidArt
A blazingly fast Adaptive Radix Tree (ART) implementation in Rust with path compression.
Features
- O(k) complexity - All operations run in O(k) time where k is the key length, not the number of entries
- Path compression - Minimizes memory usage by collapsing single-child paths
- Prefix queries -
getnanddelnfor efficient prefix-based operations - TTL support - Built-in time-to-live with lazy expiration
- Async runtime integration - First-class support for monoio and tokio
- Zero-copy values - Uses
bytes::Bytesfor efficient value handling - Memory efficient - Adaptive node sizing with
SmallVecandSlaballocation
Installation
[]
= "0.2"
= "1"
Feature Flags
| Feature | Description |
|---|---|
ttl (default) |
Enables time-to-live support for entries |
monoio |
Async integration for monoio (single-thread, io_uring) |
tokio |
Async integration for tokio (multi-thread) |
Note:
monoioandtokiofeatures are mutually exclusive.
Quick Start
use OxidArt;
use Bytes;
let mut tree = new;
// Insert key-value pairs
tree.set;
tree.set;
// Retrieve a value
assert_eq!;
// Get all entries with a prefix
let entries = tree.getn;
assert_eq!;
// Delete a key
tree.del;
// Delete all keys with a prefix
tree.deln;
TTL Support
With the ttl feature (enabled by default), you can set expiration times on entries:
use OxidArt;
use Bytes;
use Duration;
let mut tree = new;
// Update internal clock (call periodically from your event loop)
tree.set_now;
// Insert with TTL - expires after 60 seconds
tree.set_ttl;
// Insert without TTL - never expires
tree.set;
// Expired entries are automatically filtered on get/getn
Async Runtime Integration
For TTL support, we recommend using the shared_with_ticker constructor which creates a shared tree with automatic timestamp updates.
With monoio (single-threaded)
[]
= { = "0.1", = ["monoio"] }
use OxidArt;
use Bytes;
use Duration;
async
With tokio (multi-threaded)
[]
= { = "0.1", = ["tokio"] }
use OxidArt;
use Bytes;
use Duration;
async
API
| Method | Description |
|---|---|
new() |
Create a new empty tree |
shared_with_ticker(interval) |
Create shared tree with auto-ticker (recommended for TTL) |
get(key) |
Get value by exact key |
set(key, value) |
Insert or update a key-value pair (no expiration) |
set_ttl(key, duration, value) |
Insert with TTL (requires ttl feature) |
del(key) |
Delete by exact key, returns the old value |
getn(prefix) |
Get all entries matching a prefix |
deln(prefix) |
Delete all entries matching a prefix |
set_now(timestamp) |
Update internal clock for TTL checks |
tick() |
Update clock to current time (requires monoio or tokio) |
Why ART?
Adaptive Radix Trees combine the efficiency of radix trees with adaptive node sizes:
- Unlike hash maps, ART maintains key ordering and supports efficient range/prefix queries
- Unlike B-trees, ART has O(k) lookup independent of the number of entries
- Path compression eliminates redundant nodes, reducing memory overhead
License
Licensed under the Mozilla Public License 2.0.