QuotientMap

Trait QuotientMap 

Source
pub trait QuotientMap<Int>: Sized {
    // Required methods
    fn from_int(int: Int) -> Self;
    fn from_canonical_checked(int: Int) -> Option<Self>;
    unsafe fn from_canonical_unchecked(int: Int) -> Self;
}
Expand description

Implementation of the quotient map ℤ -> ℤ/p which sends an integer r to its conjugacy class [r].

This is the key trait allowing us to convert integers into field elements. Each prime field should implement this for all primitive integer types.

Required Methods§

Source

fn from_int(int: Int) -> Self

Convert a given integer into an element of the field ℤ/p.

This is the most generic method which makes no assumptions on the size of the input. Where possible, this method should be used with the smallest possible integer type. For example, if a 32-bit integer x is known to be less than 2^16, then from_int(x as u16) will often be faster than from_int(x).

This method is also strongly preferred over from_canonical_checked/from_canonical_unchecked. It will usually be identical when Int is a small type, e.g. u8/u16 and is safer for larger types.

Source

fn from_canonical_checked(int: Int) -> Option<Self>

Convert a given integer into an element of the field ℤ/p. The input is checked to ensure it lies within a given range.

  • If Int is an unsigned integer type the input must lie in [0, p - 1].
  • If Int is a signed integer type the input must lie in [-(p - 1)/2, (p - 1)/2].

Return None if the input lies outside this range and Some(val) otherwise.

Source

unsafe fn from_canonical_unchecked(int: Int) -> Self

Convert a given integer into an element of the field ℤ/p. The input is guaranteed to lie within a specific range depending on p. If the input lies outside of this range, the output is undefined.

In general from_canonical_unchecked will be faster for either signed or unsigned types but the specifics will depend on the field.

§Safety
  • If Int is an unsigned integer type then the allowed range will include [0, p - 1].
  • If Int is a signed integer type then the allowed range will include [-(p - 1)/2, (p - 1)/2].

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§