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

no-std unicode-canonical-combining-class

Fast lookup of the Canonical Combining Class property

6 releases (1 stable)

1.0.0 Oct 4, 2024
0.5.0 Sep 19, 2022
0.4.0 Jul 14, 2022
0.3.0 Jul 6, 2022
0.1.0 Jun 4, 2021

#357 in Text processing

Download history 1157/week @ 2024-08-17 884/week @ 2024-08-24 1132/week @ 2024-08-31 947/week @ 2024-09-07 445/week @ 2024-09-14 621/week @ 2024-09-21 724/week @ 2024-09-28 808/week @ 2024-10-05 655/week @ 2024-10-12 775/week @ 2024-10-19 1109/week @ 2024-10-26 1168/week @ 2024-11-02 887/week @ 2024-11-09 942/week @ 2024-11-16 1132/week @ 2024-11-23 1011/week @ 2024-11-30

4,071 downloads per month
Used in 6 crates (2 directly)

Apache-2.0

49KB
941 lines

unicode-canonical-combining-class


Fast lookup of the Unicode Canonical Combining Class property for char in Rust using Unicode 16.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