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?
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 }crates/competitive/src/math/formal_power_series/formal_power_series_impls.rs (line 418)
400 pub fn solve_sparse_differential2(
401 p: &Self,
402 q: &Self,
403 x: &Self,
404 alpha: T,
405 beta: T,
406 deg: usize,
407 ) -> Self {
408 if deg == 0 {
409 return Self::zero();
410 }
411 let collect_sparse = |p: &Self| -> Vec<(usize, T)> {
412 p.iter()
413 .enumerate()
414 .filter(|&(_, x)| !x.is_zero())
415 .map(|(i, x)| (i, x.clone()))
416 .collect()
417 };
418 assert!(q.coeff(0).is_one());
419 assert!(x.coeff(0).is_one());
420 let p = collect_sparse(p);
421 let q = collect_sparse(q);
422 let x = collect_sparse(x);
423 let diff = |p: &[(usize, T)]| -> Vec<(usize, T)> {
424 p.iter()
425 .filter(|&&(i, _)| i > 0)
426 .map(|&(i, ref x)| (i - 1, x.clone() * T::from(i)))
427 .collect()
428 };
429 let dp = diff(&p);
430 let dq = diff(&q);
431
432 let mf = T::memorized_factorial(deg);
433 let mut f = Self::zeros(deg);
434 let mut qf = Self::zeros(deg);
435 let mut dq_f = Self::zeros(deg);
436 let mut d_qf = Self::zeros(deg);
437 f[0] = T::one();
438 for i in 0..deg - 1 {
439 qf[i] = f.sparse_fold(q.iter().cloned(), i);
440 dq_f[i] = f.sparse_fold(dq.iter().cloned(), i);
441 let dp_qf_i = qf.sparse_fold(dp.iter().cloned(), i);
442 let p_dq_f_i = dq_f.sparse_fold(p.iter().cloned(), i);
443 let x_d_qf_i = d_qf.sparse_fold(
444 x.iter()
445 .map(|&(i, ref x)| (i, x.clone() - T::from((i == 0) as usize))),
446 i,
447 );
448 d_qf[i] = alpha.clone() * dp_qf_i + beta.clone() * p_dq_f_i - x_d_qf_i;
449
450 let mut f_ip1 = d_qf[i].clone();
451 for &(j, ref q) in q.iter().take_while(|&&(j, _)| j <= i) {
452 if j > 0 {
453 f_ip1 -= q.clone() * &f[i - (j - 1)] * T::from(i - (j - 1));
454 }
455 }
456 f[i + 1] = f_ip1 * T::memorized_inv(&mf, i + 1);
457 }
458 f
459 }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.