nucleo-matcher 0.1.0

plug and play high performance fuzzy matcher
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
/*!
`nucleo_matcher` is a low level crate that contains the matcher implementation
used by the other nucleo crates.

The matcher is hightly optimized and can significantly outperform `fzf` and
`skim` (the `fuzzy-matcher` crate). However some of these optimizations require
a slightly less convenient API. Particularly, `nucleo_matcher` requires that
needles and haystacks are provided as [UTF32 strings](crate::Utf32Str) instead
of rusts normal utf32 strings.
*/

// sadly ranges don't optmimzie well
#![allow(clippy::manual_range_contains)]

pub mod chars;
mod config;
#[cfg(test)]
mod debug;
mod exact;
mod fuzzy_greedy;
mod fuzzy_optimal;
mod matrix;
mod prefilter;
mod score;
mod utf32_str;

#[cfg(test)]
mod tests;

pub use crate::config::MatcherConfig;
pub use crate::utf32_str::Utf32Str;

use crate::chars::{AsciiChar, Char};
use crate::matrix::MatrixSlab;

/// A matcher engine that can execute (fuzzy) matches.
///
/// A matches contains **heap allocated** scratch memory that is reused during
/// matching. This scratch memory allows the matcher to guarantee that it will
/// **never allocate** during matching (with the exception of pushing to the
/// `indices` vector if there isn't enough capacity). However this scratch
/// memory is fairly large (around 135KB) so creating a matcher is expensive and
/// should be reused.
///
/// All `.._match` functions will not compute the indices of the matched chars
/// and are therefore significantly faster. These should be used to prefitler
/// and sort all matches. All `.._indices` functions will compute the indices of
/// the computed chars. These should be used when rendering the best N matches.
/// Note that the `indices` argument is **never cleared**. This allows running
/// multiple different matches on the same haystack and merging the indices by
/// sorting and deduplicating the vector.
///
/// Matching is limited to 2^32-1 codepoints, if the haystack is longer than
/// that the matcher *will panic*. The caller must decide whether it wants to
/// filter out long haystacks or truncate them.
pub struct Matcher {
    pub config: MatcherConfig,
    slab: MatrixSlab,
}

// this is just here for convenience not sure if we should implement this
impl Clone for Matcher {
    fn clone(&self) -> Self {
        Matcher {
            config: self.config,
            slab: MatrixSlab::new(),
        }
    }
}

impl std::fmt::Debug for Matcher {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("Matcher")
            .field("config", &self.config)
            .finish_non_exhaustive()
    }
}

impl Default for Matcher {
    fn default() -> Self {
        Matcher {
            config: MatcherConfig::DEFAULT,
            slab: MatrixSlab::new(),
        }
    }
}

impl Matcher {
    pub fn new(config: MatcherConfig) -> Self {
        Self {
            config,
            slab: MatrixSlab::new(),
        }
    }

    /// Find the fuzzy match with the highest score in the `haystack`.
    ///
    /// This functions has `O(mn)` time complexity for short inputs. To
    /// avoid slowdowns it automatically falls back to [greedy matching]
    /// (crate::Matcher::fuzzy_match_greedy) for large needles and haystacks
    ///
    /// See the [matcher documentation](crate::Matcher) for more details.
    pub fn fuzzy_match(&mut self, haystack: Utf32Str<'_>, needle: Utf32Str<'_>) -> Option<u16> {
        assert!(haystack.len() <= u32::MAX as usize);
        self.fuzzy_matcher_impl::<false>(haystack, needle, &mut Vec::new())
    }

    /// Find the fuzzy match with the higehest score in the `haystack` and
    /// compute its indices.
    ///
    /// This functions has `O(mn)` time complexity for short inputs. To
    /// avoid slowdowns it automatically falls back to [greedy matching]
    /// (crate::Matcher::fuzzy_match_greedy) for large needles and haystacks
    ///
    /// See the [matcher documentation](crate::Matcher) for more details.
    pub fn fuzzy_indices(
        &mut self,
        haystack: Utf32Str<'_>,
        needle: Utf32Str<'_>,
        indices: &mut Vec<u32>,
    ) -> Option<u16> {
        assert!(haystack.len() <= u32::MAX as usize);
        self.fuzzy_matcher_impl::<true>(haystack, needle, indices)
    }

