#unicode #combining #class #canonical #no-std #properties

no-std unicode-canonical-combining-class

Fast lookup of the Canonical Combining Class property

5 releases (breaking)

0.5.0 Sep 19, 2022
0.4.0 Jul 14, 2022
0.3.0 Jul 6, 2022
0.2.0 Jan 25, 2022
0.1.0 Jun 4, 2021

#702 in Text processing

Download history 210/week @ 2023-12-09 251/week @ 2023-12-16 83/week @ 2023-12-23 193/week @ 2023-12-30 307/week @ 2024-01-06 349/week @ 2024-01-13 374/week @ 2024-01-20 347/week @ 2024-01-27 246/week @ 2024-02-03 554/week @ 2024-02-10 562/week @ 2024-02-17 630/week @ 2024-02-24 554/week @ 2024-03-02 531/week @ 2024-03-09 535/week @ 2024-03-16 527/week @ 2024-03-23

2,266 downloads per month
Used in 8 crates (2 directly)

Apache-2.0

49KB
932 lines

unicode-canonical-combining-class


Fast lookup of the Unicode Canonical Combining Class property for char in Rust using Unicode 15.0 data. This crate is no-std compatible.

Usage

use unicode_canonical_combining_class::{get_canonical_combining_class, CanonicalCombiningClass};

fn main() {
    assert_eq!(get_canonical_combining_class(''), CanonicalCombiningClass::CCC129);
}

Performance & Implementation Notes

ucd-generate is used to generate tables.rs. A build script (build.rs) compiles this into a two level look up table. The look up time is constant as it is just indexing into two arrays.

The two level approach maps a code point to a block, then to a position within a block. This allows the second level block to be deduplicated, saving space. The code is parameterised over the block size, which must be a power of 2. The value in the build script is optimal for the data set.

This approach trades off some space for faster lookups. The tables take up about 24.5KiB. Benchmarks showed this approach to be ~5–10× faster than the typical binary search approach.

It's possible there are further optimisations that could be made to eliminate some runs of repeated values in the first level array.

No runtime deps