diff --git a/.github/actions/setup-rust/action.yml b/.github/actions/setup-rust/action.yml index 67b52235..a364a991 100644 --- a/.github/actions/setup-rust/action.yml +++ b/.github/actions/setup-rust/action.yml @@ -7,7 +7,7 @@ runs: - name: Rust Toolchain uses: dtolnay/rust-toolchain@stable with: - toolchain: "1.70.0" + toolchain: "1.82.0" - uses: taiki-e/install-action@nextest diff --git a/libs/accum/src/lib.rs b/libs/accum/src/lib.rs index 02512e22..8b542b25 100644 --- a/libs/accum/src/lib.rs +++ b/libs/accum/src/lib.rs @@ -229,13 +229,13 @@ mod tests { #[test] fn test_skipped_min() { let a = vec![4, 2, 6, 1]; - let skipped = skipped_min(&a, std::i32::MAX); + let skipped = skipped_min(&a, i32::MAX); assert_eq!(skipped, vec![1, 1, 1, 2]); } #[test] fn test_skipped_max() { let a = vec![4, 2, 6, 1]; - let skipped = skipped_max(&a, std::i32::MIN); + let skipped = skipped_max(&a, i32::MIN); assert_eq!(skipped, vec![6, 6, 4, 6]); } } diff --git a/libs/bfs/src/lib.rs b/libs/bfs/src/lib.rs index c945531e..6a60c7bc 100644 --- a/libs/bfs/src/lib.rs +++ b/libs/bfs/src/lib.rs @@ -33,12 +33,12 @@ pub fn tree_diamter_restore(g: &[Vec]) -> (Vec, u32) { /// 一点からの距離配列を作ります。 pub fn calc_dist(start: usize, g: &[Vec]) -> Vec { - let mut dist = vec![std::u32::MAX; g.len()]; + let mut dist = vec![u32::MAX; g.len()]; dist[start] = 0; let mut queue = VecDeque::from(vec![start]); while let Some(x) = queue.pop_front() { for &y in &g[x] { - if dist[y] == std::u32::MAX { + if dist[y] == u32::MAX { dist[y] = dist[x] + 1; queue.push_back(y); } @@ -49,14 +49,14 @@ pub fn calc_dist(start: usize, g: &[Vec]) -> Vec { /// 一点からの距離配列と、前者配列を作ります。始点の前者は自分自身です。 pub fn calc_dist_restore(start: usize, g: &[Vec]) -> (Vec, Vec) { - let mut dist = vec![std::u32::MAX; g.len()]; - let mut prv = vec![std::usize::MAX; g.len()]; + let mut dist = vec![u32::MAX; g.len()]; + let mut prv = vec![usize::MAX; g.len()]; dist[start] = 0; prv[start] = start; let mut queue = VecDeque::from(vec![start]); while let Some(x) = queue.pop_front() { for &y in &g[x] { - if dist[y] == std::u32::MAX { + if dist[y] == u32::MAX { dist[y] = dist[x] + 1; prv[y] = x; queue.push_back(y); @@ -69,7 +69,7 @@ pub fn calc_dist_restore(start: usize, g: &[Vec]) -> (Vec, Vec]) -> Option> { let (dist, prv) = calc_dist_restore(start, g); - if dist[end] == std::u32::MAX { + if dist[end] == u32::MAX { None } else { let mut res = vec![end]; @@ -124,7 +124,7 @@ mod tests { if let Some(path) = path { validate_path(&dist, &path, start, end); } else { - assert_eq!(dist[end], std::u32::MAX); + assert_eq!(dist[end], u32::MAX); } } } @@ -143,7 +143,7 @@ mod tests { fn validate_prv(dist: &[u32], prv: &[usize], start: usize) { assert_eq!(prv[start], start); (0..dist.len()) - .filter(|&i| i != start && prv[i] != std::usize::MAX) + .filter(|&i| i != start && prv[i] != usize::MAX) .for_each(|i| assert_eq!(dist[prv[i]] + 1, dist[i])) } @@ -185,7 +185,7 @@ mod tests { fn brute_tree_diameter(g: &[Vec]) -> ([usize; 2], u32) { let n = g.len(); - let mut dist = vec![vec![std::u32::MAX; n]; n]; + let mut dist = vec![vec![u32::MAX; n]; n]; (0..n).for_each(|i| dist[i][i] = 0); g.iter() .enumerate() @@ -202,7 +202,7 @@ mod tests { } } } - assert!(dist.iter().flatten().all(|&x| x != std::u32::MAX)); + assert!(dist.iter().flatten().all(|&x| x != u32::MAX)); dist.iter() .enumerate() .flat_map(|(i, v)| v.iter().copied().enumerate().map(move |(j, x)| (i, j, x))) diff --git a/libs/bfs01/src/lib.rs b/libs/bfs01/src/lib.rs index 1613e08c..8e708bed 100644 --- a/libs/bfs01/src/lib.rs +++ b/libs/bfs01/src/lib.rs @@ -8,7 +8,7 @@ pub enum Weight { /// 一点からの距離配列を作ります。 pub fn calc_dist(s: usize, g: &[Vec<(usize, Weight)>]) -> Vec { - let mut dist = vec![std::u32::MAX; g.len()]; + let mut dist = vec![u32::MAX; g.len()]; dist[s] = 0; let mut queue = VecDeque::from(vec![s]); while let Some(x) = queue.pop_front() { @@ -32,8 +32,8 @@ pub fn calc_dist(s: usize, g: &[Vec<(usize, Weight)>]) -> Vec { /// 一点からの距離配列と、前者配列を作ります。始点の前者は自分自身です。 pub fn calc_dist_restore(s: usize, g: &[Vec<(usize, Weight)>]) -> (Vec, Vec) { - let mut dist = vec![std::u32::MAX; g.len()]; - let mut prv = vec![std::usize::MAX; g.len()]; + let mut dist = vec![u32::MAX; g.len()]; + let mut prv = vec![usize::MAX; g.len()]; prv[s] = s; dist[s] = 0; let mut queue = VecDeque::from(vec![s]); @@ -124,8 +124,8 @@ mod tests { fn validate_dist_prv(dist: &[u32], prv: &[usize], s: usize) { assert_eq!(prv[s], s); prv.iter().copied().enumerate().for_each(|(x, p)| { - if p == std::usize::MAX { - assert_eq!(dist[x], std::u32::MAX); + if p == usize::MAX { + assert_eq!(dist[x], u32::MAX); } else { assert!(dist[p] == dist[x] || dist[p] + 1 == dist[x]) } diff --git a/libs/bitvec/src/lib.rs b/libs/bitvec/src/lib.rs index 458eb95d..a0903978 100644 --- a/libs/bitvec/src/lib.rs +++ b/libs/bitvec/src/lib.rs @@ -270,12 +270,12 @@ impl<'a> IntoIterator for &'a BitVec { } impl Debug for BitVec { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", self.to_string()) + write!(f, "{}", self) } } -impl ToString for BitVec { - fn to_string(&self) -> String { - self.format('1', '0') +impl std::fmt::Display for BitVec { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.format('1', '0')) } } diff --git a/libs/bsgs/src/lib.rs b/libs/bsgs/src/lib.rs index 36086e3f..c03d472d 100644 --- a/libs/bsgs/src/lib.rs +++ b/libs/bsgs/src/lib.rs @@ -36,7 +36,7 @@ //! * ちなみに位数の上界は、探索の打ち切りに用いています。 //! * 群の演算は、モジュラス等が動的に与えられる可能性を考えて、型ではなくオブジェクトにしました。 //! * たいてい ℤ / n ℤ -//! の乗法群にしか使わない気がするのですが、それようのユーティルがうまく作れず…… +//! の乗法群にしか使わない気がするのですが、それようのユーティルがうまく作れず…… use std::collections::HashMap; use std::fmt::Debug; use std::fmt::Formatter; @@ -124,6 +124,7 @@ where } } +#[allow(clippy::missing_fields_in_debug)] impl Debug for Bsgs { fn fmt(&self, f: &mut Formatter<'_>) -> Result { f.debug_struct("Bsgs") diff --git a/libs/cht/src/lib.rs b/libs/cht/src/lib.rs index 249cac1b..0d5fb384 100644 --- a/libs/cht/src/lib.rs +++ b/libs/cht/src/lib.rs @@ -56,8 +56,6 @@ use std::borrow::Borrow; use std::collections::BTreeSet; use std::fmt::Debug; -use std::i64::MAX; -use std::i64::MIN; use std::marker::PhantomData; use std::ops::Add; use std::ops::Mul; @@ -151,7 +149,7 @@ impl VecCht { while let Some(seg) = self.vec.pop() { let Min(x) = seg.min; - if x == MIN || line.eval(x) < seg.line.eval(x) { + if x == i64::MIN || line.eval(x) < seg.line.eval(x) { self.vec.push(seg); break; } @@ -170,11 +168,11 @@ impl VecCht { } } } - let min = Min(self.vec.last().map_or(MIN, |seg| seg.max.0)); + let min = Min(self.vec.last().map_or(i64::MIN, |seg| seg.max.0)); self.vec.push(Segment { line, min, - max: Max(MAX), + max: Max(i64::MAX), }); } } @@ -221,8 +219,8 @@ impl BTreeCht { let line = Line { p, q }; if let Some(seg) = self.set.range(p..).next() { let Min(x) = seg.min; - if x == MIN && seg.line.p == p && seg.line.q <= q - || x != MIN && line.eval(x) <= seg.line.eval(x) + if x == i64::MIN && seg.line.p == p && seg.line.q <= q + || x != i64::MIN && line.eval(x) <= seg.line.eval(x) { return; } @@ -232,14 +230,14 @@ impl BTreeCht { while let Some(&seg) = self.set.range(..p).next_back() { let Min(x) = seg.min; - if x == MIN || line.eval(x) < seg.line.eval(x) { + if x == i64::MIN || line.eval(x) < seg.line.eval(x) { break; } self.set.remove(&seg); } while let Some(&seg) = self.set.range(p..).next() { let Max(x) = seg.max; - if x == MAX || line.eval(x) < seg.line.eval(x) { + if x == i64::MAX || line.eval(x) < seg.line.eval(x) { break; } self.set.remove(&seg); @@ -274,8 +272,12 @@ impl BTreeCht { } }; } - let min = Min(self.set.range(..p).next_back().map_or(MIN, |seg| seg.max.0)); - let max = Max(self.set.range(p..).next().map_or(MAX, |seg| seg.min.0)); + let min = Min(self + .set + .range(..p) + .next_back() + .map_or(i64::MIN, |seg| seg.max.0)); + let max = Max(self.set.range(p..).next().map_or(i64::MAX, |seg| seg.min.0)); if min.0 < max.0 { self.set.insert(Segment { line, min, max }); } diff --git a/libs/convex_hull/src/lib.rs b/libs/convex_hull/src/lib.rs index b3393d44..b42ff0fd 100644 --- a/libs/convex_hull/src/lib.rs +++ b/libs/convex_hull/src/lib.rs @@ -78,8 +78,8 @@ pub fn caliper(a: &[[i64; 2]]) -> (i64, [[i64; 2]; 2]) { } else { let n = a.len(); let mut d = 0; - let mut ans_i = std::usize::MAX; - let mut ans_j = std::usize::MAX; + let mut ans_i = usize::MAX; + let mut ans_j = usize::MAX; let min_position = (0..n).min_by_key(|&i| a[i][0]).unwrap(); let max_position = (0..n).max_by_key(|&i| a[i][0]).unwrap(); let start_i = min_position.min(max_position); diff --git a/libs/dijkstra_radix_heap/src/lib.rs b/libs/dijkstra_radix_heap/src/lib.rs index d8ff0b14..75f35915 100644 --- a/libs/dijkstra_radix_heap/src/lib.rs +++ b/libs/dijkstra_radix_heap/src/lib.rs @@ -4,7 +4,7 @@ #[deprecated] /// 一点からの距離配列を作ります。 pub fn calc_dist(s: usize, g: &[Vec<(usize, u32)>]) -> Vec { - let mut dist = vec![std::u32::MAX; g.len()]; + let mut dist = vec![u32::MAX; g.len()]; dist[s] = 0; let mut heap = radix_heap::RadixHeap::new(); heap.push(0, s); @@ -24,8 +24,8 @@ pub fn calc_dist(s: usize, g: &[Vec<(usize, u32)>]) -> Vec { /// 一点からの距離配列を作ります。 pub fn calc_dist_restore(s: usize, g: &[Vec<(usize, u32)>]) -> (Vec, Vec) { - let mut dist = vec![std::u32::MAX; g.len()]; - let mut prv = vec![std::usize::MAX; g.len()]; + let mut dist = vec![u32::MAX; g.len()]; + let mut prv = vec![usize::MAX; g.len()]; prv[s] = s; dist[s] = 0; let mut heap = radix_heap::RadixHeap::new(); @@ -103,8 +103,8 @@ mod tests { prv.iter().copied().enumerate().for_each(|(x, p)| { let expected = if x == p { 0 - } else if p == std::usize::MAX { - std::u32::MAX + } else if p == usize::MAX { + u32::MAX } else { dist[p] + edges.get(&(p, x)).unwrap() }; diff --git a/libs/dinic/src/lib.rs b/libs/dinic/src/lib.rs index 29dd91b1..390b59fa 100644 --- a/libs/dinic/src/lib.rs +++ b/libs/dinic/src/lib.rs @@ -742,12 +742,12 @@ where loop { // calculate labels - let mut label = vec![std::u32::MAX; res.len()]; + let mut label = vec![u32::MAX; res.len()]; label[s] = 0; let mut queue = VecDeque::from(vec![s]); while let Some(from) = queue.pop_front() { for &__ResidualEdge { to, cap, .. } in &res[from] { - if cap == T::zero() || label[to] != std::u32::MAX { + if cap == T::zero() || label[to] != u32::MAX { continue; } label[to] = label[from] + 1; @@ -755,7 +755,7 @@ where } } - if label[t] == std::u32::MAX { + if label[t] == u32::MAX { // saturated return flow; } @@ -818,7 +818,7 @@ macro_rules! impl_value { 0 } fn infinity() -> Self { - std::$T::MAX + $T::MAX } } )*} diff --git a/libs/erato/src/lpd_sieve.rs b/libs/erato/src/lpd_sieve.rs index 06b9ad84..a45aa5dd 100644 --- a/libs/erato/src/lpd_sieve.rs +++ b/libs/erato/src/lpd_sieve.rs @@ -11,8 +11,7 @@ use super::SieveBase; /// The complexity of algorithms are like this, but it takes extra time to grow itself implicitly. /// /// - Construction: O ( n lg n ) -/// - Prime factorization: O ( ω( n ) ), where ω( n ) is the number of prime divisors, with -/// multiple divisors counted repeatedly. +/// - Prime factorization: O ( ω( n ) ), where ω( n ) is the number of prime divisors, with multiple divisors counted repeatedly. #[derive(Default, Debug, Clone, PartialEq)] pub struct LpdSieve { base: SieveBase, diff --git a/libs/erato/src/sieve.rs b/libs/erato/src/sieve.rs index e4471a57..ebf35d13 100644 --- a/libs/erato/src/sieve.rs +++ b/libs/erato/src/sieve.rs @@ -11,8 +11,7 @@ use super::SieveBase; /// The complexity of algorithms are like this, but it takes extra time to grow itself implicitly. /// /// - Construction: Θ ( n / lg lg n ) -/// - Prime factorization: Θ ( π ( √n ) ), where π ( n ) is the number of prime numbers less than -/// n. +/// - Prime factorization: Θ ( π ( √n ) ), where π ( n ) is the number of prime numbers less than n. #[derive(Default, Debug, Clone, PartialEq)] pub struct Sieve { base: SieveBase, diff --git a/libs/erato/src/sieve_kind.rs b/libs/erato/src/sieve_kind.rs index c9164cdc..b61e8257 100644 --- a/libs/erato/src/sieve_kind.rs +++ b/libs/erato/src/sieve_kind.rs @@ -59,15 +59,15 @@ pub fn construct_is_prime_table(n: usize) -> Vec { } fn construct_lpd_table(n: usize) -> Vec { - let mut lpd = vec![std::usize::MAX; n]; + let mut lpd = vec![usize::MAX; n]; for p in 2..n { - if lpd[p] != std::usize::MAX { + if lpd[p] != usize::MAX { continue; } lpd[p] = p; let mut i = p * p; while i < n { - if lpd[i] == std::usize::MAX { + if lpd[i] == usize::MAX { lpd[i] = p; } i += p; @@ -93,11 +93,11 @@ mod tests { } #[test_case(0 => Vec::::new())] - #[test_case(1 => vec![std::usize::MAX])] - #[test_case(2 => vec![std::usize::MAX, std::usize::MAX])] - #[test_case(3 => vec![std::usize::MAX, std::usize::MAX, 2])] - #[test_case(4 => vec![std::usize::MAX, std::usize::MAX, 2, 3])] - #[test_case(5 => vec![std::usize::MAX, std::usize::MAX, 2, 3, 2])] + #[test_case(1 => vec![usize::MAX])] + #[test_case(2 => vec![usize::MAX, usize::MAX])] + #[test_case(3 => vec![usize::MAX, usize::MAX, 2])] + #[test_case(4 => vec![usize::MAX, usize::MAX, 2, 3])] + #[test_case(5 => vec![usize::MAX, usize::MAX, 2, 3, 2])] fn test_construct_lpd_table(n: usize) -> Vec { construct_lpd_table(n) } diff --git a/libs/fp/src/lib.rs b/libs/fp/src/lib.rs index 566a9935..8b59480c 100644 --- a/libs/fp/src/lib.rs +++ b/libs/fp/src/lib.rs @@ -242,6 +242,7 @@ macro_rules! impl_from_signed { ($($t:ty),*) => { $( impl From<$t> for Fp

{ + #[allow(clippy::cast_lossless)] fn from(x: $t) -> Self { if x < 0 { -Self::new((P as i64 - x as i64) as u64) @@ -258,6 +259,7 @@ macro_rules! impl_from_unsigned { ($($t:ty),*) => { $( impl From<$t> for Fp

{ + #[allow(clippy::cast_lossless)] fn from(x: $t) -> Self { Self::new(x as u64) } } )* diff --git a/libs/gss/src/lib.rs b/libs/gss/src/lib.rs index f5c9b862..9eb5e65b 100644 --- a/libs/gss/src/lib.rs +++ b/libs/gss/src/lib.rs @@ -166,9 +166,11 @@ macro_rules! impl_int { fn one() -> Self { 1 } + #[allow(clippy::cast_lossless)] fn as_f64(self) -> f64 { self as f64 } + #[allow(clippy::cast_lossless)] fn f64_as(x: f64) -> Self { x as $Unsigned } @@ -180,9 +182,11 @@ macro_rules! impl_int { fn one() -> Self { 1 } + #[allow(clippy::cast_lossless)] fn as_f64(self) -> f64 { self as f64 } + #[allow(clippy::cast_lossless)] fn f64_as(x: f64) -> Self { x as $Signed } diff --git a/libs/heap_slope_trick/src/lib.rs b/libs/heap_slope_trick/src/lib.rs index 691c305a..2a137cc0 100644 --- a/libs/heap_slope_trick/src/lib.rs +++ b/libs/heap_slope_trick/src/lib.rs @@ -100,10 +100,10 @@ impl HeapSlopeTrick { [ self.small .peek() - .map_or(std::i64::MIN, |&x| x + self.shift_small), + .map_or(i64::MIN, |&x| x + self.shift_small), self.large .peek() - .map_or(std::i64::MAX, |&Reverse(x)| x + self.shift_large), + .map_or(i64::MAX, |&Reverse(x)| x + self.shift_large), ] } @@ -345,13 +345,13 @@ mod tests { let start = self.values.iter().position(|&y| y == min).unwrap(); let end = n - 1 - self.values.iter().rev().position(|&y| y == min).unwrap(); [ - if start == 0 || self.values[start - 1] == std::i64::MAX { - std::i64::MIN + if start == 0 || self.values[start - 1] == i64::MAX { + i64::MIN } else { XMIN + start as i64 }, - if end == n - 1 || self.values[end + 1] == std::i64::MAX { - std::i64::MAX + if end == n - 1 || self.values[end + 1] == i64::MAX { + i64::MAX } else { XMIN + end as i64 }, @@ -365,14 +365,14 @@ mod tests { fn add_const(&mut self, c: i64) { self.values .iter_mut() - .for_each(|x| *x = if *x == std::i64::MAX { std::i64::MAX } else { *x + c }); + .for_each(|x| *x = if *x == i64::MAX { i64::MAX } else { *x + c }); } fn add_fn(&mut self, f: impl Fn(i64) -> i64) { for x in XMIN..=XMAX { let i = (x - XMIN) as usize; let orig = self.values[i]; - self.values[i] = if orig == std::i64::MAX { std::i64::MAX } else { orig + f(x) }; + self.values[i] = if orig == i64::MAX { i64::MAX } else { orig + f(x) }; } } @@ -406,14 +406,12 @@ mod tests { let a = -a as usize; self.values.rotate_left(a); let n = self.values.len(); - self.values[n - a..] - .iter_mut() - .for_each(|x| *x = std::i64::MAX); + self.values[n - a..].iter_mut().for_each(|x| *x = i64::MAX); } Ordering::Greater => { let a = a as usize; self.values.rotate_right(a); - self.values[..a].iter_mut().for_each(|x| *x = std::i64::MAX); + self.values[..a].iter_mut().for_each(|x| *x = i64::MAX); } Ordering::Equal => (), } @@ -426,7 +424,7 @@ mod tests { (((i - b).max(0).min(n) as usize)..((i - a + 1).min(n).max(0) as usize)) .map(|j| self.values[j]) .min() - .unwrap_or(std::i64::MAX) + .unwrap_or(i64::MAX) }) .collect(); } @@ -434,7 +432,7 @@ mod tests { fn get_tilt_minimum(&self) -> i64 { self.values .windows(2) - .filter(|v| v[0] != std::i64::MAX && v[1] != std::i64::MAX) + .filter(|v| v[0] != i64::MAX && v[1] != i64::MAX) .map(|v| v[1] - v[0]) .min() .unwrap() @@ -443,7 +441,7 @@ mod tests { fn get_tilt_maximum(&self) -> i64 { self.values .windows(2) - .filter(|v| v[0] != std::i64::MAX && v[1] != std::i64::MAX) + .filter(|v| v[0] != i64::MAX && v[1] != i64::MAX) .map(|v| v[1] - v[0]) .max() .unwrap() @@ -453,9 +451,7 @@ mod tests { self.values .windows(3) .enumerate() - .filter(|(_, v)| { - v[0] != std::i64::MAX && v[2] != std::i64::MAX && v[0] + v[2] > v[1] * 2 - }) + .filter(|(_, v)| v[0] != i64::MAX && v[2] != i64::MAX && v[0] + v[2] > v[1] * 2) .map(|(i, v)| [XMIN + 1 + i as i64, v[1]]) .collect() } diff --git a/libs/heap_tricks/src/lib.rs b/libs/heap_tricks/src/lib.rs index fbf89bea..62e626e2 100644 --- a/libs/heap_tricks/src/lib.rs +++ b/libs/heap_tricks/src/lib.rs @@ -52,7 +52,7 @@ //! - 難易度: 易しめ。 //! - 制約: N + Q ≤ 70,000 //! - コメント: キーに [`Copy`] を課しているので [`String`] がくるとかなり -//! めんどくさいことに!! むーん…… +//! めんどくさいことに!! むーん…… //! - 使う構造体: [`DoubleHeap`] (左右移動の明示的追跡あり) //! - yukicoder No.649 - ここでちょっとQK! //! - 問題: @@ -75,7 +75,7 @@ //! - 提出 (211 ms): //! - 出題日: 2019-05-25 //! - 難易度: 易しめ。`heap_slope_trick` クレートがあるので -//! そちらを使ったほうが楽です。 +//! そちらを使ったほうが楽です。 //! - 制約: Q ≤ 200,000 //! - 使う構造体: [`DoubleHeap`] (`heap_slope_trick` クレートを使ったほうがよいです。) //! - ABC 128 E - Roadwork @@ -93,8 +93,8 @@ //! - 制約: N ≤ 100,000 //! - 使う構造体: [`DoubleHeap`] //! - 難易度: Mo 書かないといけないので先延ばしに…… -//! ウェーブレット行列で解く問題を Mo で無理やりクエリ -//! 先読みしているイメージですかね。 +//! ウェーブレット行列で解く問題を Mo で無理やりクエリ +//! 先読みしているイメージですかね。 //! - ABC 170 E - Smart Infants //! - 問題: //! - 提出 (163 ms): @@ -106,7 +106,7 @@ //! - C++ の `std::multiset` (488 ms): //! - AVL 木 (2477 ms): //! - コメント: これフルクラッチで書くとけっこう混乱するので、 -//! ライブラリがるとかなり助かります。 +//! ライブラリがるとかなり助かります。 //! - OUPC 2020 D - 仲良しスライム //! - 問題: //! - 提出 (90 ms): @@ -117,9 +117,9 @@ //! - 他の解法: //! - ウェーブレット行列 (440 ms): //! - コメント: A:B 重み付き中央値クエリ。平衡基準を抽象化して良かった〜〜 -//! これもウェーブレット行列のほうが思いつきやすそうですが、 -//! ウェーブレット行列ライブラリの累積和系の機能が使いづらい(あの!?)ので、 -//! 実装は [`DoubleHeap`] を使うほうが楽です。 +//! これもウェーブレット行列のほうが思いつきやすそうですが、 +//! ウェーブレット行列ライブラリの累積和系の機能が使いづらい(あの!?)ので、 +//! 実装は [`DoubleHeap`] を使うほうが楽です。 //! - ABC 213 G - Game on Tree 2 //! - 問題: //! - 提出 (115 ms): @@ -128,8 +128,8 @@ //! - 制約: N ≤ 100,000 //! - 使う構造体: [`DoubleHeap`] (削除も使います。) //! - コメント: 本番二分探索を考えてうまく行かず、 -//! 後日 [`std::collections::BTreeMap`] で multiset もどきを作って -//! なんとか通して (181 ms) いました。ヒープ4本の方が速くてきれいで嬉しいですね。 +//! 後日 [`std::collections::BTreeMap`] で multiset もどきを作って +//! なんとか通して (181 ms) いました。ヒープ4本の方が速くてきれいで嬉しいですね。 //! - yukicoder No.1786 - Maximum Suffix Median (Online) //! - 問題: //! - 提出 TODO @@ -216,17 +216,22 @@ pub struct DoubleHeap { right: RemovableHeap>, handler: H, } +#[allow(clippy::missing_fields_in_debug)] impl Debug for DoubleHeap where T: Copy + Ord + Hash + Debug, H: Handler + Debug, { + #[allow(clippy::missing_fields_in_debug)] fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("DoubleHeap") - .field("elm", &[ - self.collect_left_sorted_vec(), - self.collect_right_sorted_vec(), - ]) + .field( + "elm", + &[ + self.collect_left_sorted_vec(), + self.collect_right_sorted_vec(), + ], + ) .field("handler", &self.handler) .finish() } diff --git a/libs/hopkarp/src/lib.rs b/libs/hopkarp/src/lib.rs index e37fa78b..1bd51a08 100644 --- a/libs/hopkarp/src/lib.rs +++ b/libs/hopkarp/src/lib.rs @@ -71,10 +71,9 @@ fn construct_minimum_cut( dist: &[u32], backward: &[Option], ) -> (Box<[bool]>, Box<[bool]>) { - use std::u32::MAX; let left = dist .iter() - .map(|&x| x != MAX) + .map(|&x| x != u32::MAX) .collect::>() .into_boxed_slice(); let mut right = vec![false; backward.len()].into_boxed_slice(); @@ -126,8 +125,7 @@ fn dfs( } fn bfs(graph: &[Vec], forward: &[Option], backward: &[Option]) -> Vec { - use std::u32::MAX; - let mut dist = vec![MAX; forward.len()]; + let mut dist = vec![u32::MAX; forward.len()]; let mut queue = forward .iter() .enumerate() @@ -138,7 +136,7 @@ fn bfs(graph: &[Vec], forward: &[Option], backward: &[Option(cost_matrix: &[Vec]) -> HungarianResult { let h = cost_matrix.len(); let w = cost_matrix[0].len(); - let mut m = vec![std::usize::MAX; w + 1]; + let mut m = vec![usize::MAX; w + 1]; // initialize a feasible potential let mut all_min = T::infinity(); @@ -54,7 +54,7 @@ pub fn hungarian(cost_matrix: &[Vec]) -> HungarianResult { m[w] = s; let mut x0 = s; let mut y0 = w; - while x0 != std::usize::MAX { + while x0 != usize::MAX { // find y0 let (swap, delta) = { let mut swap = w; @@ -99,17 +99,17 @@ pub fn hungarian(cost_matrix: &[Vec]) -> HungarianResult { m.pop(); let backward = m; - let mut forward = vec![std::usize::MAX; h].into_boxed_slice(); + let mut forward = vec![usize::MAX; h].into_boxed_slice(); let mut value = T::zero(); for (y, &x) in backward.iter().enumerate() { - if x != std::usize::MAX { + if x != usize::MAX { forward[x] = y; value += cost_matrix[x][y]; } } let backward = backward .into_iter() - .map(|x| if x == std::usize::MAX { None } else { Some(x) }) + .map(|x| if x == usize::MAX { None } else { Some(x) }) .collect::>() .into_boxed_slice(); HungarianResult { @@ -153,7 +153,7 @@ macro_rules! impl_value_int { 0 } fn infinity() -> Self { - std::$T::MAX + $T::MAX } } )*} @@ -170,7 +170,7 @@ macro_rules! impl_value_float { 0. } fn infinity() -> Self { - std::$T::INFINITY + $T::INFINITY } } )*} diff --git a/libs/lazy_segbeats/src/lib.rs b/libs/lazy_segbeats/src/lib.rs index 67faf40e..4344df12 100644 --- a/libs/lazy_segbeats/src/lib.rs +++ b/libs/lazy_segbeats/src/lib.rs @@ -381,14 +381,15 @@ macro_rules! impl_elm { $( impl Elm for $ty { fn min_value() -> Self { - std::$ty::MIN + $ty::MIN } fn max_value() -> Self { - std::$ty::MAX + $ty::MAX } fn zero() -> Self { 0 } + #[allow(clippy::cast_lossless)] fn mul_u32(&self, x: u32) -> Self { self * (x as $ty) } diff --git a/libs/lin_ineq/src/lib.rs b/libs/lin_ineq/src/lib.rs index fb1ced27..f2788628 100644 --- a/libs/lin_ineq/src/lib.rs +++ b/libs/lin_ineq/src/lib.rs @@ -6,6 +6,7 @@ //! 関数とのやり取りは、[`Interval`] 型を使います。これは `[T; 2]` の透明なラッパーです。 //! - [`Interval`] 型は [`Mul`],[`Product`] を実装しており、これは [`Interval::intersection`] を呼びだします。 //! - [`full()`](Interval::full), [`contains()`](Interval::contains) +//! //! といった便利なメソッドがあります。 //! //! 一次不等式を解く関数には次のものがあります。 @@ -24,7 +25,7 @@ //! ``` //! # use { //! # lin_ineq::solve, -//! # std::i64::MIN, +//! # i64::MIN, //! # }; //! let sol = solve(2, 10); // 2x <= 10 //! assert_eq!(sol.0, [MIN, 5]); // x <= 5 @@ -35,7 +36,7 @@ //! ``` //! # use { //! # lin_ineq::{solve_squeeze, Interval}, -//! # std::i64::MIN, +//! # i64::MIN, //! # }; //! let sol = solve_squeeze(3, 1, Interval([-5, 5])); // -5 <= 3x + 1 <= 5 //! assert_eq!(sol.0, [-2, 1]); // -2 <= x <= 1 @@ -61,8 +62,8 @@ pub trait Signed: Sized + Copy + Ord + Neg + Sub { macro_rules! impl_signed { ($($T:ident),*) => {$( impl Signed for $T { - const MIN: Self = std::$T::MIN; - const MAX: Self = std::$T::MAX; + const MIN: Self = $T::MIN; + const MAX: Self = $T::MAX; const ZERO: Self = 0; fn div_euclid(self, rhs: Self) -> Self { self.div_euclid(rhs) @@ -136,6 +137,7 @@ pub fn solve_squeeze(a: T, b: T, y: Interval) -> Interval { /// - [`empty()`](Self::empty) の戻り値は必ず `[MAX, MIN]`(以下、標準形と呼びます。) です。 /// - [`normalize()`](Self::normalize) を使うと空区間はかならず標準形です。 /// - [`intersection()`](Self::intersection) により生じる空区間は標準形とは限りません。 +/// /// と同じ形になります。 /// /// @@ -186,8 +188,7 @@ impl Interval { /// /// ``` /// # use lin_ineq::Interval; - /// # use std::i64::{MIN, MAX}; - /// assert_eq!(Interval::::full().0, [MIN, MAX]); + /// assert_eq!(Interval::::full().0, [i64::MIN, i64::MAX]); /// ``` pub fn full() -> Self { Self([T::MIN, T::MAX]) @@ -199,8 +200,7 @@ impl Interval { /// /// ``` /// # use lin_ineq::Interval; - /// # use std::i64::{MIN, MAX}; - /// assert_eq!(Interval::::empty().0, [MAX, MIN]); + /// assert_eq!(Interval::::empty().0, [i64::MAX, i64::MIN]); /// ``` pub fn empty() -> Self { Self([T::MAX, T::MIN]) @@ -226,10 +226,9 @@ impl Interval { /// /// ``` /// # use lin_ineq::Interval; - /// # use std::i64::{MIN, MAX}; /// assert_eq!(Interval([0, 10]).normalize().0, [0, 10]); /// assert_eq!(Interval([0, 0]).normalize().0, [0, 0]); - /// assert_eq!(Interval([0, -10]).normalize().0, [MAX, MIN]); + /// assert_eq!(Interval([0, -10]).normalize().0, [i64::MAX, i64::MIN]); /// ``` pub fn normalize(self) -> Self { if self.is_empty() { @@ -342,8 +341,6 @@ mod tests { use rand::prelude::StdRng; use rand::Rng; use rand::SeedableRng; - use std::i64::MAX; - use std::i64::MIN; use std::iter::repeat_with; //////////////////////////////////////////////////////////////////////////////// @@ -383,12 +380,12 @@ mod tests { #[test] fn test_full() { - assert_eq!(Interval::::full().0, [MIN, MAX]); + assert_eq!(Interval::::full().0, [i64::MIN, i64::MAX]); } #[test] fn test_empty() { - assert_eq!(Interval::::empty().0, [MAX, MIN]); + assert_eq!(Interval::::empty().0, [i64::MAX, i64::MIN]); } #[test] @@ -413,10 +410,10 @@ mod tests { format!("{:?}", x) } assert_eq!(debug(Interval([0, 2])).as_str(), "Finite(0, 2)"); - assert_eq!(debug(Interval([0, MAX])).as_str(), "Ge(0)"); - assert_eq!(debug(Interval([MIN, 2])).as_str(), "Le(2)"); - assert_eq!(debug(Interval([MIN, MAX])).as_str(), "Full"); - assert_eq!(debug(Interval([MAX, MIN])).as_str(), "Empty"); + assert_eq!(debug(Interval([0, i64::MAX])).as_str(), "Ge(0)"); + assert_eq!(debug(Interval([i64::MIN, 2])).as_str(), "Le(2)"); + assert_eq!(debug(Interval([i64::MIN, i64::MAX])).as_str(), "Full"); + assert_eq!(debug(Interval([i64::MAX, i64::MIN])).as_str(), "Empty"); assert_eq!(debug(Interval([2, 0])).as_str(), "Empty"); } diff --git a/libs/mincost_flow/src/lib.rs b/libs/mincost_flow/src/lib.rs index 1ea78558..85690068 100644 --- a/libs/mincost_flow/src/lib.rs +++ b/libs/mincost_flow/src/lib.rs @@ -5,7 +5,6 @@ use std::cmp::Reverse; use std::collections::BinaryHeap; use std::fmt::Debug; -use std::i64::MAX; use std::mem::replace; /// [`MinCostFlow::get_edge`] の戻り値型 @@ -20,7 +19,7 @@ pub struct Edge { impl Debug for Edge { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn fmt_i64(x: i64) -> String { - if x == MAX { + if x == i64::MAX { "_".to_owned() } else { x.to_string() @@ -67,7 +66,7 @@ struct __InternalEdge { /// mcf.add_edge(0, 2, 1, 20); /// mcf.add_edge(1, 2, 1, 10); /// -/// let slope = mcf.slope(0, 2, std::i64::MAX); +/// let slope = mcf.slope(0, 2, i64::MAX); /// assert_eq!(slope, vec![(0, 0), (1, 20), (2, 50)]); /// ``` /// @@ -151,7 +150,7 @@ impl MinCostFlow { let mut slope = vec![(0, 0)]; let mut flow = 0; let mut cost = 0; - let mut prev_price = MAX; + let mut prev_price = i64::MAX; while flow < flow_limit { let mut dual = vec![0; n]; let mut used = vec![false; n]; @@ -202,7 +201,7 @@ impl MinCostFlow { ) -> bool { let mut heap = BinaryHeap::<(Reverse, usize)>::new(); heap.push((Reverse(0), source)); - let mut dist = vec![MAX; self.g.len()]; + let mut dist = vec![i64::MAX; self.g.len()]; dist[source] = 0; while let Some((Reverse(dx), x)) = heap.pop() { used[x] = true; @@ -236,7 +235,6 @@ impl MinCostFlow { #[cfg(test)] mod tests { use super::MinCostFlow; - use std::i64::MAX; #[test] fn test_mincost_flow() { @@ -255,7 +253,7 @@ mod tests { assert_eq!(graph.add_edge(0, 1, 1, 1), 0); assert_eq!(graph.add_edge(1, 2, 1, 0), 1); assert_eq!(graph.add_edge(0, 2, 2, 1), 2); - assert_eq!(&graph.slope(0, 2, MAX), &[(0, 0), (3, 3)]); + assert_eq!(&graph.slope(0, 2, i64::MAX), &[(0, 0), (3, 3)]); } #[test] @@ -263,6 +261,6 @@ mod tests { let mut graph = MinCostFlow::new(3); assert_eq!(graph.add_edge(0, 1, 1, 1), 0); assert_eq!(graph.add_edge(1, 2, 1, 0), 1); - assert_eq!(graph.slope(0, 2, MAX), &[(0, 0), (1, 1)]); + assert_eq!(graph.slope(0, 2, i64::MAX), &[(0, 0), (1, 1)]); } } diff --git a/libs/monotone_minima/src/lib.rs b/libs/monotone_minima/src/lib.rs index 71d7ff97..b8107985 100644 --- a/libs/monotone_minima/src/lib.rs +++ b/libs/monotone_minima/src/lib.rs @@ -251,8 +251,7 @@ mod tests { } fn minplus_convolution_brute(a: &[i32], b: &[i32]) -> Vec { - use std::i32::MAX; - let mut c = vec![MAX; a.len() + b.len() - 1]; + let mut c = vec![i32::MAX; a.len() + b.len() - 1]; for (i, &x) in a.iter().enumerate() { for (j, &y) in b.iter().enumerate() { c[i + j] = c[i + j].min(x + y); @@ -288,8 +287,7 @@ mod tests { } fn maxplus_convolution_brute(a: &[i32], b: &[i32]) -> Vec { - use std::i32::MIN; - let mut c = vec![MIN; a.len() + b.len() - 1]; + let mut c = vec![i32::MIN; a.len() + b.len() - 1]; for (i, &x) in a.iter().enumerate() { for (j, &y) in b.iter().enumerate() { c[i + j] = c[i + j].max(x + y); diff --git a/libs/naive_poly/src/lib.rs b/libs/naive_poly/src/lib.rs index 549f35a2..a125a9f7 100644 --- a/libs/naive_poly/src/lib.rs +++ b/libs/naive_poly/src/lib.rs @@ -30,7 +30,7 @@ where T: Copy + Sum + Mul + AddAssign, { if a.is_empty() || b.is_empty() { - return vec![zero(); 0]; + return Vec::new(); } let mut c = vec![zero(); a.len() + b.len() - 1]; for (i, &ai) in a.iter().enumerate() { @@ -92,7 +92,7 @@ where { assert!(!b.is_empty() && *b.last().unwrap() != zero::()); if a.len() < b.len() { - return vec![zero(); 0]; + return Vec::new(); } let mut c = vec![zero(); a.len() + 1 - b.len()]; for i in (0..c.len()).rev() { @@ -336,7 +336,7 @@ mod tests { } impl Sum for MinPlus { fn sum>(iter: I) -> Self { - iter.fold(MinPlus(std::u64::MAX), |a, b| a + b) + iter.fold(MinPlus(u64::MAX), |a, b| a + b) } } impl Mul for MinPlus { @@ -395,7 +395,7 @@ mod tests { assert_eq!(c.len(), a.len() + b.len() - 1); } for k in 0..c.len() { - let mut x = std::u64::MAX; + let mut x = u64::MAX; for i in k.saturating_sub(b.len() - 1)..=k.min(a.len() - 1) { x = x.min(a[i].0 + b[k - i].0); } diff --git a/libs/newton/src/lib.rs b/libs/newton/src/lib.rs index 76e66194..6fb42a01 100644 --- a/libs/newton/src/lib.rs +++ b/libs/newton/src/lib.rs @@ -60,13 +60,13 @@ mod tests { assert!(square(x) <= y); assert!(y < square(x + 1)); } - for &y in &[std::u64::MAX / 2, std::u64::MAX / 2 + 1] { + for &y in &[u64::MAX / 2, u64::MAX / 2 + 1] { let x = sqrt(y); assert!(square(x) <= y); assert!(y < square(x + 1)); } for _ in 0..100 { - let y = rng.gen_range(0..std::u64::MAX / 2); + let y = rng.gen_range(0..u64::MAX / 2); let x = sqrt(y); assert!(square(x) <= y); assert!(y < square(x + 1)); @@ -100,7 +100,7 @@ mod tests { assert!(y < triangular(x + 1)); } for _ in 0..100 { - let y = rng.gen_range(0..std::u64::MAX / 4); + let y = rng.gen_range(0..u64::MAX / 4); let x = triangular_root(y); assert!(triangular(x) <= y); assert!(y < triangular(x + 1)); diff --git a/libs/numeric_search/src/lib.rs b/libs/numeric_search/src/lib.rs index afe18e15..f14a50d0 100644 --- a/libs/numeric_search/src/lib.rs +++ b/libs/numeric_search/src/lib.rs @@ -43,8 +43,8 @@ pub trait Float: fn sqrt(self) -> Self; } impl Float for f32 { - const INFINITY: Self = std::f32::INFINITY; - const NEG_INFINITY: Self = std::f32::NEG_INFINITY; + const INFINITY: Self = f32::INFINITY; + const NEG_INFINITY: Self = f32::NEG_INFINITY; const ONE: Self = 1.0; const ZERO: Self = 0.0; @@ -53,8 +53,8 @@ impl Float for f32 { } } impl Float for f64 { - const INFINITY: Self = std::f64::INFINITY; - const NEG_INFINITY: Self = std::f64::NEG_INFINITY; + const INFINITY: Self = f64::INFINITY; + const NEG_INFINITY: Self = f64::NEG_INFINITY; const ONE: Self = 1.0; const ZERO: Self = 0.0; @@ -291,8 +291,8 @@ macro_rules! impl_signed { impl Signed for $ty { const ZERO: Self = 0; const ONE: Self = 1; - const MIN: Self = std::$ty::MIN; - const MAX: Self = std::$ty::MAX; + const MIN: Self = $ty::MIN; + const MAX: Self = $ty::MAX; } )*}; } @@ -316,7 +316,7 @@ impl_signed! { i8, i16, i32, i64, i128 } /// # use numeric_search::exp_search_signed; /// assert_eq!(exp_search_signed(|x| 6 <= x), Some(6)); /// assert_eq!(exp_search_signed(|_: i32| false), None); -/// assert_eq!(exp_search_signed(|_: i32| true), Some(std::i32::MIN)); +/// assert_eq!(exp_search_signed(|_: i32| true), Some(i32::MIN)); /// ``` pub fn exp_search_signed(mut f: impl FnMut(T) -> bool) -> Option { let mut lower; @@ -402,12 +402,6 @@ mod tests { #[test] fn test_exponential_search_f64() { - use std::f64::EPSILON; - use std::f64::INFINITY; - use std::f64::MAX; - use std::f64::MIN_POSITIVE; - use std::f64::NEG_INFINITY; - let mut rng = StdRng::seed_from_u64(42); for _ in 0..2000 { let expected: f64 = if rng.gen_bool(0.5) { 1.0 } else { -1.0 } @@ -425,16 +419,16 @@ mod tests { // Succeeds (0.0, 0.0), (-0.0, 0.0), - (INFINITY, INFINITY), - (NEG_INFINITY, NEG_INFINITY), - (EPSILON, EPSILON), - (MAX.sqrt(), MAX.sqrt()), - (-MAX.sqrt(), -MAX.sqrt()), - (MIN_POSITIVE, MIN_POSITIVE), - (-MIN_POSITIVE, -MIN_POSITIVE), + (f64::INFINITY, f64::INFINITY), + (f64::NEG_INFINITY, f64::NEG_INFINITY), + (f64::EPSILON, f64::EPSILON), + (f64::MAX.sqrt(), f64::MAX.sqrt()), + (-f64::MAX.sqrt(), -f64::MAX.sqrt()), + (f64::MIN_POSITIVE, f64::MIN_POSITIVE), + (-f64::MIN_POSITIVE, -f64::MIN_POSITIVE), // Fails - (MAX.sqrt() * 1.000_000_000_001, INFINITY), - (-MAX.sqrt() * 1.000_000_000_001, NEG_INFINITY), + (f64::MAX.sqrt() * 1.000_000_000_001, f64::INFINITY), + (-f64::MAX.sqrt() * 1.000_000_000_001, f64::NEG_INFINITY), ] { let result = exp_search_float(|x| threshold <= x); assert_eq!(result, expected); @@ -443,12 +437,6 @@ mod tests { #[test] fn test_exponential_search_f32() { - use std::f32::EPSILON; - use std::f32::INFINITY; - use std::f32::MAX; - use std::f32::MIN_POSITIVE; - use std::f32::NEG_INFINITY; - let mut rng = StdRng::seed_from_u64(42); for _ in 0..2000 { let expected: f32 = @@ -466,16 +454,16 @@ mod tests { // Succeeds (0.0, 0.0), (-0.0, 0.0), - (INFINITY, INFINITY), - (NEG_INFINITY, NEG_INFINITY), - (EPSILON, EPSILON), - (MAX.sqrt(), MAX.sqrt()), - (-MAX.sqrt(), -MAX.sqrt()), - (MIN_POSITIVE, MIN_POSITIVE), - (-MIN_POSITIVE, -MIN_POSITIVE), + (f32::INFINITY, f32::INFINITY), + (f32::NEG_INFINITY, f32::NEG_INFINITY), + (f32::EPSILON, f32::EPSILON), + (f32::MAX.sqrt(), f32::MAX.sqrt()), + (-f32::MAX.sqrt(), -f32::MAX.sqrt()), + (f32::MIN_POSITIVE, f32::MIN_POSITIVE), + (-f32::MIN_POSITIVE, -f32::MIN_POSITIVE), // Fails - (MAX.sqrt() * 1.000_001, INFINITY), - (-MAX.sqrt() * 1.000_001, NEG_INFINITY), + (f32::MAX.sqrt() * 1.000_001, f32::INFINITY), + (-f32::MAX.sqrt() * 1.000_001, f32::NEG_INFINITY), ] { let result = exp_search_float(|x| threshold <= x); assert_eq!(result, expected); diff --git a/libs/partially_persistent_union_find/src/lib.rs b/libs/partially_persistent_union_find/src/lib.rs index c5daa750..eae0cf3f 100644 --- a/libs/partially_persistent_union_find/src/lib.rs +++ b/libs/partially_persistent_union_find/src/lib.rs @@ -3,19 +3,16 @@ //! [構造体 `PartiallyPersistentUnionFind` のドキュメントをご覧ください。](PartiallyPersistentUnionFind) use std::mem::swap; -use std::usize::MAX; /// 部分永続化された、素集合データ構造です。 /// /// # 時刻について /// -/// `MAX` といえば `std::usize:MAX` のことであるとします。 +/// `MAX` といえば `usize:MAX` のことであるとします。 /// /// * 入力できるのは `1..=MAX`。 -/// * 過去クエリで時刻 t を指定すると、t -/// と同じかそれより小さな時刻のイベントが適用された状態を参照します。 -/// * t = `MAX` でクエリすると最終状態を参照します。(仮に時刻 `MAX` -/// にイベントが存在したとしても。) +/// * 過去クエリで時刻 t を指定すると、t と同じかそれより小さな時刻のイベントが適用された状態を参照します。 +/// * t = `MAX` でクエリすると最終状態を参照します。(仮に時刻 `MAX` にイベントが存在したとしても。) /// /// # Examples /// @@ -61,24 +58,23 @@ use std::usize::MAX; /// /// ``` /// use partially_persistent_union_find::PartiallyPersistentUnionFind; -/// use std::usize::MAX; /// /// let mut uf = PartiallyPersistentUnionFind::new(5); /// /// // MAX にイベントをセット -/// uf.union(0, 1, MAX); +/// uf.union(0, 1, usize::MAX); /// /// // 適用前を参照 -/// assert!(!uf.same(0, 1, MAX - 1)); +/// assert!(!uf.same(0, 1, usize::MAX - 1)); /// /// // 適用後を参照 -/// assert!(uf.same(0, 1, MAX)); +/// assert!(uf.same(0, 1, usize::MAX)); /// ``` /// /// /// # 速度面 /// -/// * [`size`](PartiallyPersistentUnionFind::size) を実現するために n +/// [`size`](PartiallyPersistentUnionFind::size) を実現するために n /// 回程度の動的メモリ確保の必要なフィールド `size_history` を管理しているため、 /// 定数倍が重くなっています。 #[derive(Clone, Debug)] @@ -94,7 +90,7 @@ impl PartiallyPersistentUnionFind { /// /// # 制約 /// - /// `n < std::isize::MAX` + /// `n < isize::MAX` /// /// # Examples /// @@ -103,10 +99,10 @@ impl PartiallyPersistentUnionFind { /// let uf = PartiallyPersistentUnionFind::new(5); /// ``` pub fn new(n: usize) -> Self { - assert!(n < std::isize::MAX as usize); + assert!(n < isize::MAX as usize); Self { parent: vec![-1; n], - time_stamp: vec![MAX; n], + time_stamp: vec![usize::MAX; n], size_history: vec![Vec::new(); n], last_stamp: 0, } @@ -253,7 +249,6 @@ mod tests { use rand::Rng; use rand::SeedableRng; use randtools::DistinctTwo; - use std::usize::MAX; #[test] fn test_rand() { @@ -304,8 +299,8 @@ mod tests { fn time_brute(uf: &PartiallyPersistentUnionFind, u: usize, v: usize) -> Option { let mut left = 0; - let mut right = MAX; - if uf.find(u, MAX) != uf.find(v, MAX) { + let mut right = usize::MAX; + if uf.find(u, usize::MAX) != uf.find(v, usize::MAX) { return None; } if u == v { diff --git a/libs/rb/src/balance.rs b/libs/rb/src/balance.rs index 8aa24efe..8926b666 100644 --- a/libs/rb/src/balance.rs +++ b/libs/rb/src/balance.rs @@ -237,10 +237,7 @@ impl Tree { } impl Clone for Tree { fn clone(&self) -> Self { - Self { - root: self.root, - black_height: self.black_height, - } + *self } } impl Copy for Tree {} @@ -264,10 +261,7 @@ impl fmt::Debug for BlackViolation { } impl Clone for BlackViolation { fn clone(&self) -> Self { - Self { - p: self.p, - x: self.x, - } + *self } } impl Copy for BlackViolation {} diff --git a/libs/rb/src/map.rs b/libs/rb/src/map.rs index 8d3cc2cb..d3ef071e 100644 --- a/libs/rb/src/map.rs +++ b/libs/rb/src/map.rs @@ -147,10 +147,9 @@ impl MultimapSeg { (&x.key, &mut x.value) } - pub fn binary_search(&self, key: &Q) -> Result<(&O::Value, usize), usize> + pub fn binary_search(&self, key: &Q) -> Result<(&O::Value, usize), usize> where - K: Ord + Borrow, - Q: Ord, + K: Borrow, { self.binary_search_ptr(key) .map(|(x, i)| (&x.as_longlife_ref().value, i)) @@ -222,10 +221,9 @@ impl MultimapSeg { } } - pub fn remove(&mut self, key: &Q) -> Option<(K, O::Value)> + pub fn remove(&mut self, key: &Q) -> Option<(K, O::Value)> where - K: Ord + Borrow, - Q: Ord, + K: Borrow, { let x = self.binary_search_ptr(key).ok()?.0; self.remove_ptr(x); @@ -261,10 +259,12 @@ impl MultimapSeg { x } - pub fn binary_search_ptr(&self, key: &Q) -> Result<(Ptr>, usize), usize> + pub fn binary_search_ptr( + &self, + key: &Q, + ) -> Result<(Ptr>, usize), usize> where - K: Ord + Borrow, - Q: Ord, + K: Borrow, { let mut x = self.tree.root.ok_or(0usize)?; let mut index = 0; @@ -434,10 +434,9 @@ impl Multimap { self.segmap.nth(n) } - pub fn binary_search(&self, key: &Q) -> Result<(&V, usize), usize> + pub fn binary_search(&self, key: &Q) -> Result<(&V, usize), usize> where - K: Ord + Borrow, - Q: Ord, + K: Borrow, { self.segmap.binary_search(key) } @@ -458,10 +457,9 @@ impl Multimap { self.segmap.insert(key, value) } - pub fn remove(&mut self, key: &Q) -> Option<(K, V)> + pub fn remove(&mut self, key: &Q) -> Option<(K, V)> where - K: Ord + Borrow, - Q: Ord, + K: Borrow, { self.segmap.remove(key) } @@ -537,12 +535,11 @@ impl Multiset { self.map.nth(n).0 } - pub fn binary_search(&self, key: &Q) -> Result + pub fn binary_search(&self, key: &Q) -> Result where - K: Ord + Borrow, - Q: Ord, + K: Borrow, { - self.map.binary_search(key).map(|(_, i)| i) + self.map.binary_search(key).map(|((), i)| i) } pub fn partition_point(&self, f: impl FnMut(&K) -> bool) -> usize { @@ -561,12 +558,11 @@ impl Multiset { self.map.insert(key, ()) } - pub fn remove(&mut self, key: &Q) -> Option + pub fn remove(&mut self, key: &Q) -> Option where K: Ord + Borrow, - Q: Ord, { - self.map.remove(key).map(|(k, _)| k) + self.map.remove(key).map(|(k, ())| k) } pub fn remove_nth(&mut self, n: usize) -> K { @@ -598,7 +594,7 @@ impl<'a, K: Ord> Iterator for MultisetIter<'a, K> { type Item = &'a K; fn next(&mut self) -> Option { - self.iter.next().map(|(k, _)| k) + self.iter.next().map(|(k, ())| k) } fn size_hint(&self) -> (usize, Option) { @@ -607,7 +603,7 @@ impl<'a, K: Ord> Iterator for MultisetIter<'a, K> { } impl<'a, K: Ord> DoubleEndedIterator for MultisetIter<'a, K> { fn next_back(&mut self) -> Option { - self.iter.next_back().map(|(k, _)| k) + self.iter.next_back().map(|(k, ())| k) } } impl<'a, K: Ord> ExactSizeIterator for MultisetIter<'a, K> {} diff --git a/libs/rb/src/seq.rs b/libs/rb/src/seq.rs index d4687879..b2d710f9 100644 --- a/libs/rb/src/seq.rs +++ b/libs/rb/src/seq.rs @@ -42,19 +42,16 @@ impl Node { } pub fn is_leaf(&self) -> bool { - match self.left { - None => { - debug_assert!(self.left.is_none()); - debug_assert!(self.right.is_none()); - debug_assert_eq!(self.len, 1); - true - } - Some(_) => { - debug_assert!(self.left.is_some()); - debug_assert!(self.right.is_some()); - debug_assert_ne!(self.len, 1); - false - } + if self.left.is_none() { + debug_assert!(self.left.is_none()); + debug_assert!(self.right.is_none()); + debug_assert_eq!(self.len, 1); + true + } else { + debug_assert!(self.left.is_some()); + debug_assert!(self.right.is_some()); + debug_assert_ne!(self.len, 1); + false } } } @@ -700,7 +697,7 @@ where .map(|row| { let mut swp = Vec::new(); let mut offset = 0; - for (range, value) in row.iter() { + for (range, value) in row { refinement[range.start] = true; while offset < range.start { let end = (offset + 1..n).find(|&i| refinement[i]).unwrap_or(n); @@ -1004,7 +1001,7 @@ mod test_seg { const LEN_LIM: usize = 60; let mut rng = StdRng::seed_from_u64(42); for _ in 0..20 { - let mut used = vec![false; LEN_LIM]; + let mut used = [false; LEN_LIM]; let mut seg = Seg::::new(); let mut vec = Vec::new(); for _ in 0..200 { diff --git a/libs/scc/src/lib.rs b/libs/scc/src/lib.rs index 51470d8f..b2220e61 100644 --- a/libs/scc/src/lib.rs +++ b/libs/scc/src/lib.rs @@ -3,8 +3,7 @@ //! //! - AOJ GRL_3_C - 強連結成分分解 //! - 問題: -//! - 提出 (8 ms): -//! +//! - 提出 (8 ms): //! - 出題日: 2016-09-04 //! - 難易度: 易しめ。 //! - 制約: diff --git a/libs/segbeats/src/lib.rs b/libs/segbeats/src/lib.rs index 3f80eb22..d739ba8b 100644 --- a/libs/segbeats/src/lib.rs +++ b/libs/segbeats/src/lib.rs @@ -334,14 +334,15 @@ macro_rules! impl_elm { $( impl Elm for $ty { fn min_value() -> Self { - std::$ty::MIN + $ty::MIN } fn max_value() -> Self { - std::$ty::MAX + $ty::MAX } fn zero() -> Self { 0 } + #[allow(clippy::cast_lossless)] fn mul_u32(&self, x: u32) -> Self { self * (x as $ty) } diff --git a/libs/segbeats_task3/src/lib.rs b/libs/segbeats_task3/src/lib.rs index c863a962..2f392128 100644 --- a/libs/segbeats_task3/src/lib.rs +++ b/libs/segbeats_task3/src/lib.rs @@ -475,14 +475,15 @@ macro_rules! impl_elm { $( impl Elm for $ty { fn min_value() -> Self { - std::$ty::MIN + $ty::MIN } fn max_value() -> Self { - std::$ty::MAX + $ty::MAX } fn zero() -> Self { 0 } + #[allow(clippy::cast_lossless)] fn mul_u32(&self, x: u32) -> Self { self * (x as $ty) } diff --git a/libs/segtree/src/lib.rs b/libs/segtree/src/lib.rs index aa3f0025..834a2acd 100644 --- a/libs/segtree/src/lib.rs +++ b/libs/segtree/src/lib.rs @@ -205,6 +205,16 @@ impl Segtree { } } +impl<'a, O: Op> IntoIterator for &'a Segtree { + type IntoIter = std::slice::Iter<'a, O::Value>; + type Item = &'a O::Value; + + fn into_iter(self) -> Self::IntoIter { + self.iter() + } +} + +#[allow(clippy::missing_fields_in_debug)] impl fmt::Debug for Segtree where O::Value: fmt::Debug, @@ -520,7 +530,7 @@ impl Dense2dSegtree { { let values_ = values; let h = values.len(); - let w = values.get(0).map_or(0, Vec::len); + let w = values.first().map_or(0, Vec::len); let mut values = vec![vec![O::identity(); 2 * w]; 2 * h]; for (values, values_) in values[h..].iter_mut().zip(values_) { values[w..].clone_from_slice(values_); @@ -539,7 +549,7 @@ impl Dense2dSegtree { /// Fold $\left \lbrace x_{i, j} \mid i \in \text{{range}}_i, j \in \text{{range}}_j \right \rbrace$. pub fn fold(&self, i: impl RangeBounds, j: impl RangeBounds) -> O::Value { let h = self.values.len() / 2; - let w = self.values.get(0).map_or(0, |v| v.len() / 2); + let w = self.values.first().map_or(0, |v| v.len() / 2); let (mut i0, mut i1) = open(i, h); assert!(i0 <= i1 && i1 <= h); let (mut j0, mut j1) = open(j, w); @@ -594,7 +604,7 @@ impl Dense2dSegtree { /// Returns the entry of $x_{i, j}$. pub fn entry(&mut self, i: usize, j: usize) -> Dense2dEntry { let h = self.values.len() / 2; - let w = self.values.get(0).map_or(0, |v| v.len() / 2); + let w = self.values.first().map_or(0, |v| v.len() / 2); Dense2dEntry { segtree: self, i: h + i, diff --git a/libs/sort_tree/src/lib.rs b/libs/sort_tree/src/lib.rs index 5281b4b4..5607f926 100644 --- a/libs/sort_tree/src/lib.rs +++ b/libs/sort_tree/src/lib.rs @@ -52,7 +52,6 @@ mod tests { use rand::Rng; use rand::SeedableRng; use randtools::Tree; - use std::usize::MAX; #[test] fn test_sort_tree_remove_parent() { @@ -67,11 +66,11 @@ mod tests { assert_eq!(parent.len(), n); assert_eq!(root, parent[root]); assert_eq!(ord[0], root); - let mut pos = vec![MAX; n]; + let mut pos = vec![usize::MAX; n]; for (i, &o) in ord.iter().enumerate() { pos[o] = i; } - assert!(pos.iter().all(|&x| x != MAX)); + assert!(pos.iter().all(|&x| x != usize::MAX)); for (x, y) in g .iter() .enumerate() diff --git a/libs/splay_tree/src/node.rs b/libs/splay_tree/src/node.rs index 3f9b1d61..0cd6fc5b 100644 --- a/libs/splay_tree/src/node.rs +++ b/libs/splay_tree/src/node.rs @@ -114,7 +114,7 @@ impl Node { println!( "{:?}: parent = {:?}, left = {:?}, right = {:?}, len = {}, rev = {}, value = {:?}, \ acc = {:?}, lazy = {:?}", - self as *const _, + std::ptr::from_ref(self), self.parent, self.left, self.right, diff --git a/libs/splay_tree/src/test_trivial.rs b/libs/splay_tree/src/test_trivial.rs index ad9081ae..a95e3c59 100644 --- a/libs/splay_tree/src/test_trivial.rs +++ b/libs/splay_tree/src/test_trivial.rs @@ -82,11 +82,11 @@ fn test_partial_cmp() { Some(Ordering::Greater) ); assert_eq!( - from_slice(&[0.0, 2.0]).partial_cmp(&from_slice(&[0.0, std::f64::NAN])), + from_slice(&[0.0, 2.0]).partial_cmp(&from_slice(&[0.0, f64::NAN])), None, ); assert_eq!( - from_slice(&[0.0, 1.0]).partial_cmp(&from_slice(&[2.0, std::f64::NAN])), + from_slice(&[0.0, 1.0]).partial_cmp(&from_slice(&[2.0, f64::NAN])), Some(Ordering::Less) ); } diff --git a/libs/suffix_sum/src/lib.rs b/libs/suffix_sum/src/lib.rs index e0b9cfd3..dda1b834 100644 --- a/libs/suffix_sum/src/lib.rs +++ b/libs/suffix_sum/src/lib.rs @@ -132,7 +132,7 @@ impl SuffixSum2d { let (i0, i1) = open(i, self.values.len() - 1); let (j0, j1) = open(j, self.values[0].len()); assert!(i0 <= i1 && i1 < self.values.len()); - assert!(j0 <= j1 && j1 <= self.values.get(0).map_or(0, Vec::len)); + assert!(j0 <= j1 && j1 <= self.values.first().map_or(0, Vec::len)); O::div( &O::mul(&self.values[i0][j0], &self.values[i1][j1]), &O::mul(&self.values[i0][j1], &self.values[i1][j0]), @@ -182,7 +182,7 @@ where impl From>> for SuffixSum2d { fn from(mut values: Vec>) -> Self { let h = values.len(); - let w = values.get(0).map_or(0, Vec::len); + let w = values.first().map_or(0, Vec::len); values.push(repeat_with(O::identity).take(w).collect()); for values in &mut values { values.push(O::identity()); @@ -304,6 +304,7 @@ mod tests { } #[test] + #[allow(clippy::should_panic_without_expect)] #[should_panic] #[allow(clippy::reversed_empty_ranges)] fn test_suffix_sum_invalid_range() { @@ -313,6 +314,7 @@ mod tests { } #[test] + #[allow(clippy::should_panic_without_expect)] #[should_panic] fn test_suffix_sum_out_of_range() { let values = vec![1, 2, 3, 4, 5]; diff --git a/libs/swag/src/lib.rs b/libs/swag/src/lib.rs index 0e99b7ee..2de0e95b 100644 --- a/libs/swag/src/lib.rs +++ b/libs/swag/src/lib.rs @@ -317,7 +317,7 @@ impl IntoIterator for DequeueSwag { type Item = O::Value; fn into_iter(self) -> Self::IntoIter { - self.front.into_iter().rev().chain(self.back.into_iter()) + self.front.into_iter().rev().chain(self.back) } } diff --git a/libs/uf_checklist/src/lib.rs b/libs/uf_checklist/src/lib.rs index 0aefea66..9e677a07 100644 --- a/libs/uf_checklist/src/lib.rs +++ b/libs/uf_checklist/src/lib.rs @@ -29,9 +29,7 @@ //! //! ## クエリ //! -//! * [`lower_bound`](UfChecklist::lower_bound): -//! 指定した場所と同じかもっと右にある未チェックな項 -//! を探します。 +//! * [`lower_bound`](UfChecklist::lower_bound): 指定した場所と同じかもっと右にある未チェックな項を探します。 //! * [`is_checked`](UfChecklist::is_checked): 指定した位置がチェック済みかどうかを判定します。 //! //! diff --git a/libs/union_find/src/lib.rs b/libs/union_find/src/lib.rs index a61ccfdf..2000e287 100644 --- a/libs/union_find/src/lib.rs +++ b/libs/union_find/src/lib.rs @@ -184,7 +184,7 @@ impl UnionFind { pub fn from_values(values: Vec) -> Self { let n = values.len(); - assert!(n <= std::usize::MAX / 2); + assert!(n <= usize::MAX / 2); Self { parent_or_size: vec![-1; n], values, diff --git a/libs/wavelet_matrix/src/lib.rs b/libs/wavelet_matrix/src/lib.rs index dbc9d823..8d90bcb7 100644 --- a/libs/wavelet_matrix/src/lib.rs +++ b/libs/wavelet_matrix/src/lib.rs @@ -37,8 +37,8 @@ //! - 制約: N, Q ≤ 100,000 //! - 使用するメソッド: [`range_freq`](WaveletMatrix::range_freq) //! - コメント: 様々な解法があるよう。 -//! [こちらのブログ](https://blog.hamayanhamayan.com/entry/2017/06/13/103254) -//! に各種手法お名前だけ言及ありです。 +//! [こちらのブログ](https://blog.hamayanhamayan.com/entry/2017/06/13/103254) +//! に各種手法お名前だけ言及ありです。 //! - yukicoder No.738 - 平らな農地 //! - 問題: //! - 提出 (895 ms): @@ -46,10 +46,10 @@ //! - 難易度: そこそこ。 //! - 制約: N, Q ≤ 100,000 //! - 使用するメソッド: [`range_freq`](WaveletMatrix::range_freq), -//! [`spans`](WaveletMatrix::spans) +//! [`spans`](WaveletMatrix::spans) //! - コメント: ヒープ4本でも解けてそちらのほうが一般的? -//! ウェーブレット行列を使うなら累積和が必要で、ちょっと面倒です。 -//! ([自由度の高いメソッド `spans` が活躍します。](WaveletMatrix::spans)) +//! ウェーブレット行列を使うなら累積和が必要で、ちょっと面倒です。 +//! ([自由度の高いメソッド `spans` が活躍します。](WaveletMatrix::spans)) //! - yukicoder No.919 - You Are A Project Manager //! - 問題: //! - 提出 (256 ms): @@ -57,7 +57,7 @@ //! - 難易度: そこそこ。 //! - 制約: N, Q ≤ 100,000 //! - 使用するメソッド: [`range_freq`](WaveletMatrix::range_freq), -//! [`spans`](WaveletMatrix::spans) +//! [`spans`](WaveletMatrix::spans) //! - コメント: Mo でもできて、それもそれできれいです。 //! - Library Checker - Range Kth Smallest //! - 問題: @@ -73,7 +73,7 @@ //! - 難易度: 簡単。 //! - 制約: N ≤ 100,000 //! - 使う構造体: [`quantile`](WaveletMatrix::quantile), -//! [`range_freq`](WaveletMatrix::range_freq) +//! [`range_freq`](WaveletMatrix::range_freq) //! - 他の解法: //! - ヒープ4本 (90 ms): //! - コメント: ヒープ4本のほうが楽です。 diff --git a/libs/zeta/src/lib.rs b/libs/zeta/src/lib.rs index 3f8dabb5..032656ae 100644 --- a/libs/zeta/src/lib.rs +++ b/libs/zeta/src/lib.rs @@ -231,17 +231,17 @@ mod tests { #[allow(clippy::unused_unit)] #[test_case(Add::add, 0, add, Dir::Sub)] - #[test_case(cmp::max, std::u32::MIN, max, Dir::Sub)] - #[test_case(cmp::min, std::u32::MAX, min, Dir::Sub)] + #[test_case(cmp::max, u32::MIN, max, Dir::Sub)] + #[test_case(cmp::min, u32::MAX, min, Dir::Sub)] #[test_case(BitXor::bitxor, 0, bitxor, Dir::Sub)] #[test_case(BitOr::bitor, 0, bitor, Dir::Sub)] - #[test_case(BitAnd::bitand, std::u32::MAX, bitand, Dir::Sub)] + #[test_case(BitAnd::bitand, u32::MAX, bitand, Dir::Sub)] #[test_case(Add::add, 0, radd, Dir::Super)] - #[test_case(cmp::max, std::u32::MIN, rmax, Dir::Super)] - #[test_case(cmp::min, std::u32::MAX, rmin, Dir::Super)] + #[test_case(cmp::max, u32::MIN, rmax, Dir::Super)] + #[test_case(cmp::min, u32::MAX, rmin, Dir::Super)] #[test_case(BitXor::bitxor, 0, rbitxor, Dir::Super)] #[test_case(BitOr::bitor, 0, rbitor, Dir::Super)] - #[test_case(BitAnd::bitand, std::u32::MAX, rbitand, Dir::Super)] + #[test_case(BitAnd::bitand, u32::MAX, rbitand, Dir::Super)] fn test_zeta_ops(f: fn(u32, u32) -> u32, e: u32, g: fn(&mut [u32]), dir: Dir) { let mut rng = StdRng::seed_from_u64(42); for _ in 0..20 { @@ -272,11 +272,11 @@ mod tests { #[allow(clippy::unused_unit)] #[test_case(Add::add, 0)] - #[test_case(cmp::max, std::u32::MIN)] - #[test_case(cmp::min, std::u32::MAX)] + #[test_case(cmp::max, u32::MIN)] + #[test_case(cmp::min, u32::MAX)] #[test_case(BitXor::bitxor, 0)] #[test_case(BitOr::bitor, 0)] - #[test_case(BitAnd::bitand, std::u32::MAX)] + #[test_case(BitAnd::bitand, u32::MAX)] fn test_aggr(f: fn(u32, u32) -> u32, e: u32) { let mut rng = StdRng::seed_from_u64(42); for _ in 0..20 { diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 22048ac5..2e2b8c85 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,2 +1,2 @@ [toolchain] -channel = "1.70.0" +channel = "1.82.0"