    fn fuzzy_matcher_impl<const INDICES: bool>(
        &mut self,
        haystack_: Utf32Str<'_>,
        needle_: Utf32Str<'_>,
        indices: &mut Vec<u32>,
    ) -> Option<u16> {
        if needle_.len() > haystack_.len() {
            return None;
        }
        if needle_.is_empty() {
            return Some(0);
        }
        if needle_.len() == haystack_.len() {
            return self.exact_match_impl::<INDICES>(
                haystack_,
                needle_,
                0,
                haystack_.len(),
                indices,
            );
        }
        assert!(
            haystack_.len() <= u32::MAX as usize,
            "fuzzy matching is only support for up to 2^32-1 codepoints"
        );
        match (haystack_, needle_) {
            (Utf32Str::Ascii(haystack), Utf32Str::Ascii(needle)) => {
                if let &[needle] = needle {
                    return self.substring_match_1_ascii::<INDICES>(haystack, needle, indices);
                }
                let (start, greedy_end, end) = self.prefilter_ascii(haystack, needle, false)?;
                if needle_.len() == end - start {
                    return Some(self.calculate_score::<INDICES, _, _>(
                        AsciiChar::cast(haystack),
                        AsciiChar::cast(needle),
                        start,
                        greedy_end,
                        indices,
                    ));
                }
                self.fuzzy_match_optimal::<INDICES, AsciiChar, AsciiChar>(
                    AsciiChar::cast(haystack),
                    AsciiChar::cast(needle),
                    start,
                    greedy_end,
                    end,
                    indices,
                )
            }
            (Utf32Str::Ascii(_), Utf32Str::Unicode(_)) => {
                // a purely ascii haystack can never be transformed to match
                // a needle that contains non-ascii chars since we don't allow gaps
                None
            }
            (Utf32Str::Unicode(haystack), Utf32Str::Ascii(needle)) => {
                if let &[needle] = needle {
                    let (start, _) = self.prefilter_non_ascii(haystack, needle_, true)?;
                    let res = self.substring_match_1_non_ascii::<INDICES>(
                        haystack,
                        needle as char,
                        start,
                        indices,
                    );
                    return Some(res);
                }
                let (start, end) = self.prefilter_non_ascii(haystack, needle_, false)?;
                if needle_.len() == end - start {
                    return self
                        .exact_match_impl::<INDICES>(haystack_, needle_, start, end, indices);
                }
                self.fuzzy_match_optimal::<INDICES, char, AsciiChar>(
                    haystack,
                    AsciiChar::cast(needle),
                    start,
                    start + 1,
                    end,
                    indices,
                )
            }
            (Utf32Str::Unicode(haystack), Utf32Str::Unicode(needle)) => {
                if let &[needle] = needle {
                    let (start, _) = self.prefilter_non_ascii(haystack, needle_, true)?;
                    let res = self
                        .substring_match_1_non_ascii::<INDICES>(haystack, needle, start, indices);
                    return Some(res);
                }
                let (start, end) = self.prefilter_non_ascii(haystack, needle_, false)?;
                if needle_.len() == end - start {
                    return self
                        .exact_match_impl::<INDICES>(haystack_, needle_, start, end, indices);
                }
                self.fuzzy_match_optimal::<INDICES, char, char>(
                    haystack,
                    needle,
                    start,
                    start + 1,
                    end,
                    indices,
                )
            }
        }
    }

    /// Greedly find a fuzzy match in the `haystack`.
    ///
    /// This functions has `O(n)` time complexity but may provide unintutive (non-optimal)
    /// indices and scores. Usually [fuzz_indices](crate::Matcher::fuzzy_indices) should
    /// be preferred.
    ///
    /// See the [matcher documentation](crate::Matcher) for more details.
    pub fn fuzzy_match_greedy(
        &mut self,
        haystack: Utf32Str<'_>,
        needle: Utf32Str<'_>,
    ) -> Option<u16> {
        assert!(haystack.len() <= u32::MAX as usize);
        self.fuzzy_match_greedy_impl::<false>(haystack, needle, &mut Vec::new())
    }

    /// Greedly find a fuzzy match in the `haystack` and compute its indices.
    ///
    /// This functions has `O(n)` time complexity but may provide unintuitive (non-optimal)
    /// indices and scores. Usually [fuzz_indices](crate::Matcher::fuzzy_indices) should
    /// be preferred.
    ///
    /// See the [matcher documentation](crate::Matcher) for more details.
    pub fn fuzzy_indices_greedy(
        &mut self,
        haystack: Utf32Str<'_>,
        needle: Utf32Str<'_>,
        indices: &mut Vec<u32>,
    ) -> Option<u16> {
        assert!(haystack.len() <= u32::MAX as usize);
        self.fuzzy_match_greedy_impl::<true>(haystack, needle, indices)
    }

