Table2dU8xU8

Struct Table2dU8xU8 

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

A 2D SIMD lookup table for u8 × u8 coordinates, supporting up to 64K entries.

This table stores data in row-major order and uses SIMD gather operations for efficient parallel lookups. Each lookup takes a row index (0..num_rows) and column index (0..num_cols), both as u8, and returns the corresponding value.

§Index Calculation

For row r and column c, the flat index is: index = r * num_cols + c

Since row and column are both u8 (max 255), and num_cols is at most 256, the maximum index is 255 * 256 + 255 = 65535, which fits in u16.

§Example

// Create a 16x16 multiplication table
let mut data = vec![0u8; 256];
for r in 0..16u8 {
    for c in 0..16u8 {
        data[(r as usize) * 16 + (c as usize)] = r.wrapping_mul(c);
    }
}
let table = Table2dU8xU8::from_flat(&data, 16);

// Look up multiple (row, col) pairs in parallel
let rows = u8x16::from([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]);
let cols = u8x16::splat(5);  // All looking up column 5
let result = table.lookup_one(rows, cols);
// result[i] = i * 5

Implementations§

Source§

impl Table2dU8xU8

Source

pub fn from_flat(data: &[u8], num_cols: usize) -> Self

Create a 2D table from a flat slice with the given number of columns.

The data is stored in row-major order: data[row * num_cols + col].

§Arguments
  • data: Flat slice of values, length must be num_rows * num_cols
  • num_cols: Number of columns per row (1..=256)
§Panics
  • Panics if num_cols is 0 or greater than 256
  • Panics if data.len() is not a multiple of num_cols
  • Panics if data.len() > 65536
Source

pub fn from_2d(matrix: &[&[u8]]) -> Self

Create a 2D table from a 2D matrix (Vec of rows).

All rows must have the same length.

§Panics
  • Panics if the matrix is empty
  • Panics if rows have different lengths
  • Panics if total size exceeds 65536
Source

pub fn num_cols(&self) -> usize

Returns the number of columns per row.

Source

pub fn num_rows(&self) -> usize

Returns the number of rows in the table.

Source

pub fn len(&self) -> usize

Returns the total number of entries in the table.

Source

pub fn is_empty(&self) -> bool

Returns true if the table is empty.

Source

pub fn lookup_one(&self, rows: u8x16, cols: u8x16) -> u8x16

Look up 16 values in parallel using (row, col) coordinates.

Computes result[i] = table[rows[i]][cols[i]] for all 16 lanes.

§Arguments
  • rows: Row indices (0..num_rows) for each of the 16 lanes
  • cols: Column indices (0..num_cols) for each of the 16 lanes
§Safety

In debug mode, asserts that all indices are in bounds. In release mode, out-of-bounds access is undefined behavior.

Source

pub fn get(&self, row: u8, col: u8) -> u8

Scalar lookup for a single (row, col) coordinate.

§Panics

Panics if row or col is out of bounds.

Trait Implementations§

Source§

impl Clone for Table2dU8xU8

Source§

fn clone(&self) -> Table2dU8xU8

Returns a duplicate of the value. Read more
1.0.0§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Table2dU8xU8

Source§

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

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

impl Default for Table2dU8xU8

Source§

fn default() -> Table2dU8xU8

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

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

§

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

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

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

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

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

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

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.