Skip to content

Commit

Permalink
feat!(Cargo): update edition to 2024 and MSRV to 1.85.0
Browse files Browse the repository at this point in the history
Source files have been reformatted according to the 2024 edition
standard.
  • Loading branch information
samueltardieu committed Jan 3, 2025
1 parent 637392a commit 9d88d1a
Show file tree
Hide file tree
Showing 27 changed files with 275 additions and 308 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ version = "4.13.0"
authors = ["Samuel Tardieu <[email protected]>"]
categories = ["algorithms"]
readme = "README.md"
edition = "2021"
rust-version = "1.83.0"
edition = "2024"
rust-version = "1.85.0"

[package.metadata.release]
sign-commit = true
Expand Down
2 changes: 1 addition & 1 deletion benches/algos-fill.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// This version uses a filler in the Pt structure to increase
// the cost of cloning a node.

use codspeed_criterion_compat::{criterion_group, criterion_main, Criterion};
use codspeed_criterion_compat::{Criterion, criterion_group, criterion_main};
use pathfinding::prelude::{astar, bfs, dfs, dijkstra, fringe, idastar, iddfs};

#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
Expand Down
2 changes: 1 addition & 1 deletion benches/algos.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use codspeed_criterion_compat::{criterion_group, criterion_main, Criterion};
use codspeed_criterion_compat::{Criterion, criterion_group, criterion_main};
use itertools::Itertools;
use pathfinding::prelude::{
astar, bfs, dfs, dijkstra, fringe, idastar, iddfs, separate_components,
Expand Down
4 changes: 2 additions & 2 deletions benches/edmondskarp.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use codspeed_criterion_compat::{criterion_group, criterion_main, Criterion};
use codspeed_criterion_compat::{Criterion, criterion_group, criterion_main};
use pathfinding::directed::edmonds_karp::{
edmonds_karp, DenseCapacity, EKFlows, EdmondsKarp, SparseCapacity,
DenseCapacity, EKFlows, EdmondsKarp, SparseCapacity, edmonds_karp,
};
use std::collections::HashMap;

Expand Down
4 changes: 2 additions & 2 deletions benches/kuhn_munkres.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use codspeed_criterion_compat::{criterion_group, criterion_main, BenchmarkId, Criterion};
use pathfinding::prelude::{kuhn_munkres, Matrix};
use codspeed_criterion_compat::{BenchmarkId, Criterion, criterion_group, criterion_main};
use pathfinding::prelude::{Matrix, kuhn_munkres};
use rand::{Rng, SeedableRng};
use rand_xorshift::XorShiftRng;

Expand Down
2 changes: 1 addition & 1 deletion benches/matrices.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use codspeed_criterion_compat::{criterion_group, criterion_main, Criterion};
use codspeed_criterion_compat::{Criterion, criterion_group, criterion_main};
use pathfinding::matrix::Matrix;

#[expect(clippy::missing_panics_doc)]
Expand Down
2 changes: 1 addition & 1 deletion benches/movingai.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Test with files from https://movingai.com/benchmarks/

use codspeed_criterion_compat::{criterion_group, criterion_main, Criterion};
use codspeed_criterion_compat::{Criterion, criterion_group, criterion_main};
use movingai::parser::{parse_map_file, parse_scen_file};
use movingai::{Coords2D, Map2D};
use noisy_float::prelude::*;
Expand Down
4 changes: 2 additions & 2 deletions benches/separate_components.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use codspeed_criterion_compat::{criterion_group, criterion_main, Criterion};
use codspeed_criterion_compat::{Criterion, criterion_group, criterion_main};
use itertools::Itertools;
use pathfinding::prelude::separate_components;
use rand::{prelude::SliceRandom, Rng, RngCore, SeedableRng};
use rand::{Rng, RngCore, SeedableRng, prelude::SliceRandom};
use rand_xorshift::XorShiftRng;
use std::collections::HashSet;

Expand Down
2 changes: 1 addition & 1 deletion src/directed/dijkstra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ where
reached.map(|target| {
(
reverse_path(&parents, |&(p, _)| p, target),
parents.get_index(target).unwrap().1 .1,
parents.get_index(target).unwrap().1.1,
)
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/directed/edmonds_karp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
//! edges.
use super::bfs::bfs;
use crate::{matrix::Matrix, FxIndexSet};
use crate::{FxIndexSet, matrix::Matrix};
use num_traits::{Bounded, Signed, Zero};
use std::collections::{BTreeMap, BTreeSet, VecDeque};
use std::hash::Hash;
Expand Down
2 changes: 1 addition & 1 deletion src/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
//! without diagonal links.
use super::matrix::Matrix;
use crate::FxIndexSet;
use crate::directed::bfs::bfs_reach;
use crate::directed::dfs::dfs_reach;
use crate::utils::constrain;
use crate::FxIndexSet;
use num_traits::ToPrimitive;
use std::collections::BTreeSet;
use std::fmt;
Expand Down
2 changes: 1 addition & 1 deletion src/kuhn_munkres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! [Kuhn-Munkres algorithm](https://en.wikipedia.org/wiki/Hungarian_algorithm)
//! (also known as Hungarian algorithm).
use crate::{matrix::Matrix, FxIndexSet};
use crate::{FxIndexSet, matrix::Matrix};
use num_traits::{Bounded, Signed, Zero};
use std::iter::Sum;

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
//! in this context, you can wrap them into compliant types using the
//! [ordered-float](https://crates.io/crates/ordered-float) crate.
//!
//! The minimum supported Rust version (MSRV) is Rust 1.83.0.
//! The minimum supported Rust version (MSRV) is Rust 1.85.0.
//!
//! [A*]: https://en.wikipedia.org/wiki/A*_search_algorithm
//! [BFS]: https://en.wikipedia.org/wiki/Breadth-first_search
Expand Down
15 changes: 6 additions & 9 deletions tests/astar_bag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,12 @@ fn multiple_sinks() {
)
.unwrap();
assert_eq!(cost, 4);
assert_eq!(
solutions.sorted().collect_vec(),
vec![
vec![1, 2, 4],
vec![1, 2, 5, 6, 7],
vec![1, 3, 4],
vec![1, 3, 5, 6, 7],
]
);
assert_eq!(solutions.sorted().collect_vec(), vec![
vec![1, 2, 4],
vec![1, 2, 5, 6, 7],
vec![1, 3, 4],
vec![1, 3, 5, 6, 7],
]);
}

#[test]
Expand Down
10 changes: 3 additions & 7 deletions tests/cliques.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,9 @@ fn test_same_node_appears_in_multiple_clique() {
let cliques_as_vectors: Vec<Vec<i32>> = sort(&cliques);

assert_eq!(
vec![
vec![1, 5, 9],
vec![2, 6],
vec![3, 6, 9],
vec![3, 7],
vec![4, 8]
],
vec![vec![1, 5, 9], vec![2, 6], vec![3, 6, 9], vec![3, 7], vec![
4, 8
]],
cliques_as_vectors
);
}
Expand Down
28 changes: 12 additions & 16 deletions tests/connected-components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ fn basic_components() {
let mut c = components(&[vec![1, 2], vec![3, 4], vec![5, 6], vec![1, 4, 7]]);
c.sort_unstable_by_key(|v| *v.iter().min().unwrap());
assert_eq!(c.len(), 2);
assert_eq!(
c[0].clone().into_iter().sorted().collect_vec(),
vec![1, 2, 3, 4, 7]
);
assert_eq!(c[0].clone().into_iter().sorted().collect_vec(), vec![
1, 2, 3, 4, 7
]);
assert_eq!(c[1].clone().into_iter().sorted().collect_vec(), vec![5, 6]);
}

Expand All @@ -48,10 +47,9 @@ fn empty_components() {
let mut c = components(&[vec![1, 2], vec![3, 4], vec![], vec![1, 4, 7]]);
c.sort_unstable_by_key(|v| *v.iter().min().unwrap());
assert_eq!(c.len(), 1);
assert_eq!(
c[0].clone().into_iter().sorted().collect_vec(),
vec![1, 2, 3, 4, 7]
);
assert_eq!(c[0].clone().into_iter().sorted().collect_vec(), vec![
1, 2, 3, 4, 7
]);
}

#[test]
Expand All @@ -67,14 +65,12 @@ fn basic_connected_components() {
});
c.sort_unstable_by_key(|v| *v.iter().min().unwrap());
assert_eq!(c.len(), 2);
assert_eq!(
c[0].clone().into_iter().sorted().collect_vec(),
vec![1, 3, 5, 7]
);
assert_eq!(
c[1].clone().into_iter().sorted().collect_vec(),
vec![2, 4, 6, 8]
);
assert_eq!(c[0].clone().into_iter().sorted().collect_vec(), vec![
1, 3, 5, 7
]);
assert_eq!(c[1].clone().into_iter().sorted().collect_vec(), vec![
2, 4, 6, 8
]);
assert_eq!(counter, 2);
}

Expand Down
7 changes: 5 additions & 2 deletions tests/dijkstra-all.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use pathfinding::prelude::*;
use rand::{rngs, Rng};
use rand::{Rng, rngs};

fn build_network(size: usize) -> Matrix<usize> {
let mut network = Matrix::new(size, size, 0);
Expand Down Expand Up @@ -52,7 +52,10 @@ fn all_paths() {
let other_path = build_path(&target, &paths);
// There might be several paths, but we know that internally we use the
// same algorithm so the comparison holds.
assert_eq!(path, other_path, "path {start} -> {target} differ in {network:?}: {path:?} vs {other_path:?}");
assert_eq!(
path, other_path,
"path {start} -> {target} differ in {network:?}: {path:?} vs {other_path:?}"
);
}
} else {
assert!(
Expand Down
14 changes: 8 additions & 6 deletions tests/dijkstra-reach.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use itertools::Itertools;
use pathfinding::prelude::{dijkstra_reach, DijkstraReachableItem};
use pathfinding::prelude::{DijkstraReachableItem, dijkstra_reach};
use std::collections::HashMap;

#[test]
Expand All @@ -12,11 +12,13 @@ fn dijkstra_reach_numbers() {
assert!((0..100).all(|x| reach.iter().any(|y| x == y.total_cost)));

// dijkstra_reach should return reachable nodes in order of cost
assert!(reach
.iter()
.map(|x| x.total_cost)
.tuple_windows()
.all(|(a, b)| b >= a));
assert!(
reach
.iter()
.map(|x| x.total_cost)
.tuple_windows()
.all(|(a, b)| b >= a)
);
}

#[test]
Expand Down
102 changes: 48 additions & 54 deletions tests/grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,16 @@ fn diagonal_mode() {
g.enable_diagonal_mode();
let mut ns = g.neighbours((1, 1));
ns.sort_unstable();
assert_eq!(
ns,
vec![
(0, 0),
(0, 1),
(0, 2),
(1, 0),
(1, 2),
(2, 0),
(2, 1),
(2, 2),
]
);
assert_eq!(ns, vec![
(0, 0),
(0, 1),
(0, 2),
(1, 0),
(1, 2),
(2, 0),
(2, 1),
(2, 2),
]);
g.disable_diagonal_mode();
let mut ns = g.neighbours((1, 1));
ns.sort_unstable();
Expand Down Expand Up @@ -290,10 +287,13 @@ fn neighbours_of_border() {
g.enable_diagonal_mode();
assert_eq!(g.neighbours((2, 1)), vec![]);
g.fill();
assert_eq!(
sort(g.neighbours((2, 1))),
vec![(1, 0), (1, 1), (1, 2), (2, 0), (2, 2)]
);
assert_eq!(sort(g.neighbours((2, 1))), vec![
(1, 0),
(1, 1),
(1, 2),
(2, 0),
(2, 2)
]);
g.disable_diagonal_mode();
assert_eq!(sort(g.neighbours((2, 1))), vec![(1, 1), (2, 0), (2, 2)]);

Expand All @@ -302,10 +302,13 @@ fn neighbours_of_border() {
g.enable_diagonal_mode();
assert_eq!(g.neighbours((1, 2)), vec![]);
g.fill();
assert_eq!(
sort(g.neighbours((1, 2))),
vec![(0, 1), (0, 2), (1, 1), (2, 1), (2, 2)]
);
assert_eq!(sort(g.neighbours((1, 2))), vec![
(0, 1),
(0, 2),
(1, 1),
(2, 1),
(2, 2)
]);
g.disable_diagonal_mode();
assert_eq!(sort(g.neighbours((1, 2))), vec![(0, 2), (1, 1), (2, 2)]);
}
Expand Down Expand Up @@ -467,47 +470,38 @@ fn edges() {
g.fill();
let mut edges = g.edges().collect::<Vec<_>>();
edges.sort_unstable();
assert_eq!(
edges,
vec![
((0, 0), (0, 1)),
((0, 0), (1, 0)),
((0, 1), (1, 1)),
((1, 0), (1, 1))
]
);
assert_eq!(edges, vec![
((0, 0), (0, 1)),
((0, 0), (1, 0)),
((0, 1), (1, 1)),
((1, 0), (1, 1))
]);
g.enable_diagonal_mode();
let mut edges = g.edges().collect::<Vec<_>>();
edges.sort_unstable();
assert_eq!(
edges,
vec![
((0, 0), (0, 1)),
((0, 0), (1, 0)),
((0, 0), (1, 1)),
((0, 1), (1, 1)),
((1, 0), (0, 1)),
((1, 0), (1, 1))
]
);
assert_eq!(edges, vec![
((0, 0), (0, 1)),
((0, 0), (1, 0)),
((0, 0), (1, 1)),
((0, 1), (1, 1)),
((1, 0), (0, 1)),
((1, 0), (1, 1))
]);
let mut g = Grid::new(3, 3);
g.fill();
g.remove_vertex((1, 1));
let mut edges = g.edges().collect::<Vec<_>>();
edges.sort_unstable();
assert_eq!(
edges,
vec![
((0, 0), (0, 1)),
((0, 0), (1, 0)),
((0, 1), (0, 2)),
((0, 2), (1, 2)),
((1, 0), (2, 0)),
((1, 2), (2, 2)),
((2, 0), (2, 1)),
((2, 1), (2, 2))
]
);
assert_eq!(edges, vec![
((0, 0), (0, 1)),
((0, 0), (1, 0)),
((0, 1), (0, 2)),
((0, 2), (1, 2)),
((1, 0), (2, 0)),
((1, 2), (2, 2)),
((2, 0), (2, 1)),
((2, 1), (2, 2))
]);
}

#[test]
Expand Down
Loading

0 comments on commit 9d88d1a

Please sign in to comment.