Skip to content

Commit 32922f5

Browse files
committed
---
yaml --- r: 154575 b: refs/heads/try2 c: 9a43492 h: refs/heads/master i: 154573: bd8bd4f 154571: 2d20b71 154567: 6952a2f 154559: c0c9791 v: v3
1 parent d5c333b commit 32922f5

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 9419e9265950a16f873dbed49c715fd7ea4e08e7
8+
refs/heads/try2: 9a43492f59bfc38ed819e361c3cf99aa7b972e15
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libcore/str.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -439,9 +439,13 @@ impl TwoWaySearcher {
439439
let byteset = needle.iter()
440440
.fold(0, |a, &b| (1 << ((b & 0x3f) as uint)) | a);
441441

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
445449
if needle.slice_to(critPos) == needle.slice(period, period + critPos) {
446450
TwoWaySearcher {
447451
critPos: critPos,
@@ -513,6 +517,9 @@ impl TwoWaySearcher {
513517
}
514518
}
515519

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
516523
#[inline]
517524
fn maximal_suffix(arr: &[u8], reversed: bool) -> (uint, uint) {
518525
let mut left = -1; // Corresponds to i in the paper

0 commit comments

Comments
 (0)