mappy-core
Core maplet data structure implementation - Space-efficient approximate key-value mappings with one-sided error guarantees.
Overview
Maplets provide the same space benefits as filters while natively supporting key-value associations. Unlike traditional filters that only support set membership queries, maplets allow you to associate values with keys and retrieve them during queries with configurable merge operators.
Based on the research paper: "Time To Replace Your Filter: How Maplets Simplify System Design" by Bender et al. (2025).
Key Features
- Space Efficiency: Achieves
O(log 1/ε + v)
bits per item where ε is the false-positive rate and v is the value size - Value Support: Native key-value associations with configurable merge operators
- One-Sided Errors: Guarantees
M[k] ≺ m[k]
for application-specific ordering relations - Deletion Support: Full support for removing key-value pairs
- Merging: Combine maplets using associative/commutative operators
- Resizing: Dynamic growth with efficient rehashing
- Cache Locality: Optimized memory layout for performance
- Concurrency: Thread-safe operations with lock-free reads
Quick Start
Add to your Cargo.toml
:
[]
= "0.1.0"
Basic Usage
use ;
// Create a maplet for counting with 1% false-positive rate
let mut maplet = new;
// Insert key-value pairs
maplet.insert.unwrap;
maplet.insert.unwrap;
// Query values (may return approximate results)
let count1 = maplet.query; // Some(5) or Some(5 + other_values)
let count2 = maplet.query; // Some(3) or Some(3 + other_values)
// Check if key exists
let exists = maplet.contains; // true
// Get statistics
let stats = maplet.stats;
println!;
println!;
Use Cases
1. K-mer Counting (Computational Biology)
use ;
let mut kmer_counter = new;
// Count k-mers in DNA sequences with high accuracy
2. Network Routing Tables
use ;
use HashSet;
let mut routing_table = new;
// Map network prefixes to sets of next-hop routers
3. LSM Storage Engine Index
use ;
let mut sstable_index = new;
// Map keys to SSTable identifiers for efficient lookups
Available Merge Operators
CounterOperator
: Adds values together (useful for counting)MaxOperator
: Takes the maximum valueMinOperator
: Takes the minimum valueSetOperator
: Union of setsCustomOperator
: Define your own merge function
Performance Characteristics
- Query Throughput: Within 2x of HashMap for same memory usage
- Memory Efficiency: 20-50% reduction vs HashMap for typical workloads
- Error Control: False-positive rate within 1.5x of configured ε
- Cache Performance: Optimized for sequential access patterns
Error Guarantees
Maplets provide the strong maplet property:
m[k] = M[k] ⊕ (⊕ᵢ₌₁ˡ M[kᵢ])
Where Pr[ℓ ≥ L] ≤ ε^L
, meaning even when wrong, the result is close to correct.
Storage Backends
- Memory: In-memory storage for fast access
- Disk: Persistent storage with configurable durability
- AOF: Append-only file for crash recovery
- Hybrid: Combination of memory and disk storage
Examples
See the examples/
directory for comprehensive usage examples:
counter.rs
- Basic counting examplerouting.rs
- Network routing table simulationcaching_service.rs
- Distributed caching systemperformance_comparison.rs
- Benchmarking against standard HashMap
Benchmarks
Run benchmarks to see performance characteristics:
Documentation
- API Documentation - Complete API reference
- Technical Guide - Comprehensive technical documentation
- Research Foundation - Original research papers
License
MIT License - see LICENSE file for details.
Contributing
Contributions are welcome! Please see the main repository for contribution guidelines.
References
Based on the research paper:
Bender, M. A., Conway, A., Farach-Colton, M., Johnson, R., & Pandey, P. (2025). Time To Replace Your Filter: How Maplets Simplify System Design. arXiv preprint arXiv:2510.05518.