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