Skip to main content

One

Trait One 

Source
pub trait One: Sized {
    // Required method
    fn one() -> Self;

    // Provided methods
    fn is_one(&self) -> bool
       where Self: PartialEq { ... }
    fn set_one(&mut self) { ... }
}

Required Methods§

Source

fn one() -> Self

Provided Methods§

Source

fn is_one(&self) -> bool
where Self: PartialEq,

Examples found in repository?
crates/competitive/src/num/integer.rs (line 101)
98    fn mod_inv(self, modulo: Self) -> Self {
99        debug_assert!(!modulo.is_zero(), "modulo must be non-zero");
100        let extgcd = self.signed().extgcd(modulo.signed());
101        debug_assert!(extgcd.g.is_one(), "not coprime");
102        extgcd.x.rem_euclid(modulo.signed()).unsigned()
103    }
More examples
Hide additional examples
crates/competitive/src/algorithm/stern_brocot_tree.rs (line 81)
71    fn from(r: URational<T>) -> Self {
72        assert!(!r.num.is_zero(), "rational must be positive");
73        assert!(!r.den.is_zero(), "rational must be positive");
74
75        let (mut a, mut b) = (r.num, r.den);
76        let mut path = vec![];
77        loop {
78            let x = a / b;
79            a %= b;
80            if a.is_zero() {
81                if !x.is_one() {
82                    path.push(x - T::one());
83                }
84                break;
85            }
86            path.push(x);
87            swap(&mut a, &mut b);
88        }
89        Self { path }
90    }
crates/competitive/src/math/mint_matrix.rs (line 103)
84    fn determinant_linear_non_singular(mut self, mut other: Self) -> Option<Vec<MInt<M>>>
85    where
86        M: MIntDotProduct,
87    {
88        let n = self.data.len();
89        let mut f = MInt::one();
90        for d in 0..n {
91            let i = other.data.iter().position(|other| !other[d].is_zero())?;
92            if i != d {
93                self.data.swap(i, d);
94                other.data.swap(i, d);
95                f = -f;
96            }
97            f *= other[d][d];
98            let r = other[d][d].inv();
99            for j in 0..n {
100                self[d][j] *= r;
101                other[d][j] *= r;
102            }
103            assert!(other[d][d].is_one());
104            for i in d + 1..n {
105                let a = other[i][d];
106                for k in 0..n {
107                    self[i][k] = self[i][k] - a * self[d][k];
108                    other[i][k] = other[i][k] - a * other[d][k];
109                }
110            }
111            for j in d + 1..n {
112                let a = other[d][j];
113                for k in 0..n {
114                    self[k][j] = self[k][j] - a * self[k][d];
115                    other[k][j] = other[k][j] - a * other[k][d];
116                }
117            }
118        }
119        for s in self.data.iter_mut() {
120            for s in s.iter_mut() {
121                *s = -*s;
122            }
123        }
124        let mut p = self.characteristic_polynomial();
125        for p in p.iter_mut() {
126            *p *= f;
127        }
128        Some(p)
129    }
crates/competitive/src/math/formal_power_series/formal_power_series_impls.rs (line 749)
731    pub fn solve_sparse_differential2(
732        p: &Self,
733        q: &Self,
734        x: &Self,
735        alpha: T,
736        beta: T,
737        deg: usize,
738    ) -> Self {
739        if deg == 0 {
740            return Self::zero();
741        }
742        let collect_sparse = |p: &Self| -> Vec<(usize, T)> {
743            p.iter()
744                .enumerate()
745                .filter(|&(_, x)| !x.is_zero())
746                .map(|(i, x)| (i, x.clone()))
747                .collect()
748        };
749        assert!(q.coeff(0).is_one());
750        assert!(x.coeff(0).is_one());
751        let p = collect_sparse(p);
752        let q = collect_sparse(q);
753        let x = collect_sparse(x);
754        let diff = |p: &[(usize, T)]| -> Vec<(usize, T)> {
755            p.iter()
756                .filter(|&&(i, _)| i > 0)
757                .map(|&(i, ref x)| (i - 1, x.clone() * T::from(i)))
758                .collect()
759        };
760        let dp = diff(&p);
761        let dq = diff(&q);
762
763        let mf = T::memorized_factorial(deg);
764        let mut f = Self::zeros(deg);
765        let mut qf = Self::zeros(deg);
766        let mut dq_f = Self::zeros(deg);
767        let mut d_qf = Self::zeros(deg);
768        f[0] = T::one();
769        for i in 0..deg - 1 {
770            qf[i] = f.sparse_fold(q.iter().cloned(), i);
771            dq_f[i] = f.sparse_fold(dq.iter().cloned(), i);
772            let dp_qf_i = qf.sparse_fold(dp.iter().cloned(), i);
773            let p_dq_f_i = dq_f.sparse_fold(p.iter().cloned(), i);
774            let x_d_qf_i = d_qf.sparse_fold(
775                x.iter()
776                    .map(|&(i, ref x)| (i, x.clone() - T::from((i == 0) as usize))),
777                i,
778            );
779            d_qf[i] = alpha.clone() * dp_qf_i + beta.clone() * p_dq_f_i - x_d_qf_i;
780
781            let mut f_ip1 = d_qf[i].clone();
782            for &(j, ref q) in q.iter().take_while(|&&(j, _)| j <= i) {
783                if j > 0 {
784                    f_ip1 -= q.clone() * &f[i - (j - 1)] * T::from(i - (j - 1));
785                }
786            }
787            f[i + 1] = f_ip1 * T::memorized_inv(&mf, i + 1);
788        }
789        f
790    }
Source

fn set_one(&mut self)

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl One for f32

Source§

fn one() -> Self

Source§

impl One for f64

Source§

fn one() -> Self

Source§

impl One for i8

Source§

fn one() -> Self

Source§

impl One for i16

Source§

fn one() -> Self

Source§

impl One for i32

Source§

fn one() -> Self

Source§

impl One for i64

Source§

fn one() -> Self

Source§

impl One for i128

Source§

fn one() -> Self

Source§

impl One for isize

Source§

fn one() -> Self

Source§

impl One for u8

Source§

fn one() -> Self

Source§

impl One for u16

Source§

fn one() -> Self

Source§

impl One for u32

Source§

fn one() -> Self

Source§

impl One for u64

Source§

fn one() -> Self

Source§

impl One for u128

Source§

fn one() -> Self

Source§

impl One for usize

Source§

fn one() -> Self

Source§

impl<T: One> One for Wrapping<T>

Source§

fn one() -> Self

Implementors§

Source§

impl One for Decimal

Source§

impl One for DoubleDouble

Source§

impl One for Float32

Source§

impl One for Float64

Source§

impl One for QuadDouble

Source§

impl<M> One for MInt<M>
where M: MIntBase,

Source§

impl<T, C> One for FormalPowerSeries<T, C>
where T: PartialEq + One,

Source§

impl<T: Zero + One> One for Polynomial<T>

Source§

impl<T> One for Complex<T>
where T: Zero + One,

Source§

impl<T> One for DualNumber<T>
where T: Zero + One,

Source§

impl<T> One for Rational<T>
where T: Signed,

Source§

impl<T> One for Saturating<T>
where T: One,

Source§

impl<T> One for URational<T>
where T: Unsigned,

Source§

impl<T> One for competitive::num::Wrapping<T>
where T: One,