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;

    // Provided methods
    fn lcm(self, other: Self) -> Self { ... }
    fn extgcd(self, other: Self) -> ExtendedGcd<Self> { ... }
    fn modinv(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

Provided Methods§

Source

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

Source

fn extgcd(self, other: Self) -> ExtendedGcd<Self>

Examples found in repository?
crates/competitive/src/num/integer.rs (line 119)
113    fn modinv(self, modulo: Self) -> Self {
114        assert!(
115            !self.is_zero(),
116            "attempt to inverse zero with modulo {}",
117            modulo
118        );
119        let extgcd = self.extgcd(modulo);
120        assert!(
121            extgcd.g.is_one(),
122            "there is no inverse {} modulo {}",
123            self,
124            modulo
125        );
126        extgcd.x.rem_euclid(modulo.signed()).unsigned()
127    }
Source

fn modinv(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 * a.modinv(m) % m, m))
16}

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§

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§

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§

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§

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§

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

Implementors§