Skip to content

style: include legacy_numeric_constants #755

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -165,5 +165,3 @@ suspicious_operation_groupings = { level = "allow", priority = 1 }
use_self = { level = "allow", priority = 1 }
# cargo-lints:
cargo_common_metadata = { level = "allow", priority = 1 }
# style-lints:
legacy_numeric_constants = { level = "allow", priority = 1 }
2 changes: 1 addition & 1 deletion src/dynamic_programming/egg_dropping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub fn egg_drop(eggs: u32, floors: u32) -> u32 {
// Complete solutions vector using optimal substructure property
for i in 2..=eggs_index {
for j in 2..=floors_index {
egg_drops[i][j] = std::u32::MAX;
egg_drops[i][j] = u32::MAX;

for k in 1..=j {
let res = 1 + std::cmp::max(egg_drops[i - 1][k - 1], egg_drops[i][j - k]);
Expand Down
3 changes: 1 addition & 2 deletions src/general/kmeans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ macro_rules! impl_kmeans {
($kind: ty, $modname: ident) => {
// Since we can't overload methods in rust, we have to use namespacing
pub mod $modname {
use std::$modname::INFINITY;

/// computes sum of squared deviation between two identically sized vectors
/// `x`, and `y`.
Expand All @@ -22,7 +21,7 @@ macro_rules! impl_kmeans {
// Find the argmin by folding using a tuple containing the argmin
// and the minimum distance.
let (argmin, _) = centroids.iter().enumerate().fold(
(0_usize, INFINITY),
(0_usize, <$kind>::INFINITY),
|(min_ix, min_dist), (ix, ci)| {
let dist = distance(xi, ci);
if dist < min_dist {
Expand Down
12 changes: 6 additions & 6 deletions src/graph/bipartite_matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,24 @@ impl BipartiteMatching {
// else set the vertex distance as infinite because it is matched
// this will be considered the next time

*d_i = i32::max_value();
*d_i = i32::MAX;
}
}
dist[0] = i32::max_value();
dist[0] = i32::MAX;
while !q.is_empty() {
let u = *q.front().unwrap();
q.pop_front();
if dist[u] < dist[0] {
for i in 0..self.adj[u].len() {
let v = self.adj[u][i];
if dist[self.mt2[v] as usize] == i32::max_value() {
if dist[self.mt2[v] as usize] == i32::MAX {
dist[self.mt2[v] as usize] = dist[u] + 1;
q.push_back(self.mt2[v] as usize);
}
}
}
}
dist[0] != i32::max_value()
dist[0] != i32::MAX
}
fn dfs(&mut self, u: i32, dist: &mut Vec<i32>) -> bool {
if u == 0 {
Expand All @@ -105,14 +105,14 @@ impl BipartiteMatching {
return true;
}
}
dist[u as usize] = i32::max_value();
dist[u as usize] = i32::MAX;
false
}
pub fn hopcroft_karp(&mut self) -> i32 {
// NOTE: how to use: https://cses.fi/paste/7558dba8d00436a847eab8/
self.mt2 = vec![0; self.num_vertices_grp2 + 1];
self.mt1 = vec![0; self.num_vertices_grp1 + 1];
let mut dist = vec![i32::max_value(); self.num_vertices_grp1 + 1];
let mut dist = vec![i32::MAX; self.num_vertices_grp1 + 1];
let mut res = 0;
while self.bfs(&mut dist) {
for u in 1..self.num_vertices_grp1 + 1 {
Expand Down
8 changes: 4 additions & 4 deletions src/graph/disjoint_set_union.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ impl DisjointSetUnion {
self.nodes[v].parent
}
// Returns the new component of the merged sets,
// or std::usize::MAX if they were the same.
// or usize::MAX if they were the same.
pub fn merge(&mut self, u: usize, v: usize) -> usize {
let mut a = self.find_set(u);
let mut b = self.find_set(v);
if a == b {
return std::usize::MAX;
return usize::MAX;
}
if self.nodes[a].size < self.nodes[b].size {
std::mem::swap(&mut a, &mut b);
Expand Down Expand Up @@ -79,11 +79,11 @@ mod tests {
];
let mut added_edges: Vec<(usize, usize)> = Vec::new();
for (u, v) in edges {
if dsu.merge(u, v) < std::usize::MAX {
if dsu.merge(u, v) < usize::MAX {
added_edges.push((u, v));
}
// Now they should be the same
assert!(dsu.merge(u, v) == std::usize::MAX);
assert!(dsu.merge(u, v) == usize::MAX);
}
assert_eq!(added_edges, expected_edges);
let comp_1 = dsu.find_set(1);
Expand Down
2 changes: 1 addition & 1 deletion src/graph/minimum_spanning_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub fn kruskal(mut edges: Vec<Edge>, number_of_vertices: i64) -> (i64, Vec<Edge>

let source: i64 = edge.source;
let destination: i64 = edge.destination;
if dsu.merge(source as usize, destination as usize) < std::usize::MAX {
if dsu.merge(source as usize, destination as usize) < usize::MAX {
merge_count += 1;
let cost: i64 = edge.cost;
total_cost += cost;
Expand Down