    fn fuzzy_match_greedy_impl<const INDICES: bool>(
        &mut self,
        haystack: Utf32Str<'_>,
        needle_: Utf32Str<'_>,
        indices: &mut Vec<u32>,
    ) -> Option<u16> {
        if needle_.len() > haystack.len() {
            return None;
        }
        if needle_.is_empty() {
            return Some(0);
        }
        if needle_.len() == haystack.len() {
            return self.exact_match_impl::<INDICES>(haystack, needle_, 0, haystack.len(), indices);
        }
        assert!(
            haystack.len() <= u32::MAX as usize,
            "matching is only support for up to 2^32-1 codepoints"
        );
        match (haystack, needle_) {
            (Utf32Str::Ascii(haystack), Utf32Str::Ascii(needle)) => {
                let (start, greedy_end, _) = self.prefilter_ascii(haystack, needle, true)?;
                if needle_.len() == greedy_end - start {
                    return Some(self.calculate_score::<INDICES, _, _>(
                        AsciiChar::cast(haystack),
                        AsciiChar::cast(needle),
                        start,
                        greedy_end,
                        indices,
                    ));
                }
                self.fuzzy_match_greedy_::<INDICES, AsciiChar, AsciiChar>(
                    AsciiChar::cast(haystack),
                    AsciiChar::cast(needle),
                    start,
                    greedy_end,
                    indices,
                )
            }
            (Utf32Str::Ascii(_), Utf32Str::Unicode(_)) => {
                // a purely ascii haystack can never be transformed to match
                // a needle that contains non-ascii chars since we don't allow gaps
                None
            }
            (Utf32Str::Unicode(haystack), Utf32Str::Ascii(needle)) => {
                let (start, _) = self.prefilter_non_ascii(haystack, needle_, true)?;
                self.fuzzy_match_greedy_::<INDICES, char, AsciiChar>(
                    haystack,
                    AsciiChar::cast(needle),
                    start,
                    start + 1,
                    indices,
                )
            }
            (Utf32Str::Unicode(haystack), Utf32Str::Unicode(needle)) => {
                let (start, _) = self.prefilter_non_ascii(haystack, needle_, true)?;
                self.fuzzy_match_greedy_::<INDICES, char, char>(
                    haystack,
                    needle,
                    start,
                    start + 1,
                    indices,
                )
            }
        }
    }

    /// Finds the substring match with the highest score in the `haystack`.
    ///
    /// This functions has `O(nm)` time complexity. However many cases can
    /// be significantly accelerated using prefilters so it's usually fast
    /// in practice.
    ///
    /// See the [matcher documentation](crate::Matcher) for more details.
    pub fn substring_match(
        &mut self,
        haystack: Utf32Str<'_>,
        needle_: Utf32Str<'_>,
    ) -> Option<u16> {
        self.substring_match_impl::<false>(haystack, needle_, &mut Vec::new())
    }

    /// Finds the substring match with the highest score in the `haystack` and
    /// compute its indices.
    ///
    /// This functions has `O(nm)` time complexity. However many cases can
    /// be significantly accelerated using prefilters so it's usually fast
    /// in practice.
    ///
    /// See the [matcher documentation](crate::Matcher) for more details.
    pub fn substring_indices(
        &mut self,
        haystack: Utf32Str<'_>,
        needle_: Utf32Str<'_>,
        indices: &mut Vec<u32>,
    ) -> Option<u16> {
        self.substring_match_impl::<true>(haystack, needle_, indices)
    }

