memchr::arch::x86_64::avx2::memchr

Struct Three

Source
pub struct Three { /* private fields */ }
Expand description

Finds all occurrences of three bytes in a haystack.

That is, this reports matches of one of three possible bytes. For example, searching for a, b or o in afoobar would report matches at offsets 0, 2, 3, 4 and 5.

Implementations§

Source§

impl Three

Source

pub fn new(needle1: u8, needle2: u8, needle3: u8) -> Option<Three>

Create a new searcher that finds occurrences of the needle bytes given.

This particular searcher is specialized to use AVX2 vector instructions that typically make it quite fast. (SSE2 is used for haystacks that are too short to accommodate an AVX2 vector.)

If either SSE2 or AVX2 is unavailable in the current environment, then None is returned.

Source

pub unsafe fn new_unchecked(needle1: u8, needle2: u8, needle3: u8) -> Three

Available on target features sse2 and avx2 only.

Create a new finder specific to AVX2 vectors and routines without checking that either SSE2 or AVX2 is available.

§Safety

Callers must guarantee that it is safe to execute both sse2 and avx2 instructions in the current environment.

Note that it is a common misconception that if one compiles for an x86_64 target, then they therefore automatically have access to SSE2 instructions. While this is almost always the case, it isn’t true in 100% of cases.

Source

pub fn is_available() -> bool

Returns true when this implementation is available in the current environment.

When this is true, it is guaranteed that Three::new will return a Some value. Similarly, when it is false, it is guaranteed that Three::new will return a None value.

Note also that for the lifetime of a single program, if this returns true then it will always return true.

Source

pub fn find(&self, haystack: &[u8]) -> Option<usize>

Return the first occurrence of one of the needle bytes in the given haystack. If no such occurrence exists, then None is returned.

The occurrence is reported as an offset into haystack. Its maximum value is haystack.len() - 1.

Source

pub fn rfind(&self, haystack: &[u8]) -> Option<usize>

Return the last occurrence of one of the needle bytes in the given haystack. If no such occurrence exists, then None is returned.

The occurrence is reported as an offset into haystack. Its maximum value is haystack.len() - 1.

Source

pub unsafe fn find_raw( &self, start: *const u8, end: *const u8, ) -> Option<*const u8>

Like find, but accepts and returns raw pointers.

When a match is found, the pointer returned is guaranteed to be >= start and < end.

This routine is useful if you’re already using raw pointers and would like to avoid converting back to a slice before executing a search.

§Safety
  • Both start and end must be valid for reads.
  • Both start and end must point to an initialized value.
  • Both start and end must point to the same allocated object and must either be in bounds or at most one byte past the end of the allocated object.
  • Both start and end must be derived from a pointer to the same object.
  • The distance between start and end must not overflow isize.
  • The distance being in bounds must not rely on “wrapping around” the address space.

Note that callers may pass a pair of pointers such that start >= end. In that case, None will always be returned.

Source

pub unsafe fn rfind_raw( &self, start: *const u8, end: *const u8, ) -> Option<*const u8>

Like rfind, but accepts and returns raw pointers.

When a match is found, the pointer returned is guaranteed to be >= start and < end.

This routine is useful if you’re already using raw pointers and would like to avoid converting back to a slice before executing a search.

§Safety
  • Both start and end must be valid for reads.
  • Both start and end must point to an initialized value.
  • Both start and end must point to the same allocated object and must either be in bounds or at most one byte past the end of the allocated object.
  • Both start and end must be derived from a pointer to the same object.
  • The distance between start and end must not overflow isize.
  • The distance being in bounds must not rely on “wrapping around” the address space.

Note that callers may pass a pair of pointers such that start >= end. In that case, None will always be returned.

Source

pub fn iter<'a, 'h>(&'a self, haystack: &'h [u8]) -> ThreeIter<'a, 'h>

Returns an iterator over all occurrences of the needle bytes in the given haystack.

The iterator returned implements DoubleEndedIterator. This means it can also be used to find occurrences in reverse order.

Trait Implementations§

Source§

impl Clone for Three

Source§

fn clone(&self) -> Three

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Three

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Copy for Three

Auto Trait Implementations§

§

impl Freeze for Three

§

impl RefUnwindSafe for Three

§

impl Send for Three

§

impl Sync for Three

§

impl Unpin for Three

§

impl UnwindSafe for Three

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 192 bytes