# trie-rs Memory efficient trie (prefix tree) and map library based on LOUDS. [Master API Docs](https://laysakura.github.io/trie-rs/trie_rs/) | [Released API Docs](https://docs.rs/crate/trie-rs) | [Benchmark Results](https://laysakura.github.io/trie-rs/criterion/report/) | [Changelog](https://github.com/laysakura/trie-rs/blob/master/CHANGELOG.md) [![GitHub Actions Status](https://github.com/laysakura/trie-rs/actions/workflows/ci.yml/badge.svg)](https://github.com/laysakura/trie-rs/actions) [![Crates.io Version](https://img.shields.io/crates/v/trie-rs.svg)](https://crates.io/crates/trie-rs) [![Crates.io Downloads](https://img.shields.io/crates/d/trie-rs.svg)](https://crates.io/crates/trie-rs) [![Minimum rustc version](https://img.shields.io/badge/rustc-1.56+-lightgray.svg)](https://github.com/laysakura/trie-rs#rust-version-supports) [![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/laysakura/trie-rs/blob/master/LICENSE-MIT) [![License: Apache 2.0](https://img.shields.io/badge/license-Apache_2.0-blue.svg)](https://github.com/laysakura/trie-rs/blob/master/LICENSE-APACHE) ## Quickstart To use trie-rs, add the following to your `Cargo.toml` file: ```toml [dependencies] trie-rs = "0.4.2" ``` ### Usage Overview ```rust use std::str; use trie_rs::TrieBuilder; let mut builder = TrieBuilder::new(); // Inferred `TrieBuilder` automatically builder.push("すし"); builder.push("すしや"); builder.push("すしだね"); builder.push("すしづめ"); builder.push("すしめし"); builder.push("すしをにぎる"); builder.push("すし"); // Word `push`ed twice is just ignored. builder.push("🍣"); let trie = builder.build(); // exact_match(): Find a word exactly match to query. assert_eq!(trie.exact_match("すし"), true); assert_eq!(trie.exact_match("🍣"), true); assert_eq!(trie.exact_match("🍜"), false); // predictive_search(): Find words which include `query` as their prefix. let results_in_u8s: Vec> = trie.predictive_search("すし").collect(); let results_in_str: Vec = trie.predictive_search("すし").collect(); assert_eq!( results_in_str, vec![ "すし", "すしだね", "すしづめ", "すしめし", "すしや", "すしをにぎる" ] // Sorted by `Vec`'s order ); // common_prefix_search(): Find words which is included in `query`'s prefix. let results_in_u8s: Vec> = trie.common_prefix_search("すしや").collect(); let results_in_str: Vec = trie.common_prefix_search("すしや").collect(); assert_eq!( results_in_str, vec![ "すし", "すしや", ] // Sorted by `Vec`'s order ); ``` ### Using with Various Data Types `TrieBuilder` is implemented using generic type like following: ```ignore impl TrieBuilder