pub fn symbol_class(s: u32) -> u64Expand description
Bit that represents the character class of symbol s (used by subtree
signatures). Symbols are Unicode scalar values (see docs/design/unicode.md).
- ASCII (
s < 128): bits & 63, so ASCII characters that agree modulo 64 share a class (a(97) and!(33), for instance, or digits andp-y). The lettersa-ztake the classes 33 to 58 and are distinct from one another. - Everything else: one of the 38 classes the letters
a-znever use (0 to 32 and 59 to 63), chosen bys % 38, so that an accented letter or a letter of another script never hides a missinga-zletter.
The collisions are harmless: the signatures only bound the search, and a collision can make a bound weaker (a class looks present when it is not), never wrong. The proof needs only that equal symbols have equal classes.
§Examples
use keyhammer::cost::symbol_class;
assert_ne!(symbol_class('a'.into()), symbol_class('b'.into()));
assert_eq!(symbol_class('a'.into()), symbol_class('!'.into())); // 97 and 33, modulo 64
// No non-ASCII symbol shares a class with a letter a-z.
let letters = ('a'..='z').fold(0, |m, c| m | symbol_class(c.into()));
assert_eq!(symbol_class('é'.into()) & letters, 0);