@@ -439,9 +439,13 @@ impl TwoWaySearcher {
439
439
let byteset = needle. iter ( )
440
440
. fold ( 0 , |a, & b| ( 1 << ( ( b & 0x3f ) as uint ) ) | a) ;
441
441
442
- // Check if the needle is periodic. If so, during searching when we
443
- // find a mismatch, we must only advance the position by the length
444
- // of the period, not the length of the entire needle
442
+
443
+ // The logic here (calculating critPos and period, the final if statement to see which
444
+ // period to use for the TwoWaySearcher) is essentially an implementation of the
445
+ // "small-period" function from the paper (p. 670)
446
+ //
447
+ // In the paper they check whether `needle.slice_to(critPos)` is a suffix of
448
+ // `needle.slice(critPos, critPos + period)`, which is precisely what this does
445
449
if needle. slice_to ( critPos) == needle. slice ( period, period + critPos) {
446
450
TwoWaySearcher {
447
451
critPos : critPos,
@@ -513,6 +517,9 @@ impl TwoWaySearcher {
513
517
}
514
518
}
515
519
520
+ // returns (i, p) where i is the "critical position", the starting index of
521
+ // of maximal suffix, and p is the period of the suffix
522
+ // see p. 668 of the paper
516
523
#[ inline]
517
524
fn maximal_suffix ( arr : & [ u8 ] , reversed : bool ) -> ( uint , uint ) {
518
525
let mut left = -1 ; // Corresponds to i in the paper
0 commit comments