[][src]Trait qr_code::decode::g2p::GaloisField

pub trait GaloisField: Add<Output = Self> + AddAssign + Sub<Output = Self> + SubAssign + Mul<Output = Self> + MulAssign + Div<Output = Self> + DivAssign + Copy + PartialEq + Eq {
    const SIZE: usize;
    const ZERO: Self;
    const ONE: Self;
    const GENERATOR: Self;
    const MODULUS: G2Poly;
    fn pow(self, p: usize) -> Self { ... }
}

Common trait for finite fields

All types generated by g2p! implement this trait. The trait ensures that all the expected operations of a finite field are implemented.

In addition, some often used constants like ONE and ZERO are exported, as well as the more esoteric GENERATOR.

Associated Constants

const SIZE: usize

Number of elements in the field

const ZERO: Self

The value 0 as a finite field constant

const ONE: Self

The value 1 as a finite field constant

const GENERATOR: Self

A generator of the multiplicative group of a finite field The powers of this element will generate all non-zero elements of the finite field

use qr_code::decode::g2p::{self, GaloisField};
use qr_code::decode::gf16::GF16;

let mut g = GF16::GENERATOR;
let mut set = std::collections::HashSet::new();
for _ in 0..15 {
    g *= GF16::GENERATOR;
    set.insert(g);
}
assert_eq!(set.len(), 15);

const MODULUS: G2Poly

Polynomial representation of the modulus used to generate the field

Loading content...

Provided methods

fn pow(self, p: usize) -> Self

Calculate the p-th power of a value

Calculate the value of x to the power p in finite field arithmethic

Example

use qr_code::decode::g2p::{self, GaloisField};
use qr_code::decode::gf16::GF16;

let g: GF16 = 2.into();
assert_eq!(g.pow(0), GF16::ONE);
assert_eq!(g.pow(1), g);
assert_eq!(g.pow(2), 4.into());
assert_eq!(g.pow(3), 8.into());
assert_eq!(g.pow(4), 3.into());
Loading content...

Implementors

impl GaloisField for GF16[src]

Loading content...