    fn substring_match_impl<const INDICES: bool>(
        &mut self,
        haystack: Utf32Str<'_>,
        needle_: Utf32Str<'_>,
        indices: &mut Vec<u32>,
    ) -> Option<u16> {
        if needle_.len() > haystack.len() {
            return None;
        }
        if needle_.is_empty() {
            return Some(0);
        }
        if needle_.len() == haystack.len() {
            return self.exact_match_impl::<INDICES>(haystack, needle_, 0, haystack.len(), indices);
        }
        assert!(
            haystack.len() <= u32::MAX as usize,
            "matching is only support for up to 2^32-1 codepoints"
        );
        match (haystack, needle_) {
            (Utf32Str::Ascii(haystack), Utf32Str::Ascii(needle)) => {
                if let &[needle] = needle {
                    return self.substring_match_1_ascii::<INDICES>(haystack, needle, indices);
                }
                self.substring_match_ascii::<INDICES>(haystack, needle, indices)
            }
            (Utf32Str::Ascii(_), Utf32Str::Unicode(_)) => {
                // a purely ascii haystack can never be transformed to match
                // a needle that contains non-ascii chars since we don't allow gaps
                None
            }
            (Utf32Str::Unicode(haystack), Utf32Str::Ascii(needle)) => {
                if let &[needle] = needle {
                    let (start, _) = self.prefilter_non_ascii(haystack, needle_, true)?;
                    let res = self.substring_match_1_non_ascii::<INDICES>(
                        haystack,
                        needle as char,
                        start,
                        indices,
                    );
                    return Some(res);
                }
                let (start, _) = self.prefilter_non_ascii(haystack, needle_, false)?;
                self.substring_match_non_ascii::<INDICES, _>(
                    haystack,
                    AsciiChar::cast(needle),
                    start,
                    indices,
                )
            }
            (Utf32Str::Unicode(haystack), Utf32Str::Unicode(needle)) => {
                if let &[needle] = needle {
                    let (start, _) = self.prefilter_non_ascii(haystack, needle_, true)?;
                    let res = self
                        .substring_match_1_non_ascii::<INDICES>(haystack, needle, start, indices);
                    return Some(res);
                }
                let (start, end) = self.prefilter_non_ascii(haystack, needle_, false)?;
                self.fuzzy_match_optimal::<INDICES, char, char>(
                    haystack,
                    needle,
                    start,
                    start + 1,
                    end,
                    indices,
                )
            }
        }
    }

    /// Checks whether needle and haystack match exactly.
    ///
    /// This functions has `O(n)` time complexity.
    ///
    /// See the [matcher documentation](crate::Matcher) for more details.
    pub fn exact_match(&mut self, haystack: Utf32Str<'_>, needle: Utf32Str<'_>) -> Option<u16> {
        if needle.is_empty() {
            return Some(0);
        }
        let mut leading_space = 0;
        let mut trailing_space = 0;
        if !needle.first().is_whitespace() {
            leading_space = haystack.leading_white_space()
        }
        if !needle.last().is_whitespace() {
            trailing_space = haystack.trailing_white_space()
        }
        // avoid wraparound in size check
        if trailing_space == haystack.len() {
            return None;
        }
        self.exact_match_impl::<false>(
            haystack,
            needle,
            leading_space,
            haystack.len() - trailing_space,
            &mut Vec::new(),
        )
    }

    /// Checks whether needle and haystack match exactly and compute the matches indices.
    ///
    /// This functions has `O(n)` time complexity.
    ///
    /// See the [matcher documentation](crate::Matcher) for more details.
    pub fn exact_indices(
        &mut self,
        haystack: Utf32Str<'_>,
        needle: Utf32Str<'_>,
        indices: &mut Vec<u32>,
    ) -> Option<u16> {
        if needle.is_empty() {
            return Some(0);
        }
        let mut leading_space = 0;
        let mut trailing_space = 0;
        if !needle.first().is_whitespace() {
            leading_space = haystack.leading_white_space()
        }
        if !needle.last().is_whitespace() {
            trailing_space = haystack.trailing_white_space()
        }
        // avoid wraparound in size check
        if trailing_space == haystack.len() {
            return None;
        }
        self.exact_match_impl::<true>(
            haystack,
            needle,
            leading_space,
            haystack.len() - trailing_space,
            indices,
        )
    }

    /// Checks whether needle is a prefix of the haystack.
    ///
    /// This functions has `O(n)` time complexity.
    ///
    /// See the [matcher documentation](crate::Matcher) for more details.
    pub fn prefix_match(&mut self, haystack: Utf32Str<'_>, needle: Utf32Str<'_>) -> Option<u16> {
        if needle.is_empty() {
            return Some(0);
        }
        let mut leading_space = 0;
        if !needle.first().is_whitespace() {
            leading_space = haystack.leading_white_space()
        }
        if haystack.len() - leading_space < needle.len() {
            None
        } else {
            self.exact_match_impl::<false>(
                haystack,
                needle,
                leading_space,
                needle.len() + leading_space,
                &mut Vec::new(),
            )
        }
    }

