Marisa FFI Rust Bindings
This project provides Rust FFI bindings for the libmarisa library, a space-efficient trie data structure implementation.
Features
- Lookup: Check whether a string exists in the dictionary
- Reverse lookup: Restore a key from its ID
- Common prefix search: Find keys from prefixes of a given string
- Predictive search: Find keys starting with a given string
- Memory efficient: Significantly more compact than other trie implementations
- Cross-platform: Works on Linux, macOS, and Windows
Installation
Prerequisites
- Rust 1.70+
- CMake 3.22+
- C++ compiler with C++20 support
From Crates.io
Add this to your Cargo.toml:
[]
= "0.3.1"
From Source
- Clone the repository:
- Build the FFI library:
Using as a Dependency
Add this to your Cargo.toml:
[]
= "0.3.1"
Quick Start
use ;
API Reference
Trie
The main trie structure for efficient string storage and lookup.
Keyset
A collection of keys used to build tries.
Agent
An agent for performing search operations and retrieving results.
Examples
Basic Usage
See examples/basic_usage.rs for a comprehensive example demonstrating all features.
Benchmark
See examples/benchmark.rs for performance testing and comparison.
Performance
Marisa trie is significantly more space-efficient than other implementations:
| Implementation | Size (bytes) | Remarks |
|---|---|---|
| darts-clone | 376,613,888 | Compacted double-array trie |
| tx-trie | 127,727,058 | LOUDS-based trie |
| marisa-trie | 50,753,560 | MARISA trie |
Source: English Wikipedia page titles (9,805,576 keys)
Error Handling
All operations return Result types with detailed error information:
License
This project is licensed under the same terms as libmarisa:
- BSD-2-Clause OR LGPL-2.1-or-later
Contributing
Contributions are welcome! Please feel free to submit issues and pull requests.
Acknowledgments
- s-yata for the original libmarisa implementation
- The Rust community for excellent FFI tooling and documentation