1 unstable release

0.3.3 Aug 6, 2022

#65 in #cldr

Download history 21/week @ 2022-08-14 25/week @ 2022-08-21 4/week @ 2022-08-28 13/week @ 2022-09-04 8/week @ 2022-09-11 8/week @ 2022-09-18 30/week @ 2022-09-25 27/week @ 2022-10-02 20/week @ 2022-10-09 87/week @ 2022-10-16 14/week @ 2022-10-23 13/week @ 2022-10-30 15/week @ 2022-11-06 20/week @ 2022-11-13 20/week @ 2022-11-20 11/week @ 2022-11-27

66 downloads per month
Used in 2 crates (via icu_datagen)

Unicode-DFS-2016

520KB
6K SLoC

icu_codepointtrie_builder crates.io

icu_codepointtrie_builder is a utility crate of the ICU4X project.

This crate exposes functionality to build a [CodePointTrie] from values provided at runtime. Because it is normally expected for CodePointTrie data to be pre-compiled, this crate is not optimized for speed; it should be used during a build phase.

Under the hood, this crate uses the CodePointTrie builder code from ICU4C, UMutableCPTrie, shipped as a WebAssembly module and then JIT-compiled at runtime. For more context, see https://github.com/unicode-org/icu4x/issues/1837.

Examples

use icu_collections::codepointtrie::CodePointTrie;
use icu_collections::codepointtrie::TrieType;
use icu_codepointtrie_builder::CodePointTrieBuilder;
use icu_codepointtrie_builder::CodePointTrieBuilderData;

let default_value = 1;
let error_value = 2;
let values_by_code_point = &[3, 4, 5, 6];

let cpt: CodePointTrie<u8> = CodePointTrieBuilder {
    data: CodePointTrieBuilderData::ValuesByCodePoint(values_by_code_point),
    default_value,
    error_value,
    trie_type: TrieType::Small,
}
.build();

assert_eq!(cpt.get(0), 3);
assert_eq!(cpt.get(1), 4);
assert_eq!(cpt.get(2), 5);
assert_eq!(cpt.get(3), 6);
assert_eq!(cpt.get(4), 1); // default value
assert_eq!(cpt.get(u32::MAX), 2); // error value

More Information

For more information on development, authorship, contributing etc. please visit ICU4X home page.

Dependencies

~11MB
~209K SLoC