| 1 | /// BoolTrie is a trie for representing a set of Unicode codepoints. It is |
| 2 | /// implemented with postfix compression (sharing of identical child nodes), |
| 3 | /// which gives both compact size and fast lookup. |
| 4 | /// |
| 5 | /// The space of Unicode codepoints is divided into 3 subareas, each |
| 6 | /// represented by a trie with different depth. In the first (0..0x800), there |
| 7 | /// is no trie structure at all; each u64 entry corresponds to a bitvector |
| 8 | /// effectively holding 64 bool values. |
| 9 | /// |
| 10 | /// In the second (0x800..0x10000), each child of the root node represents a |
| 11 | /// 64-wide subrange, but instead of storing the full 64-bit value of the leaf, |
| 12 | /// the trie stores an 8-bit index into a shared table of leaf values. This |
| 13 | /// exploits the fact that in reasonable sets, many such leaves can be shared. |
| 14 | /// |
| 15 | /// In the third (0x10000..0x110000), each child of the root node represents a |
| 16 | /// 4096-wide subrange, and the trie stores an 8-bit index into a 64-byte slice |
| 17 | /// of a child tree. Each of these 64 bytes represents an index into the table |
| 18 | /// of shared 64-bit leaf values. This exploits the sparse structure in the |
| 19 | /// non-BMP range of most Unicode sets. |
| 20 | pub struct BoolTrierust-analyzer cargo unicode-casing 0.1.1 bool_trie/BoolTrie# { |
| 21 | // 0..0x800 (corresponding to 1 and 2 byte utf-8 sequences) |
| 22 | pub r1rust-analyzer cargo unicode-casing 0.1.1 bool_trie/BoolTrie#r1.: [u64; 32], // leaves |
| 23 | |
| 24 | // 0x800..0x10000 (corresponding to 3 byte utf-8 sequences) |
| 25 | pub r2rust-analyzer cargo unicode-casing 0.1.1 bool_trie/BoolTrie#r2.: [u8; 992], // first level |
| 26 | pub r3rust-analyzer cargo unicode-casing 0.1.1 bool_trie/BoolTrie#r3.: &'static [u64], // leaves |
| 27 | |
| 28 | // 0x10000..0x110000 (corresponding to 4 byte utf-8 sequences) |
| 29 | pub r4rust-analyzer cargo unicode-casing 0.1.1 bool_trie/BoolTrie#r4.: [u8; 256], // first level |
| 30 | pub r5rust-analyzer cargo unicode-casing 0.1.1 bool_trie/BoolTrie#r5.: &'static [u8], // second level |
| 31 | pub r6rust-analyzer cargo unicode-casing 0.1.1 bool_trie/BoolTrie#r6.: &'static [u64], // leaves |
| 32 | } |
| 33 | impl BoolTrierust-analyzer cargo unicode-casing 0.1.1 bool_trie/BoolTrie# { |
| 34 | pub fn lookuprust-analyzer cargo unicode-casing 0.1.1 bool_trie/impl#[BoolTrie]lookup().(&self, c: char) -> bool { |
| 35 | let c = c as u32; |
| 36 | if c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]lt().0x800 { |
| 37 | trie_range_leafrust-analyzer cargo unicode-casing 0.1.1 bool_trie/trie_range_leaf().(c, self.r1rust-analyzer cargo unicode-casing 0.1.1 bool_trie/BoolTrie#r1.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().(c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr().6) as usize]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().) |
| 38 | } else if c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialOrd<Self>`]lt().0x10000 { |
| 39 | let child = self.r2rust-analyzer cargo unicode-casing 0.1.1 bool_trie/BoolTrie#r2.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().(c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr().6) as usize rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().0x20]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().; |
| 40 | trie_range_leafrust-analyzer cargo unicode-casing 0.1.1 bool_trie/trie_range_leaf().(c, self.r3rust-analyzer cargo unicode-casing 0.1.1 bool_trie/BoolTrie#r3.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().child as usize]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().) |
| 41 | } else { |
| 42 | let child = self.r4rust-analyzer cargo unicode-casing 0.1.1 bool_trie/BoolTrie#r4.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().(c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr().12) as usize rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().0x10]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().; |
| 43 | let leaf = self.r5rust-analyzer cargo unicode-casing 0.1.1 bool_trie/BoolTrie#r5.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().((child as usize) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[usize][`Shl<i32>`]shl().<<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[usize][`Shl<i32>`]shl(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[usize][`Shl<i32>`]shl().6) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().((c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`Shr<i32>`]shr().6) as usize rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[usize][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[usize][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[usize][`BitAnd<Self>`]bitand().0x3f)]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().; |
| 44 | trie_range_leafrust-analyzer cargo unicode-casing 0.1.1 bool_trie/trie_range_leaf().(c, self.r6rust-analyzer cargo unicode-casing 0.1.1 bool_trie/BoolTrie#r6.[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().leaf as usize]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().) |
| 45 | } |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | fn trie_range_leafrust-analyzer cargo unicode-casing 0.1.1 bool_trie/trie_range_leaf().(c: u32, bitmap_chunk: u64) -> bool { |
| 50 | ((bitmap_chunk rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shr<u32>`]shr().>>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shr<u32>`]shr(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`Shr<u32>`]shr().(c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u32][`BitAnd<Self>`]bitand().63)) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitAnd<Self>`]bitand().&rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitAnd<Self>`]bitand(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[u64][`BitAnd<Self>`]bitand().1) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u64][`PartialEq<Self>`]ne().0 |
| 51 | } |