unicode-general-category

Crates.iounicode-general-category
lib.rsunicode-general-category
version1.0.0
sourcesrc
created_at2019-12-13 03:41:47.759947
updated_at2024-10-30 01:50:59.435627
descriptionFast lookup of the Unicode General Category property for char
homepagehttps://github.com/yeslogic/unicode-general-category
repositoryhttps://github.com/yeslogic/unicode-general-category
max_upload_size
id188972
size233,647
Developers (prince) (github:yeslogic:developers-prince)

documentation

https://docs.rs/unicode-general-category

README

unicode-general-category

Build Status Documentation Version Unicode Version License

Fast lookup of the Unicode General Category property for char in Rust using Unicode 16.0 data. This crate is no-std compatible.

Usage

use unicode_general_category::{get_general_category, GeneralCategory};

fn main() {
    assert_eq!(get_general_category('A'), GeneralCategory::UppercaseLetter);
}

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 45KiB. 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: 31

cargo fmt