Skip to content

Commit efded4e

Browse files
committed
---
yaml --- r: 129499 b: refs/heads/snap-stage3 c: 9a43492 h: refs/heads/master i: 129497: 46f84fe 129495: abc5845 v: v3
1 parent 26a200e commit efded4e

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
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 566b470e138e929e8a93d613372db1ba177c494f
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 9419e9265950a16f873dbed49c715fd7ea4e08e7
4+
refs/heads/snap-stage3: 9a43492f59bfc38ed819e361c3cf99aa7b972e15
55
refs/heads/try: 80b45ddbd351f0a4a939c3a3c4e20b4defec4b35
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/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)