Unsigned

Trait Unsigned 

Source
pub trait Unsigned: IntBase {
    type Signed: Signed<Unsigned = Self>;

    // Required methods
    fn signed(self) -> Self::Signed;
    fn abs_diff(self, other: Self) -> Self;
    fn next_power_of_two(self) -> Self;
    fn gcd(self, other: Self) -> Self;
    fn mod_add(self, rhs: Self, modulo: Self) -> Self;
    fn mod_sub(self, rhs: Self, modulo: Self) -> Self;
    fn mod_mul(self, rhs: Self, modulo: Self) -> Self;

    // Provided methods
    fn lcm(self, other: Self) -> Self { ... }
    fn mod_inv(self, modulo: Self) -> Self { ... }
    fn mod_neg(self, modulo: Self) -> Self { ... }
}
Expand description

Trait for unsigned integer operations.

Required Associated Types§

Source

type Signed: Signed<Unsigned = Self>

Required Methods§

Source

fn signed(self) -> Self::Signed

Source

fn abs_diff(self, other: Self) -> Self

Source

fn next_power_of_two(self) -> Self

Source

fn gcd(self, other: Self) -> Self

Source

fn mod_add(self, rhs: Self, modulo: Self) -> Self

Source

fn mod_sub(self, rhs: Self, modulo: Self) -> Self

Source

fn mod_mul(self, rhs: Self, modulo: Self) -> Self

Provided Methods§

Source

fn lcm(self, other: Self) -> Self

Source

fn mod_inv(self, modulo: Self) -> Self

Examples found in repository?
crates/competitive/src/math/linear_congruence.rs (line 15)
6pub fn solve_linear_congruence<T>(a: T, b: T, m: T) -> Option<(T, T)>
7where
8    T: Unsigned,
9{
10    let g = a.gcd(m);
11    if b % g != T::zero() {
12        return None;
13    }
14    let (a, b, m) = (a / g, b / g, m / g);
15    Some((b.mod_mul(a.mod_inv(m), m), m))
16}
More examples
Hide additional examples
crates/competitive/src/math/garner.rs (line 52)
39    pub fn new_unchecked<M>(moduli: M, modulo: T) -> Self
40    where
41        M: IntoIterator<Item = T>,
42    {
43        let mut moduli: Vec<_> = moduli.into_iter().collect();
44        let n = moduli.len();
45        moduli.push(modulo);
46        let coeff_len = n * (n + 1) / 2;
47        let mut coeff = Vec::with_capacity(coeff_len);
48        let mut inv = Vec::with_capacity(n);
49        let mut prefix = vec![T::one(); moduli.len()];
50        for i in 0..n {
51            let modulus = moduli[i];
52            inv.push(prefix[i].mod_inv(modulus));
53            for j in i + 1..=n {
54                coeff.push(prefix[j]);
55                prefix[j] = prefix[j].mod_mul(modulus, moduli[j]);
56            }
57        }
58        Self { moduli, coeff, inv }
59    }
Source

fn mod_neg(self, modulo: Self) -> Self

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.

Implementations on Foreign Types§

Source§

impl Unsigned for u8

Source§

type Signed = i8

Source§

fn signed(self) -> Self::Signed

Source§

fn abs_diff(self, other: Self) -> Self

Source§

fn next_power_of_two(self) -> Self

Source§

fn gcd(self, other: Self) -> Self

Source§

fn mod_add(self, rhs: Self, modulo: Self) -> Self

Source§

fn mod_sub(self, rhs: Self, modulo: Self) -> Self

Source§

fn mod_mul(self, rhs: Self, modulo: Self) -> Self

Source§

impl Unsigned for u16

Source§

type Signed = i16

Source§

fn signed(self) -> Self::Signed

Source§

fn abs_diff(self, other: Self) -> Self

Source§

fn next_power_of_two(self) -> Self

Source§

fn gcd(self, other: Self) -> Self

Source§

fn mod_add(self, rhs: Self, modulo: Self) -> Self

Source§

fn mod_sub(self, rhs: Self, modulo: Self) -> Self

Source§

fn mod_mul(self, rhs: Self, modulo: Self) -> Self

Source§

impl Unsigned for u32

Source§

type Signed = i32

Source§

fn signed(self) -> Self::Signed

Source§

fn abs_diff(self, other: Self) -> Self

Source§

fn next_power_of_two(self) -> Self

Source§

fn gcd(self, other: Self) -> Self

Source§

fn mod_add(self, rhs: Self, modulo: Self) -> Self

Source§

fn mod_sub(self, rhs: Self, modulo: Self) -> Self

Source§

fn mod_mul(self, rhs: Self, modulo: Self) -> Self

Source§

impl Unsigned for u64

Source§

type Signed = i64

Source§

fn signed(self) -> Self::Signed

Source§

fn abs_diff(self, other: Self) -> Self

Source§

fn next_power_of_two(self) -> Self

Source§

fn gcd(self, other: Self) -> Self

Source§

fn mod_add(self, rhs: Self, modulo: Self) -> Self

Source§

fn mod_sub(self, rhs: Self, modulo: Self) -> Self

Source§

fn mod_mul(self, rhs: Self, modulo: Self) -> Self

Source§

impl Unsigned for u128

Source§

type Signed = i128

Source§

fn signed(self) -> Self::Signed

Source§

fn abs_diff(self, other: Self) -> Self

Source§

fn next_power_of_two(self) -> Self

Source§

fn gcd(self, other: Self) -> Self

Source§

fn mod_add(self, rhs: Self, modulo: Self) -> Self

Source§

fn mod_sub(self, rhs: Self, modulo: Self) -> Self

Source§

fn mod_mul(self, rhs: Self, modulo: Self) -> Self

Source§

impl Unsigned for usize

Source§

type Signed = isize

Source§

fn signed(self) -> Self::Signed

Source§

fn abs_diff(self, other: Self) -> Self

Source§

fn next_power_of_two(self) -> Self

Source§

fn gcd(self, other: Self) -> Self

Source§

fn mod_add(self, rhs: Self, modulo: Self) -> Self

Source§

fn mod_sub(self, rhs: Self, modulo: Self) -> Self

Source§

fn mod_mul(self, rhs: Self, modulo: Self) -> Self

Implementors§