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§
Provided Methods§
Sourcefn is_one(&self) -> boolwhere
Self: PartialEq,
fn is_one(&self) -> boolwhere
Self: PartialEq,
Examples found in repository?
crates/competitive/src/num/integer.rs (line 98)
90 fn mod_inv(self, modulo: Self) -> Self {
91 assert!(
92 !self.is_zero(),
93 "attempt to inverse zero with modulo {}",
94 modulo
95 );
96 let extgcd = self.signed().extgcd(modulo.signed());
97 assert!(
98 extgcd.g.is_one(),
99 "there is no inverse {} modulo {}",
100 self,
101 modulo
102 );
103 extgcd.x.rem_euclid(modulo.signed()).unsigned()
104 }
More 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 60)
41 fn determinant_linear_non_singular(mut self, mut other: Self) -> Option<Vec<MInt<M>>>
42 where
43 M: MIntBase,
44 {
45 let n = self.data.len();
46 let mut f = MInt::one();
47 for d in 0..n {
48 let i = other.data.iter().position(|other| !other[d].is_zero())?;
49 if i != d {
50 self.data.swap(i, d);
51 other.data.swap(i, d);
52 f = -f;
53 }
54 f *= other[d][d];
55 let r = other[d][d].inv();
56 for j in 0..n {
57 self[d][j] *= r;
58 other[d][j] *= r;
59 }
60 assert!(other[d][d].is_one());
61 for i in d + 1..n {
62 let a = other[i][d];
63 for k in 0..n {
64 self[i][k] = self[i][k] - a * self[d][k];
65 other[i][k] = other[i][k] - a * other[d][k];
66 }
67 }
68 for j in d + 1..n {
69 let a = other[d][j];
70 for k in 0..n {
71 self[k][j] = self[k][j] - a * self[k][d];
72 other[k][j] = other[k][j] - a * other[k][d];
73 }
74 }
75 }
76 for s in self.data.iter_mut() {
77 for s in s.iter_mut() {
78 *s = -*s;
79 }
80 }
81 let mut p = self.characteristic_polynomial();
82 for p in p.iter_mut() {
83 *p *= f;
84 }
85 Some(p)
86 }
fn set_one(&mut 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.