Skip to content

Commit 4324451

Browse files
committed
Fix suffix_array's signature
1 parent e87e825 commit 4324451

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/string.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,8 @@ pub fn suffix_array_arbitrary<T: Ord>(s: &[T]) -> Vec<usize> {
234234
sa_is_i32::<DefaultThreshold>(&s2, now)
235235
}
236236

237-
pub fn suffix_array(s: impl IntoIterator<Item = char>) -> Vec<usize> {
238-
let s2: Vec<usize> = s.into_iter().map(|x| x as usize).collect();
237+
pub fn suffix_array(s: &str) -> Vec<usize> {
238+
let s2: Vec<usize> = s.bytes().map(|x| x as usize).collect();
239239
sa_is::<DefaultThreshold>(&s2, 255)
240240
}
241241

@@ -334,7 +334,7 @@ mod tests {
334334
let sa_is = sa_is_i32::<ZeroThreshold>(&array, 255);
335335
assert_eq!(sa_is, expected_array);
336336

337-
let sa_str = suffix_array(str.chars());
337+
let sa_str = suffix_array(str);
338338
assert_eq!(sa_str, expected_array);
339339
}
340340

@@ -360,15 +360,15 @@ mod tests {
360360
#[test]
361361
fn test_lcp_0() {
362362
let str = "abracadabra";
363-
let sa = suffix_array(str.chars());
363+
let sa = suffix_array(str);
364364
let lcp = lcp_array(str, &sa);
365365
assert_eq!(lcp, &[1, 4, 1, 1, 0, 3, 0, 0, 0, 2]);
366366
}
367367

368368
#[test]
369369
fn test_lcp_1() {
370370
let str = "mmiissiissiippii"; // an example taken from https://mametter.hatenablog.com/entry/20180130/p1
371-
let sa = suffix_array(str.chars());
371+
let sa = suffix_array(str);
372372
let lcp = lcp_array(str, &sa);
373373
assert_eq!(lcp, &[1, 2, 2, 6, 1, 1, 5, 0, 1, 0, 1, 0, 3, 1, 4]);
374374
}

0 commit comments

Comments
 (0)