Doublets
LinksPlatform's Rust implementation of Doublets (associative storage links).
Rust port of Data.Doublets library.
Overview
Doublets is an associative data structure that represents a link store where each link consists of:
- Index - unique identifier of the link
- Source - the link's source (can reference itself or another link)
- Target - the link's target (can reference itself or another link)
This simple yet powerful structure can represent any data model, from traditional key-value pairs to complex graph structures. Doublets provide a unified approach to data storage with constant-time lookup operations using size-balanced trees.
Key Features
- File-mapped storage - data persists directly to disk using memory-mapped files
- Generic link types - supports any unsigned integer type (
u8,u16,u32,u64,usize) - Two storage modes:
unit::Store- combined data and index storage in a single memory regionsplit::Store- separated data and index storage for optimized memory layouts
- Thread-safe -
SendandSyncimplementations for concurrent access - Query system - flexible pattern matching using
anyconstants - FFI bindings - C-compatible foreign function interface for cross-language integration
Installation
Add to your Cargo.toml:
[]
= "0.1.0-pre"
Note: This crate requires nightly Rust due to usage of experimental features.
Example
Basic CRUD operations with doublets:
use ;
use Flow;
Using In-Memory Storage
For testing or temporary data, you can use heap-allocated memory instead of file storage:
use ;
Using Split Storage
Split storage separates data and index trees for potentially better cache utilization:
use ;
use Global;
API Overview
Core Traits
| Trait | Description |
|---|---|
Links<T> |
Low-level CRUD operations with handlers |
Doublets<T> |
High-level operations with ergonomic API |
DoubletsExt<T> |
Iterator extensions and parallel processing |
Main Types
| Type | Description |
|---|---|
Link<T> |
A triplet of (index, source, target) |
Doublet<T> |
A pair of (source, target) without index |
unit::Store |
Combined memory layout storage |
split::Store |
Separated memory layout storage |
Error<T> |
Error type for link operations |
Key Operations
// Create operations
store.create?; // Create empty link
store.create_point?; // Create self-referencing link
store.create_link?; // Create link with source and target
// Read operations
store.count; // Count all links
store.count_by; // Count by pattern
store.get_link; // Get link by index
store.search; // Find link by source and target
store.iter; // Iterate all links
store.each_iter; // Iterate by pattern
// Update operations
store.update?; // Update link
// Delete operations
store.delete?; // Delete link
store.delete_all?; // Delete all links
Architecture
doublets-rs/
├── doublets/ # Core library
│ ├── src/
│ │ ├── data/ # Core data structures (Link, Doublet, traits)
│ │ └── mem/ # Memory management and storage
│ │ ├── unit/ # Combined storage implementation
│ │ └── split/ # Split storage implementation
│ └── benches/ # Performance benchmarks
├── doublets-ffi/ # C FFI bindings
├── dev-deps/ # Platform dependencies
│ ├── data-rs/ # Data primitives (LinkType, Flow, etc.)
│ ├── mem-rs/ # Memory abstractions (RawMem, FileMapped)
│ └── trees-rs/ # Tree structures (size-balanced trees)
└── integration/ # Integration tests
Features
| Feature | Description |
|---|---|
platform (default) |
Core platform types and traits |
mem |
Memory management utilities |
num |
Numeric utilities |
data |
Re-exports from platform-data |
rayon |
Parallel iteration support |
small-search |
Stack-allocated buffers for small queries |
full |
All features enabled |
Performance
The library is optimized for high-throughput operations:
- Size-balanced trees for O(log n) search, insert, and delete operations
- Memory-mapped files for efficient disk I/O
- Optional parallel iteration with rayon feature
- Benchmarks show creation of 1 million points in ~1 second on modern hardware
Run benchmarks:
Related Projects
- Data.Doublets - C# implementation
- Comparisons.SQLiteVSDoublets - Performance comparison with SQLite
Documentation
- API Documentation (when published)
- LinksPlatform Overview
Dependencies
- platform-data - Core data types
- platform-mem - Memory abstractions
- platform-trees - Tree implementations
Support
- Ask questions at stackoverflow.com/tags/links-platform (use tag
links-platform) - Join our Discord server for real-time support
- Open issues on GitHub
License
This project is released into the public domain under the Unlicense.