Skip to content

Commit 01990eb

Browse files
author
Foster Guo
committed
refactor: update documentation for clarity and accuracy in process and matcher modules
1 parent bebcd41 commit 01990eb

6 files changed

Lines changed: 21 additions & 18 deletions

File tree

matcher_rs/src/process/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919
//!
2020
//! - [`step`] — [`TransformStep`](step::TransformStep) enum and the global
2121
//! `OnceLock` cache that lazily compiles each single-bit step once.
22-
//! - [`transform`] — Low-level engines (charwise page-table, Aho-Corasick
23-
//! normalizer, SIMD delete).
22+
//! - [`transform`] — Low-level engines (page-table lookups for
23+
//! VariantNorm/Normalize/Romanize/EmojiNorm, bitset-based Delete, SIMD skip
24+
//! helpers).
2425
pub(crate) mod process_type;
2526
pub(crate) mod step;
2627
pub(crate) mod transform;

matcher_rs/src/process/process_type.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ bitflags! {
9797
/// Applies the Normalize replacement tables (e.g. full-width forms, digit-like
9898
/// variants).
9999
///
100-
/// Uses an Aho-Corasick automaton compiled from `process_map/NORM.txt` and
100+
/// Uses a page-table lookup compiled from `process_map/NORM.txt` and
101101
/// `process_map/NUM-NORM.txt`.
102102
const Normalize = 0b00001000;
103103

@@ -125,7 +125,7 @@ bitflags! {
125125
/// Also strips emoji modifiers (ZWJ, VS16, skin tones) by mapping them to empty string.
126126
///
127127
/// Does NOT compose usefully with [`Delete`](Self::Delete) — Delete removes emoji
128-
/// before EmojiNorm can see them. Use one or the other.
128+
/// before EmojiNorm can see them. Use `EmojiNorm | Normalize` for emoji→word matching.
129129
const EmojiNorm = 0b01000000;
130130
}
131131
}

matcher_rs/src/process/step.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Compiled single-step transforms for the text-processing pipeline.
22
//!
3-
//! Each [`TransformStep`] variant wraps a low-level matcher (VariantNorm,
4-
//! Delete, Normalize, Romanize) and provides a uniform
3+
//! Each [`TransformStep`] variant wraps a low-level matcher (None, VariantNorm,
4+
//! Delete, Normalize, Romanize, RomanizeChar, EmojiNorm) and provides a uniform
55
//! [`apply`](TransformStep::apply) interface. Returns `Option<String>` — `None`
66
//! when the input is unaffected.
77
//!
@@ -37,7 +37,7 @@ pub(crate) enum TransformStep {
3737
VariantNorm(VariantNormMatcher),
3838
/// Codepoint deletion using a bitset, with optional SIMD acceleration.
3939
Delete(DeleteMatcher),
40-
/// Multi-character normalization replacements via Aho-Corasick.
40+
/// Multi-character normalization replacements via page-table lookup.
4141
Normalize(NormalizeMatcher),
4242
/// CJK romanization with inter-syllable spaces preserved.
4343
Romanize(RomanizeMatcher),
@@ -47,13 +47,14 @@ pub(crate) enum TransformStep {
4747
EmojiNorm(RomanizeMatcher),
4848
}
4949

50-
/// Streaming byte iterator wrapping one of the four fusible
51-
/// [`FilterIterator`] specializations.
50+
/// Streaming byte iterator wrapping one of the four [`FilterIterator`]
51+
/// specializations (Delete, Normalize, VariantNorm, Romanize).
5252
///
5353
/// Returned by [`TransformStep::filter_bytes`] for steps that support the
54-
/// fused transform-scan path (Delete, Normalize, VariantNorm, Romanize,
55-
/// RomanizeChar). `EmojiNorm` and `None` return `Option::None` from
56-
/// `filter_bytes`.
54+
/// fused transform-scan path. Five steps support filtering (Delete,
55+
/// Normalize, VariantNorm, Romanize, RomanizeChar) — RomanizeChar reuses
56+
/// the `Romanize` filter variant. `EmojiNorm` and `None` return
57+
/// `Option::None` from `filter_bytes`.
5758
pub(crate) enum TransformFilter<'a> {
5859
Delete(FilterIterator<'a, DeleteFilter<'a>>),
5960
Normalize(FilterIterator<'a, NormalizeFilter<'a>>),

matcher_rs/src/simple_matcher/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,9 @@ pub struct SimpleResult<'a> {
144144
/// **Pass 1 — Transform and Scan**: The input text is transformed through the
145145
/// configured [`ProcessType`](crate::ProcessType) pipelines, producing the
146146
/// distinct text variants needed for this matcher. Each variant is scanned by
147-
/// the bytewise or charwise engine, selected by SIMD density scan (≤0.67
148-
/// non-ASCII → bytewise, >0.67 → charwise). Hits update per-rule state;
147+
/// the bytewise or charwise engine, selected by SIMD density scan (density
148+
/// ≥ 0.55 → bytewise, < 0.55 → charwise; higher density = more ASCII).
149+
/// Hits update per-rule state;
149150
/// simple rules stay on a bitmask fast path, while more complex rules fall
150151
/// back to a per-rule counter matrix.
151152
///

matcher_rs/src/simple_matcher/pattern.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ pub(super) fn decode_direct(raw: u32) -> (u8, u8, PatternKind, usize, usize) {
125125
/// - No operator, or `&` → [`And`](Self::And)
126126
/// - `~` → [`Not`](Self::Not)
127127
///
128-
/// Single-segment rules without NOT use `SatisfactionMethod::SingleAnd` for the
129-
/// simplified satisfaction path. The DIRECT bit-packing in `process_match`
128+
/// Single-segment rules without NOT use [`SatisfactionMethod::Immediate`] for
129+
/// the simplified satisfaction path. The DIRECT bit-packing in `process_match`
130130
/// handles these inline without consulting `PatternKind`.
131131
///
132132
/// `repr(u8)` keeps this type small for dense storage in [`PatternEntry`].
@@ -137,7 +137,7 @@ pub(super) enum PatternKind {
137137
///
138138
/// All AND segments in a rule must be satisfied (across any text variant)
139139
/// before the rule can fire. Single-segment rules also use this variant
140-
/// (with `SatisfactionMethod::SingleAnd`).
140+
/// (with [`SatisfactionMethod::Immediate`]).
141141
And = 0,
142142
/// Negative segment that vetoes the rule when observed.
143143
///

matcher_rs/src/simple_matcher/scan.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ macro_rules! dispatch {
446446
/// Both engines are always built from the full pattern set. The charwise
447447
/// engine gives ~1.6–1.9× throughput over bytewise on CJK-heavy text (3 UTF-8
448448
/// bytes → 1 charwise transition). Engine selection is density-based at
449-
/// runtime: bytewise for [`CHARWISE_DENSITY_THRESHOLD`], charwise above.
449+
/// runtime: bytewise for [`CHARWISE_DENSITY_THRESHOLD`], charwise below.
450450
#[derive(Clone)]
451451
pub(super) struct ScanPlan {
452452
engines: Engines,

0 commit comments

Comments
 (0)