Skip to content

Commit

Permalink
Merge pull request #558 from evenfurther/usize-max
Browse files Browse the repository at this point in the history
chore: replace usize::max_value() by usize::MAX
  • Loading branch information
samueltardieu committed May 3, 2024
2 parents b695b57 + 838504f commit 5813a36
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 14 deletions.
1 change: 0 additions & 1 deletion benches/algos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use rand::prelude::SliceRandom;
use rand::{Rng, RngCore, SeedableRng};
use rand_xorshift::XorShiftRng;
use std::collections::HashSet;
use std::usize;

#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
struct Pt {
Expand Down
3 changes: 1 addition & 2 deletions src/directed/astar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use std::cmp::Ordering;
use std::collections::{BinaryHeap, HashSet};
use std::hash::Hash;
use std::iter::FusedIterator;
use std::usize;

use super::reverse_path;
use crate::FxIndexMap;
Expand Down Expand Up @@ -100,7 +99,7 @@ where
index: 0,
});
let mut parents: FxIndexMap<N, (usize, C)> = FxIndexMap::default();
parents.insert(start.clone(), (usize::max_value(), Zero::zero()));
parents.insert(start.clone(), (usize::MAX, Zero::zero()));
while let Some(SmallestCostHolder { cost, index, .. }) = to_see.pop() {
let successors = {
let (node, &(_, c)) = parents.get_index(index).unwrap(); // Cannot fail
Expand Down
3 changes: 1 addition & 2 deletions src/directed/bfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::{FxIndexMap, FxIndexSet};
use indexmap::map::Entry::Vacant;
use std::hash::Hash;
use std::iter::FusedIterator;
use std::usize;

/// Compute a shortest path using the [breadth-first search
/// algorithm](https://en.wikipedia.org/wiki/Breadth-first_search).
Expand Down Expand Up @@ -90,7 +89,7 @@ where
}
let mut i = 0;
let mut parents: FxIndexMap<N, usize> = FxIndexMap::default();
parents.insert(start.clone(), usize::max_value());
parents.insert(start.clone(), usize::MAX);
while let Some((node, _)) = parents.get_index(i) {
for successor in successors(node) {
if success(&successor) {
Expand Down
5 changes: 2 additions & 3 deletions src/directed/dijkstra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use rustc_hash::{FxHashMap, FxHashSet};
use std::cmp::Ordering;
use std::collections::{BinaryHeap, HashMap};
use std::hash::Hash;
use std::usize;

/// Compute a shortest path using the [Dijkstra search
/// algorithm](https://en.wikipedia.org/wiki/Dijkstra's_algorithm).
Expand Down Expand Up @@ -211,7 +210,7 @@ where
index: 0,
});
let mut parents: FxIndexMap<N, (usize, C)> = FxIndexMap::default();
parents.insert(start.clone(), (usize::max_value(), Zero::zero()));
parents.insert(start.clone(), (usize::MAX, Zero::zero()));
let mut target_reached = None;
while let Some(SmallestHolder { cost, index }) = to_see.pop() {
let successors = {
Expand Down Expand Up @@ -416,7 +415,7 @@ where
});

let mut parents: FxIndexMap<N, (usize, C)> = FxIndexMap::default();
parents.insert(start.clone(), (usize::max_value(), Zero::zero()));
parents.insert(start.clone(), (usize::MAX, Zero::zero()));

let mut total_costs = FxHashMap::default();
total_costs.insert(start.clone(), Zero::zero());
Expand Down
3 changes: 1 addition & 2 deletions src/directed/fringe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use num_traits::{Bounded, Zero};
use std::collections::VecDeque;
use std::hash::Hash;
use std::mem;
use std::usize;

/// Compute a shortest path using the [Fringe search
/// algorithm](https://en.wikipedia.org/wiki/Fringe_search).
Expand Down Expand Up @@ -98,7 +97,7 @@ where
let mut parents: FxIndexMap<N, (usize, C)> = FxIndexMap::default();
let mut flimit = heuristic(start);
now.push_back(0);
parents.insert(start.clone(), (usize::max_value(), Zero::zero()));
parents.insert(start.clone(), (usize::MAX, Zero::zero()));

loop {
if now.is_empty() {
Expand Down
5 changes: 2 additions & 3 deletions src/undirected/connected_components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::collections::hash_map::Entry::{Occupied, Vacant};
use std::collections::{HashMap, HashSet};
use std::hash::Hash;
use std::iter::once;
use std::usize;

fn join(table: &mut [usize], mut rx: usize, mut ry: usize) -> usize {
while table[rx] != table[ry] {
Expand Down Expand Up @@ -66,7 +65,7 @@ where
let mut indices = HashMap::new();
for (mut group_index, group) in groups.iter().enumerate() {
if group.is_empty() {
table[group_index] = usize::max_value();
table[group_index] = usize::MAX;
}
for element in group {
match indices.entry(element) {
Expand Down Expand Up @@ -108,7 +107,7 @@ where
let mut gb = gindices
.into_iter()
.enumerate()
.filter(|&(_, n)| n != usize::max_value())
.filter(|&(_, n)| n != usize::MAX)
.collect::<Vec<_>>();
gb.sort_unstable_by(|&(_, n1), &(_, n2)| Ord::cmp(&n1, &n2));
let mut key = None;
Expand Down
1 change: 0 additions & 1 deletion tests/connected-components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use pathfinding::undirected::connected_components::*;
use rand::prelude::*;
use rand_xorshift::XorShiftRng;
use std::collections::HashSet;
use std::usize;

#[test]
fn basic_separate_components() {
Expand Down

0 comments on commit 5813a36

Please sign in to comment.