pub trait PackedFe32: Copy + PartialEq + Eq + BitXor<Self, Output = Self> {
    const ONE: Self;
    const WIDTH: usize = _;

    // Required methods
    fn unpack(&self, n: usize) -> u8;
    fn mul_by_x_then_add(&mut self, degree: usize, add: u8) -> u8;
}
Expand description

Trait describing an integer type which can be used as a “packed” sequence of Fe32s.

This is implemented for u32, u64 and u128, as a way to treat these primitive types as packed coefficients of polynomials over GF32 (up to some maximal degree, of course).

This is useful because then multiplication by x reduces to simply left-shifting by 5, and addition of entire polynomials can be done by xor.

Required Associated Constants§

source

const ONE: Self

The one constant, for which stdlib provides no existing trait.

Provided Associated Constants§

source

const WIDTH: usize = _

The number of fe32s that can fit into the type; computed as floor(bitwidth / 5).

Required Methods§

source

fn unpack(&self, n: usize) -> u8

Extracts the coefficient of the x^n from the packed polynomial.

source

fn mul_by_x_then_add(&mut self, degree: usize, add: u8) -> u8

Multiply the polynomial by x, drop its highest coefficient (and return it), and add a new field element to the now-0 constant coefficient.

Takes the degree of the polynomial as an input; for checksum applications this should basically always be Checksum::CHECKSUM_WIDTH.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl PackedFe32 for u32

source§

const ONE: Self = 1u32

source§

fn unpack(&self, n: usize) -> u8

source§

fn mul_by_x_then_add(&mut self, degree: usize, add: u8) -> u8

source§

impl PackedFe32 for u64

source§

const ONE: Self = 1u64

source§

fn unpack(&self, n: usize) -> u8

source§

fn mul_by_x_then_add(&mut self, degree: usize, add: u8) -> u8

source§

impl PackedFe32 for u128

source§

const ONE: Self = 1u128

source§

fn unpack(&self, n: usize) -> u8

source§

fn mul_by_x_then_add(&mut self, degree: usize, add: u8) -> u8

Implementors§

source§

impl PackedFe32 for PackedNull

source§

const ONE: Self = PackedNull