Portable SIMD byte and substring search, double-ended byte matches, and reusable Two-Way finders ported from memchr
///|
test "byte search and view-relative offsets" {
assert_eq(@memchr.memchr(b'o', b"foo bar foo"), Some(1))
assert_eq(@memchr.memrchr(b'o', b"foo bar foo"), Some(10))
assert_eq(@memchr.memchr2(b' ', b'!', b"foo bar"), Some(3))
assert_eq(@memchr.memchr3(b'x', b'y', b'z', b"xyz"[1:]), Some(0))
}///|
test "mixed cursor consumption and independent copies" {
let matches = @memchr.memchr_iter(b'o', b"foo bar foo")
assert_eq(matches.next(), Some(1))
let copy = matches.copy()
assert_eq(matches.next_back(), Some(10))
assert_eq(matches.count(), 2)
assert_eq(copy.iter().to_array(), [2, 9, 10])
}pub struct Matches {
// private fields
}fn memchr(needle : Byte, haystack : BytesView, simd? : Bool) -> Int?test {
assert_eq(@memchr.memchr(b'o', b"foo bar"), Some(1))
assert_eq(@memchr.memchr(b'x', b"foo bar"), None)
}fn memchr2(needle1 : Byte, needle2 : Byte, haystack : BytesView, simd? : Bool) -> Int?fn memchr3(needle1 : Byte, needle2 : Byte, needle3 : Byte, haystack : BytesView, simd? : Bool) -> Int?fn memchr3_iter(needle1 : Byte, needle2 : Byte, needle3 : Byte, haystack : BytesView, simd? : Bool) -> Matchesfn memrchr(needle : Byte, haystack : BytesView, simd? : Bool) -> Int?fn memrchr2(needle1 : Byte, needle2 : Byte, haystack : BytesView, simd? : Bool) -> Int?fn memrchr3(needle1 : Byte, needle2 : Byte, needle3 : Byte, haystack : BytesView, simd? : Bool) -> Int?fn memrchr3_iter(needle1 : Byte, needle2 : Byte, needle3 : Byte, haystack : BytesView, simd? : Bool) -> MatchesInstall
Download zipPortable SIMD byte and substring search, double-ended byte matches, and reusable Two-Way finders ported from memchr