Skip to main content

Module char16trie

Module char16trie 

Source
Expand description

This module provides a data structure for a space-efficient and time-efficient lookup of sequences of 16-bit units (commonly but not necessarily UTF-16 code units) which map to integer values.

It is an implementation of the existing ICU4C UCharsTrie / ICU4J CharsTrie API.

§Architecture

ICU4X Char16Trie is designed to provide a read-only view of UCharsTrie data that is exported from ICU4C.

§Examples

§Querying a Char16Trie

use icu::collections::char16trie::Char16Trie;
use zerovec::ZeroVec;

// A Char16Trie containing the ASCII characters mapping 'a' to 1 and 'ab'
// to 100.
let trie_data = [48, 97, 176, 98, 32868];
let trie = Char16Trie::new(ZeroVec::from_slice_or_alloc(&trie_data));

let mut cursor = trie.cursor();
cursor.step('a');
assert_eq!(cursor.value(), Some(1));
assert!(!cursor.is_empty());
cursor.step('b');
assert_eq!(cursor.value(), Some(100));
assert!(cursor.is_empty());
cursor.step('c');
assert_eq!(cursor.value(), None);
assert!(cursor.is_empty());

Structs§

Char16Trie
This struct represents a de-serialized Char16Trie that was exported from ICU binary data.
Char16TrieCursor
A cursor into a Char16Trie, useful for stepwise lookup.
Char16TrieIteratorDeprecated
This struct represents an iterator over a Char16Trie.

Enums§

TrieResultDeprecated
An enum representing the return value from a lookup in Char16Trie.