Skip to content

Commit afdb283

Browse files
authored
style: include legacy_numeric_constants (#755)
1 parent f164e81 commit afdb283

File tree

6 files changed

+13
-16
lines changed

6 files changed

+13
-16
lines changed

Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,5 +165,3 @@ suspicious_operation_groupings = { level = "allow", priority = 1 }
165165
use_self = { level = "allow", priority = 1 }
166166
# cargo-lints:
167167
cargo_common_metadata = { level = "allow", priority = 1 }
168-
# style-lints:
169-
legacy_numeric_constants = { level = "allow", priority = 1 }

src/dynamic_programming/egg_dropping.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub fn egg_drop(eggs: u32, floors: u32) -> u32 {
3535
// Complete solutions vector using optimal substructure property
3636
for i in 2..=eggs_index {
3737
for j in 2..=floors_index {
38-
egg_drops[i][j] = std::u32::MAX;
38+
egg_drops[i][j] = u32::MAX;
3939

4040
for k in 1..=j {
4141
let res = 1 + std::cmp::max(egg_drops[i - 1][k - 1], egg_drops[i][j - k]);

src/general/kmeans.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ macro_rules! impl_kmeans {
44
($kind: ty, $modname: ident) => {
55
// Since we can't overload methods in rust, we have to use namespacing
66
pub mod $modname {
7-
use std::$modname::INFINITY;
87

98
/// computes sum of squared deviation between two identically sized vectors
109
/// `x`, and `y`.
@@ -22,7 +21,7 @@ macro_rules! impl_kmeans {
2221
// Find the argmin by folding using a tuple containing the argmin
2322
// and the minimum distance.
2423
let (argmin, _) = centroids.iter().enumerate().fold(
25-
(0_usize, INFINITY),
24+
(0_usize, <$kind>::INFINITY),
2625
|(min_ix, min_dist), (ix, ci)| {
2726
let dist = distance(xi, ci);
2827
if dist < min_dist {

src/graph/bipartite_matching.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,24 +74,24 @@ impl BipartiteMatching {
7474
// else set the vertex distance as infinite because it is matched
7575
// this will be considered the next time
7676

77-
*d_i = i32::max_value();
77+
*d_i = i32::MAX;
7878
}
7979
}
80-
dist[0] = i32::max_value();
80+
dist[0] = i32::MAX;
8181
while !q.is_empty() {
8282
let u = *q.front().unwrap();
8383
q.pop_front();
8484
if dist[u] < dist[0] {
8585
for i in 0..self.adj[u].len() {
8686
let v = self.adj[u][i];
87-
if dist[self.mt2[v] as usize] == i32::max_value() {
87+
if dist[self.mt2[v] as usize] == i32::MAX {
8888
dist[self.mt2[v] as usize] = dist[u] + 1;
8989
q.push_back(self.mt2[v] as usize);
9090
}
9191
}
9292
}
9393
}
94-
dist[0] != i32::max_value()
94+
dist[0] != i32::MAX
9595
}
9696
fn dfs(&mut self, u: i32, dist: &mut Vec<i32>) -> bool {
9797
if u == 0 {
@@ -105,14 +105,14 @@ impl BipartiteMatching {
105105
return true;
106106
}
107107
}
108-
dist[u as usize] = i32::max_value();
108+
dist[u as usize] = i32::MAX;
109109
false
110110
}
111111
pub fn hopcroft_karp(&mut self) -> i32 {
112112
// NOTE: how to use: https://cses.fi/paste/7558dba8d00436a847eab8/
113113
self.mt2 = vec![0; self.num_vertices_grp2 + 1];
114114
self.mt1 = vec![0; self.num_vertices_grp1 + 1];
115-
let mut dist = vec![i32::max_value(); self.num_vertices_grp1 + 1];
115+
let mut dist = vec![i32::MAX; self.num_vertices_grp1 + 1];
116116
let mut res = 0;
117117
while self.bfs(&mut dist) {
118118
for u in 1..self.num_vertices_grp1 + 1 {

src/graph/disjoint_set_union.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ impl DisjointSetUnion {
2626
self.nodes[v].parent
2727
}
2828
// Returns the new component of the merged sets,
29-
// or std::usize::MAX if they were the same.
29+
// or usize::MAX if they were the same.
3030
pub fn merge(&mut self, u: usize, v: usize) -> usize {
3131
let mut a = self.find_set(u);
3232
let mut b = self.find_set(v);
3333
if a == b {
34-
return std::usize::MAX;
34+
return usize::MAX;
3535
}
3636
if self.nodes[a].size < self.nodes[b].size {
3737
std::mem::swap(&mut a, &mut b);
@@ -79,11 +79,11 @@ mod tests {
7979
];
8080
let mut added_edges: Vec<(usize, usize)> = Vec::new();
8181
for (u, v) in edges {
82-
if dsu.merge(u, v) < std::usize::MAX {
82+
if dsu.merge(u, v) < usize::MAX {
8383
added_edges.push((u, v));
8484
}
8585
// Now they should be the same
86-
assert!(dsu.merge(u, v) == std::usize::MAX);
86+
assert!(dsu.merge(u, v) == usize::MAX);
8787
}
8888
assert_eq!(added_edges, expected_edges);
8989
let comp_1 = dsu.find_set(1);

src/graph/minimum_spanning_tree.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub fn kruskal(mut edges: Vec<Edge>, number_of_vertices: i64) -> (i64, Vec<Edge>
4141

4242
let source: i64 = edge.source;
4343
let destination: i64 = edge.destination;
44-
if dsu.merge(source as usize, destination as usize) < std::usize::MAX {
44+
if dsu.merge(source as usize, destination as usize) < usize::MAX {
4545
merge_count += 1;
4646
let cost: i64 = edge.cost;
4747
total_cost += cost;

0 commit comments

Comments
 (0)