Skip to content

Commit 68e43d3

Browse files
committed
Add rust clippy
1 parent 80e09a9 commit 68e43d3

File tree

20 files changed

+41
-55
lines changed

20 files changed

+41
-55
lines changed

.github/workflows/rust.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ jobs:
1414
run: |
1515
cd rust
1616
cargo fmt -- --check
17+
RUSTFLAGS="-A unused" cargo clippy
18+
cargo clippy --tests
1719
- name: compile
1820
run: |
1921
cd rust

rust/Cargo.toml

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,7 @@ version = "0.1.0"
55
edition = "2021"
66

77
[dev-dependencies]
8-
rstest="0.21.0"
8+
rstest="0.22.0"
99

10-
[[bin]]
11-
name = "permutations"
12-
path = "combinatorics/permutations.rs"
13-
14-
[[bin]]
15-
name = "topological_sort"
16-
path = "graphs/dfs/topological_sort.rs"
17-
18-
[[bin]]
19-
name = "dijkstra"
20-
path = "graphs/shortestpaths/dijkstra.rs"
21-
22-
[[bin]]
23-
name = "max_bipartite_matching_EV"
24-
path = "graphs/matchings/max_bipartite_matching_EV.rs"
25-
26-
[[bin]]
27-
name = "euclid"
28-
path = "numbertheory/euclid.rs"
29-
30-
[[bin]]
31-
name = "disjoint_sets"
32-
path = "structures/disjoint_sets.rs"
33-
34-
[[bin]]
35-
name = "fenwick_tree"
36-
path = "structures/fenwick_tree.rs"
37-
38-
[[bin]]
39-
name = "persistent_tree"
40-
path = "structures/persistent_tree.rs"
41-
42-
[[bin]]
43-
name = "binary_search"
44-
path = "misc/binary_search.rs"
10+
[lib]
11+
path = "lib.rs"

rust/combinatorics/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod permutations;

rust/combinatorics/permutations.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ pub fn next_permutation(p: &mut [usize]) -> Option<()> {
88

99
#[cfg(test)]
1010
mod tests {
11-
use crate::next_permutation;
1211
use rstest::rstest;
12+
use crate::combinatorics::permutations::next_permutation;
1313

1414
#[rstest]
1515
#[case(vec![0], vec![0], None)]

rust/graphs/dfs/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod topological_sort;

rust/graphs/dfs/topological_sort.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ pub fn topological_sort(graph: &[Vec<usize>]) -> Vec<usize> {
1818
}
1919
}
2020
order.reverse();
21-
return order;
21+
order
2222
}
2323

2424
#[cfg(test)]
2525
mod tests {
26-
use crate::topological_sort;
26+
use crate::graphs::dfs::topological_sort::topological_sort;
2727

2828
#[test]
2929
fn basic_test() {

rust/graphs/matchings/max_bipartite_matching_EV.rs renamed to rust/graphs/matchings/max_bipartite_matching_ev.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
#![feature(test)]
2-
extern crate test;
3-
41
fn find_path(graph: &[Vec<usize>], u1: usize, matching: &mut [usize], vis: &mut [bool]) -> bool {
52
vis[u1] = true;
63
for v in &graph[u1] {
@@ -10,7 +7,7 @@ fn find_path(graph: &[Vec<usize>], u1: usize, matching: &mut [usize], vis: &mut
107
return true;
118
}
129
}
13-
return false;
10+
false
1411
}
1512

1613
pub fn max_matching(graph: &[Vec<usize>], n2: usize) -> (usize, Vec<usize>) {
@@ -23,13 +20,13 @@ pub fn max_matching(graph: &[Vec<usize>], n2: usize) -> (usize, Vec<usize>) {
2320
matches += 1;
2421
}
2522
}
26-
return (matches, matching);
23+
(matches, matching)
2724
}
2825

2926
#[cfg(test)]
3027
mod tests {
31-
use crate::max_matching;
3228
use test::Bencher;
29+
use crate::graphs::matchings::max_bipartite_matching_ev::max_matching;
3330

3431
#[test]
3532
fn basic_test() {

rust/graphs/matchings/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod max_bipartite_matching_ev;

rust/graphs/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub mod dfs;
2+
pub mod matchings;
3+
pub mod shortestpaths;

rust/graphs/shortestpaths/dijkstra.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ pub fn dijkstra_heap(graph: &[Vec<(usize, i32)>], s: usize) -> (Vec<i32>, Vec<us
2222
}
2323
}
2424
}
25-
return (prio, pred);
25+
(prio, pred)
2626
}
2727

2828
#[cfg(test)]
2929
mod tests {
30-
use crate::dijkstra_heap;
30+
use crate::graphs::shortestpaths::dijkstra::dijkstra_heap;
3131

3232
#[test]
3333
fn basic_test() {

rust/graphs/shortestpaths/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod dijkstra;

rust/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#![feature(test)]
2+
extern crate test;
3+
4+
pub mod combinatorics;
5+
pub mod graphs;
6+
pub mod misc;
7+
pub mod numbertheory;
8+
pub mod structures;

rust/misc/binary_search.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ where
1818

1919
#[cfg(test)]
2020
mod tests {
21-
use crate::binary_search_first_true;
2221
use rstest::rstest;
22+
use crate::misc::binary_search::binary_search_first_true;
2323

2424
#[rstest]
2525
#[case(100, 0)]

rust/misc/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod binary_search;

rust/numbertheory/euclid.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
fn gcd(a: i32, b: i32) -> i32 {
2-
return if b == 0 { a.abs() } else { gcd(b, a % b) };
2+
if b == 0 { a.abs() } else { gcd(b, a % b) }
33
}
44

55
// returns { gcd(a,b), x, y } such that gcd(a,b) = a*x + b*y
@@ -21,12 +21,12 @@ fn euclid(mut a: i64, mut b: i64) -> [i64; 3] {
2121
y = _y1;
2222
a = _b;
2323
}
24-
return if a > 0 { [a, x, y] } else { [-a, -x, -y] };
24+
if a > 0 { [a, x, y] } else { [-a, -x, -y] }
2525
}
2626

2727
#[cfg(test)]
2828
mod tests {
29-
use crate::{euclid, gcd};
29+
use crate::numbertheory::euclid::{euclid, gcd};
3030

3131
#[test]
3232
fn basic_test() {

rust/numbertheory/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod euclid;

rust/structures/disjoint_sets.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ impl DisjointSets {
2525

2626
#[cfg(test)]
2727
mod tests {
28-
use crate::DisjointSets;
28+
use crate::structures::disjoint_sets::DisjointSets;
2929

3030
#[test]
3131
fn basic_test() {

rust/structures/fenwick_tree.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ impl<T: AddAssign + Copy + From<i32>> Fenwick<T> {
2525
res += self.t[i as usize];
2626
i = (i & (i + 1)) - 1;
2727
}
28-
return res;
28+
res
2929
}
3030
}
3131

3232
#[cfg(test)]
3333
mod tests {
34-
use crate::Fenwick;
34+
use crate::structures::fenwick_tree::Fenwick;
3535

3636
#[test]
3737
fn basic_test() {

rust/structures/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub mod disjoint_sets;
2+
pub mod fenwick_tree;
3+
pub mod persistent_tree;

rust/structures/persistent_tree.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ impl PersistentTree {
7171

7272
#[cfg(test)]
7373
mod tests {
74-
use crate::PersistentTree;
74+
use crate::structures::persistent_tree::PersistentTree;
7575

7676
#[test]
7777
fn basic_test() {

0 commit comments

Comments
 (0)