lib-misc-utils · crate

kinogaki-bytes

Libraryenvironment

Fast search for one byte value in a byte slice, in safe code: find, rfind and count.

Repository
lib-misc-utils (kinogaki/lib-misc-utils)
Folder
libs/lib-misc-utils/crates/bytes
Source
1 file, 92 lines
Tests
1 file, 77 lines
depends onused by tests alonedependencies for tests alone are listed below, not drawn

What it is

Fast search for one byte value in a byte slice, in safe code: find, rfind and count.

The slice is read eight bytes at a time as a u64 ("SWAR"). For a word w and the needle repeated in every byte, x = w ^ needle has a zero byte exactly where w holds the needle, and !(((x & 0x7f..7f) + 0x7f..7f) | x) & 0x80..80 sets the top bit of exactly those bytes (no carry crosses a byte, unlike the shorter (x - 0x01..01) & !x test). The lowest or highest such bit gives the first or last match; the bit count gives the number of matches. Blocks of four words are tested together before one is looked at.

Depends on

None.

Third-party

None.

Used by

CrateRepositoryAsWhat it is
kinogaki-objOBJnormalWavefront OBJ, a format plugin: an OBJ file reads as one standard Geometry, its material libraries (mtllib) as MaterialX networks (materials) in a materials item before it; any polygons and polylines write as ...

Modules

One file: the crate root.

Public types and traits

Besides these, 3 public functions at module level.