| 1 |
// This file is part of ICU4X. For terms of use, please see the file |
| 2 |
// called LICENSE at the top level of the ICU4X source tree |
| 3 |
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ). |
| 4 |
|
| 5 |
//! This module provides a data structure for a space-efficient and time-efficient lookup of |
| 6 |
//! sequences of 16-bit units (commonly but not necessarily UTF-16 code units) |
| 7 |
//! which map to integer values. |
| 8 |
//! |
| 9 |
//! It is an implementation of the existing [ICU4C UCharsTrie](https://unicode-org.github.io/icu-docs/apidoc/released/icu4c/classicu_1_1UCharsTrie.html) |
| 10 |
//! / [ICU4J CharsTrie](https://unicode-org.github.io/icu-docs/apidoc/released/icu4j/com/ibm/icu/util/CharsTrie.html) API. |
| 11 |
//! |
| 12 |
//! ## Architecture |
| 13 |
//! |
| 14 |
//! ICU4X [`Char16Trie`] is designed to provide a read-only view of `UCharsTrie` data that is exported from ICU4C. |
| 15 |
//! |
| 16 |
//! ## Examples |
| 17 |
//! |
| 18 |
//! ### Querying a `Char16Trie` |
| 19 |
//! |
| 20 |
//! ```rust |
| 21 |
//! use icu::collections::char16trie::{Char16Trie, TrieResult}; |
| 22 |
//! use zerovec::ZeroVec; |
| 23 |
//! |
| 24 |
//! // A Char16Trie containing the ASCII characters mapping 'a' to 1 and 'ab' |
| 25 |
//! // to 100. |
| 26 |
//! let trie_data = [48, 97, 176, 98, 32868]; |
| 27 |
//! let trie = Char16Trie::new(ZeroVec::from_slice_or_alloc(&trie_data)); |
| 28 |
//! |
| 29 |
//! let mut iter = trie.iter(); |
| 30 |
//! let res = iter.next('a'); |
| 31 |
//! assert_eq!(res, TrieResult::Intermediate(1)); |
| 32 |
//! let res = iter.next('b'); |
| 33 |
//! assert_eq!(res, TrieResult::FinalValue(100)); |
| 34 |
//! let res = iter.next('c'); |
| 35 |
//! assert_eq!(res, TrieResult::NoMatch); |
| 36 |
//! ``` |
| 37 |
//! |
| 38 |
//! [`ICU4X`]: ../icu/index.html |
| 39 |
|
| 40 |
mod trie; |
| 41 |
|
| 42 |
pub use trie::Char16Trie; |
| 43 |
pub use trie::Char16TrieIterator; |
| 44 |
pub use trie::TrieResult; |