| 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 |
// https://github.com/unicode-org/icu4x/blob/main/documents/process/boilerplate.md#library-annotations |
| 6 |
#![cfg_attr(not(any(test, doc)), no_std)] |
| 7 |
#![cfg_attr( |
| 8 |
not(test), |
| 9 |
deny( |
| 10 |
clippy::indexing_slicing, |
| 11 |
clippy::unwrap_used, |
| 12 |
clippy::expect_used, |
| 13 |
clippy::panic, |
| 14 |
) |
| 15 |
)] |
| 16 |
#![warn(missing_docs)] |
| 17 |
|
| 18 |
//! A data structure offering zero-copy storage and retrieval of byte strings, with a focus |
| 19 |
//! on the efficient storage of ASCII strings. Strings are mapped to `usize` values. |
| 20 |
//! |
| 21 |
//! [`ZeroTrie`] does not support mutation because doing so would require recomputing the entire |
| 22 |
//! data structure. Instead, it supports conversion to and from [`LiteMap`] and [`BTreeMap`]. |
| 23 |
//! |
| 24 |
//! There are multiple variants of [`ZeroTrie`] optimized for different use cases. |
| 25 |
//! |
| 26 |
//! # Safe Rust |
| 27 |
//! |
| 28 |
//! All runtime lookup code in this crate is 100% safe Rust. |
| 29 |
//! |
| 30 |
//! A small amount of unsafe Rust is used in these situations: |
| 31 |
//! |
| 32 |
//! - Constructing unsized transparent newtypes (i.e. <https://github.com/rust-lang/rust/issues/18806>), |
| 33 |
//! which is reachable from builder code and when creating a `&TypedZeroTrie<[u8]>` DST. |
| 34 |
//! - Implementing unsafe traits when the `zerovec` feature is enabled |
| 35 |
//! |
| 36 |
//! # Examples |
| 37 |
//! |
| 38 |
//! ``` |
| 39 |
//! use zerotrie::ZeroTrie; |
| 40 |
//! |
| 41 |
//! let data: &[(&str, usize)] = &[("abc", 11), ("xyz", 22), ("axyb", 33)]; |
| 42 |
//! |
| 43 |
//! let trie: ZeroTrie<Vec<u8>> = data.iter().copied().collect(); |
| 44 |
//! |
| 45 |
//! assert_eq!(trie.get("axyb"), Some(33)); |
| 46 |
//! assert_eq!(trie.byte_len(), 18); |
| 47 |
//! ``` |
| 48 |
//! |
| 49 |
//! # Internal Structure |
| 50 |
//! |
| 51 |
//! To read about the internal structure of [`ZeroTrie`], build the docs with private modules: |
| 52 |
//! |
| 53 |
//! ```bash |
| 54 |
//! cargo doc --document-private-items --all-features --no-deps --open |
| 55 |
//! ``` |
| 56 |
//! |
| 57 |
//! [`LiteMap`]: litemap::LiteMap |
| 58 |
//! [`BTreeMap`]: alloc::collections::BTreeMap |
| 59 |
|
| 60 |
// To back up the claim in the docs: |
| 61 |
#![deny(unsafe_code)] |
| 62 |
|
| 63 |
#[cfg(feature = "alloc")] |
| 64 |
extern crate alloc; |
| 65 |
|
| 66 |
mod builder; |
| 67 |
mod byte_phf; |
| 68 |
pub mod cursor; |
| 69 |
#[cfg(feature = "dense")] |
| 70 |
pub mod dense; |
| 71 |
mod error; |
| 72 |
#[macro_use] |
| 73 |
mod helpers; |
| 74 |
mod options; |
| 75 |
mod reader; |
| 76 |
#[cfg(feature = "serde")] |
| 77 |
mod serde; |
| 78 |
mod varint; |
| 79 |
mod zerotrie; |
| 80 |
|
| 81 |
pub use crate::zerotrie::ZeroAsciiIgnoreCaseTrie; |
| 82 |
pub use crate::zerotrie::ZeroTrie; |
| 83 |
pub use crate::zerotrie::ZeroTrieExtendedCapacity; |
| 84 |
pub use crate::zerotrie::ZeroTriePerfectHash; |
| 85 |
pub use crate::zerotrie::ZeroTrieSimpleAscii; |
| 86 |
pub use error::ZeroTrieBuildError; |
| 87 |
|
| 88 |
#[cfg(feature = "alloc")] |
| 89 |
pub use crate::zerotrie::ZeroTrieStringIterator; |
| 90 |
#[cfg(feature = "alloc")] |
| 91 |
pub use reader::ZeroTrieIterator; |
| 92 |
|
| 93 |
#[doc(hidden)] |
| 94 |
pub mod _internal { |
| 95 |
pub use crate::byte_phf::f1; |
| 96 |
pub use crate::byte_phf::f2; |
| 97 |
pub use crate::byte_phf::PerfectByteHashMap; |
| 98 |
} |