[−][src]Crate darts
Double Array Trie in Rust
Installation
Add it to your Cargo.toml
:
[dependencies]
darts = "0.1"
Then you are good to go. If you are using Rust 2015 you have to extern crate darts
to your crate root as well.
Example
use std::fs::File; use darts::DoubleArrayTrie; fn main() { let mut f = File::open("./priv/dict.big.bincode").unwrap(); let da = DoubleArrayTrie::load(&mut f).unwrap(); let string = "中华人民共和国"; let prefixes = da.common_prefix_search(string).map(|matches| { matches .into_iter() .map(|(end_idx, v)| { &string[..end_idx] }) .collect() }).unwrap_or(vec![]); assert_eq!(vec!["中", "中华", "中华人民", "中华人民共和国"], prefixes); }
use std::fs::File; use darts::DoubleArrayTrie; fn main() { let mut f = File::open("./priv/dict.big.bincode").unwrap(); let da = DoubleArrayTrie::load(&mut f).unwrap(); assert!(da.exact_match_search("东湖高新技术开发区").is_some()); }
Enabling Additional Features
searcher
feature enables searcher for maximum forward matcherserialization
feature enables saving and loading serializedDoubleArrayTrie
data
[dependencies]
darts = { version = "0.1", features = ["searcher", "serialization"] }
Modules
searcher |
Structs
DoubleArrayTrie | A Double Array Trie. |
DoubleArrayTrieBuilder | Build a Double Arrary Trie from a series of strings. |
PrefixIter |
Enums
DartsError | The error type which is used in this crate. |
Type Definitions
Result | The result type which is used in this crate. |