Module memchr::arch::all::memchr

source ·
Expand description

Provides architecture independent implementations of memchr and friends.

The main types in this module are One, Two and Three. They are for searching for one, two or three distinct bytes, respectively, in a haystack. Each type also has corresponding double ended iterators. These searchers are typically slower than hand-coded vector routines accomplishing the same task, but are also typically faster than naive scalar code. These routines effectively work by treating a usize as a vector of 8-bit lanes, and thus achieves some level of data parallelism even without explicit vector support.

The One searcher also provides a One::count routine for efficiently counting the number of times a single byte occurs in a haystack. This is useful, for example, for counting the number of lines in a haystack. This routine exists because it is usually faster, especially with a high match count, then using One::find repeatedly. (OneIter specializes its Iterator::count implementation to use this routine.)

Only one, two and three bytes are supported because three bytes is about the point where one sees diminishing returns. Beyond this point and it’s probably (but not necessarily) better to just use a simple [bool; 256] array or similar. However, it depends mightily on the specific work-load and the expected match frequency.

Structs

  • Finds all occurrences of a single byte in a haystack.
  • An iterator over all occurrences of a single byte in a haystack.
  • Finds all occurrences of three bytes in a haystack.
  • An iterator over all occurrences of three possible bytes in a haystack.
  • Finds all occurrences of two bytes in a haystack.
  • An iterator over all occurrences of two possible bytes in a haystack.