    /// Checks whether needle is a prefix of the haystack and compute the matches indices.
    ///
    /// This functions has `O(n)` time complexity.
    ///
    /// See the [matcher documentation](crate::Matcher) for more details.
    pub fn prefix_indices(
        &mut self,
        haystack: Utf32Str<'_>,
        needle: Utf32Str<'_>,
        indices: &mut Vec<u32>,
    ) -> Option<u16> {
        if needle.is_empty() {
            return Some(0);
        }
        let mut leading_space = 0;
        if !needle.first().is_whitespace() {
            leading_space = haystack.leading_white_space()
        }
        if haystack.len() - leading_space < needle.len() {
            None
        } else {
            self.exact_match_impl::<true>(
                haystack,
                needle,
                leading_space,
                needle.len() + leading_space,
                indices,
            )
        }
    }

    /// Checks whether needle is a postfix of the haystack.
    ///
    /// This functions has `O(n)` time complexity.
    ///
    /// See the [matcher documentation](crate::Matcher) for more details.
    pub fn postfix_match(&mut self, haystack: Utf32Str<'_>, needle: Utf32Str<'_>) -> Option<u16> {
        if needle.is_empty() {
            return Some(0);
        }
        let mut trailing_spaces = 0;
        if !needle.last().is_whitespace() {
            trailing_spaces = haystack.trailing_white_space()
        }
        if haystack.len() - trailing_spaces < needle.len() {
            None
        } else {
            self.exact_match_impl::<false>(
                haystack,
                needle,
                haystack.len() - needle.len() - trailing_spaces,
                haystack.len() - trailing_spaces,
                &mut Vec::new(),
            )
        }
    }

    /// Checks whether needle is a postfix of the haystack and compute the matches indices.
    ///
    /// This functions has `O(n)` time complexity.
    ///
    /// See the [matcher documentation](crate::Matcher) for more details.
    pub fn postfix_indices(
        &mut self,
        haystack: Utf32Str<'_>,
        needle: Utf32Str<'_>,
        indices: &mut Vec<u32>,
    ) -> Option<u16> {
        if needle.is_empty() {
            return Some(0);
        }
        let mut trailing_spaces = 0;
        if !needle.last().is_whitespace() {
            trailing_spaces = haystack.trailing_white_space()
        }
        if haystack.len() - trailing_spaces < needle.len() {
            None
        } else {
            self.exact_match_impl::<true>(
                haystack,
                needle,
                haystack.len() - needle.len() - trailing_spaces,
                haystack.len() - trailing_spaces,
                indices,
            )
        }
    }

    fn exact_match_impl<const INDICES: bool>(
        &mut self,
        haystack: Utf32Str<'_>,
        needle_: Utf32Str<'_>,
        start: usize,
        end: usize,
        indices: &mut Vec<u32>,
    ) -> Option<u16> {
        if needle_.len() != end - start {
            return None;
        }
        assert!(
            haystack.len() <= u32::MAX as usize,
            "matching is only support for up to 2^32-1 codepoints"
        );
        let score = match (haystack, needle_) {
            (Utf32Str::Ascii(haystack), Utf32Str::Ascii(needle)) => {
                let matched = if self.config.ignore_case {
                    AsciiChar::cast(haystack)[start..end]
                        .iter()
                        .map(|c| c.normalize(&self.config))
                        .eq(AsciiChar::cast(needle)
                            .iter()
                            .map(|c| c.normalize(&self.config)))
                } else {
                    haystack == needle
                };
                if !matched {
                    return None;
                }
                self.calculate_score::<INDICES, _, _>(
                    AsciiChar::cast(haystack),
                    AsciiChar::cast(needle),
                    start,
                    end,
                    indices,
                )
            }
            (Utf32Str::Ascii(_), Utf32Str::Unicode(_)) => {
                // a purely ascii haystack can never be transformed to match
                // a needle that contains non-ascii chars since we don't allow gaps
                return None;
            }
            (Utf32Str::Unicode(haystack), Utf32Str::Ascii(needle)) => {
                let matched = haystack[start..end]
                    .iter()
                    .map(|c| c.normalize(&self.config))
                    .eq(AsciiChar::cast(needle)
                        .iter()
                        .map(|c| c.normalize(&self.config)));
                if !matched {
                    return None;
                }

                self.calculate_score::<INDICES, _, _>(
                    haystack,
                    AsciiChar::cast(needle),
                    start,
                    end,
                    indices,
                )
            }
            (Utf32Str::Unicode(haystack), Utf32Str::Unicode(needle)) => {
                let matched = haystack[start..end]
                    .iter()
                    .map(|c| c.normalize(&self.config))
                    .eq(needle.iter().map(|c| c.normalize(&self.config)));
                if !matched {
                    return None;
                }
                self.calculate_score::<INDICES, _, _>(haystack, needle, start, end, indices)
            }
        };
        Some(score)
    }
}