1 个不稳定版本
0.1.3 | 2024年7月3日 |
---|
#1701 在 数据结构 中
每月 下载 68 次
6KB
65 行
Rust前缀树实现
前缀树(发音为"try")或前缀树是一种专门化的树形数据结构,用于高效存储和检索字符串。它提供基于前缀的快速搜索操作,特别适用于自动完成、拼写检查和IP路由等应用。
特性
- 高效前缀搜索:快速在字符串集中搜索单词或前缀。
- 内存优化:共享单词间的公共前缀,减少存储开销。
- 可定制:易于适应各种用例。
用法
- Cargo.toml
[dependencies]
simple_trie = "0.1.0"
- main.rs
use simple_trie::Trie;
let mut my_trie = Trie::new();
my_trie.insert("hello");
my_trie.insert("world");
my_trie.insert("help");
// Search for a full word
let exists = my_trie.search_full_world("hello"); // true
// Search for a prefix
let prefix_exists = my_trie.search_prefix("hel"); // true
测试
使用
cargo test
许可证
本项目采用MIT许可证。