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§
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
Sourcefn mod_inv(self, modulo: Self) -> Self
fn mod_inv(self, modulo: Self) -> Self
Examples found in repository?
More 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 }
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.