yeslogic-unicode-script

Crates.ioyeslogic-unicode-script
lib.rsyeslogic-unicode-script
version1.0.0
sourcesrc
created_at2020-01-09 06:50:07.101872
updated_at2024-10-31 00:26:11.178033
descriptionFast lookup of the Unicode Script property
homepagehttps://github.com/yeslogic/unicode-script
repositoryhttps://github.com/yeslogic/unicode-script
max_upload_size
id196850
size63,168
Developers (prince) (github:yeslogic:developers-prince)

documentation

https://docs.rs/crate/yeslogic-unicode-script

README

yeslogic-unicode-script

Build Status Documentation Unicode Version Version

Fast lookup of the Unicode Script property for char in Rust using Unicode 16.0 data.

Usage

use unicode_script::{get_script, Script};

fn main() {
    assert_eq!(get_script('A'), Script::Latin);
    assert_eq!(get_script('カ'), Script::Katakana);
}

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. The allows the second level of 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 43KiB. 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.

Commit count: 38

cargo fmt