Skip to content
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

Add rust clippy #202

Merged
merged 1 commit into from
Aug 25, 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: 2 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ jobs:
run: |
cd rust
cargo fmt -- --check
RUSTFLAGS="-A unused" cargo clippy
cargo clippy --tests
- name: compile
run: |
cd rust
Expand Down
39 changes: 3 additions & 36 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,7 @@ version = "0.1.0"
edition = "2021"

[dev-dependencies]
rstest="0.21.0"
rstest="0.22.0"

[[bin]]
name = "permutations"
path = "combinatorics/permutations.rs"

[[bin]]
name = "topological_sort"
path = "graphs/dfs/topological_sort.rs"

[[bin]]
name = "dijkstra"
path = "graphs/shortestpaths/dijkstra.rs"

[[bin]]
name = "max_bipartite_matching_EV"
path = "graphs/matchings/max_bipartite_matching_EV.rs"

[[bin]]
name = "euclid"
path = "numbertheory/euclid.rs"

[[bin]]
name = "disjoint_sets"
path = "structures/disjoint_sets.rs"

[[bin]]
name = "fenwick_tree"
path = "structures/fenwick_tree.rs"

[[bin]]
name = "persistent_tree"
path = "structures/persistent_tree.rs"

[[bin]]
name = "binary_search"
path = "misc/binary_search.rs"
[lib]
path = "lib.rs"
1 change: 1 addition & 0 deletions rust/combinatorics/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod permutations;
2 changes: 1 addition & 1 deletion rust/combinatorics/permutations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub fn next_permutation(p: &mut [usize]) -> Option<()> {

#[cfg(test)]
mod tests {
use crate::next_permutation;
use crate::combinatorics::permutations::next_permutation;
use rstest::rstest;

#[rstest]
Expand Down
1 change: 1 addition & 0 deletions rust/graphs/dfs/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod topological_sort;
4 changes: 2 additions & 2 deletions rust/graphs/dfs/topological_sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ pub fn topological_sort(graph: &[Vec<usize>]) -> Vec<usize> {
}
}
order.reverse();
return order;
order
}

#[cfg(test)]
mod tests {
use crate::topological_sort;
use crate::graphs::dfs::topological_sort::topological_sort;

#[test]
fn basic_test() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#![feature(test)]
extern crate test;

fn find_path(graph: &[Vec<usize>], u1: usize, matching: &mut [usize], vis: &mut [bool]) -> bool {
vis[u1] = true;
for v in &graph[u1] {
Expand All @@ -10,7 +7,7 @@ fn find_path(graph: &[Vec<usize>], u1: usize, matching: &mut [usize], vis: &mut
return true;
}
}
return false;
false
}

pub fn max_matching(graph: &[Vec<usize>], n2: usize) -> (usize, Vec<usize>) {
Expand All @@ -23,12 +20,12 @@ pub fn max_matching(graph: &[Vec<usize>], n2: usize) -> (usize, Vec<usize>) {
matches += 1;
}
}
return (matches, matching);
(matches, matching)
}

#[cfg(test)]
mod tests {
use crate::max_matching;
use crate::graphs::matchings::max_bipartite_matching_ev::max_matching;
use test::Bencher;

#[test]
Expand Down
1 change: 1 addition & 0 deletions rust/graphs/matchings/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod max_bipartite_matching_ev;
3 changes: 3 additions & 0 deletions rust/graphs/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod dfs;
pub mod matchings;
pub mod shortestpaths;
4 changes: 2 additions & 2 deletions rust/graphs/shortestpaths/dijkstra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ pub fn dijkstra_heap(graph: &[Vec<(usize, i32)>], s: usize) -> (Vec<i32>, Vec<us
}
}
}
return (prio, pred);
(prio, pred)
}

#[cfg(test)]
mod tests {
use crate::dijkstra_heap;
use crate::graphs::shortestpaths::dijkstra::dijkstra_heap;

#[test]
fn basic_test() {
Expand Down
1 change: 1 addition & 0 deletions rust/graphs/shortestpaths/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod dijkstra;
8 changes: 8 additions & 0 deletions rust/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#![feature(test)]
extern crate test;

pub mod combinatorics;
pub mod graphs;
pub mod misc;
pub mod numbertheory;
pub mod structures;
2 changes: 1 addition & 1 deletion rust/misc/binary_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ where

#[cfg(test)]
mod tests {
use crate::binary_search_first_true;
use crate::misc::binary_search::binary_search_first_true;
use rstest::rstest;

#[rstest]
Expand Down
1 change: 1 addition & 0 deletions rust/misc/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod binary_search;
14 changes: 11 additions & 3 deletions rust/numbertheory/euclid.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
fn gcd(a: i32, b: i32) -> i32 {
return if b == 0 { a.abs() } else { gcd(b, a % b) };
if b == 0 {
a.abs()
} else {
gcd(b, a % b)
}
}

// returns { gcd(a,b), x, y } such that gcd(a,b) = a*x + b*y
Expand All @@ -21,12 +25,16 @@ fn euclid(mut a: i64, mut b: i64) -> [i64; 3] {
y = _y1;
a = _b;
}
return if a > 0 { [a, x, y] } else { [-a, -x, -y] };
if a > 0 {
[a, x, y]
} else {
[-a, -x, -y]
}
}

#[cfg(test)]
mod tests {
use crate::{euclid, gcd};
use crate::numbertheory::euclid::{euclid, gcd};

#[test]
fn basic_test() {
Expand Down
1 change: 1 addition & 0 deletions rust/numbertheory/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod euclid;
2 changes: 1 addition & 1 deletion rust/structures/disjoint_sets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl DisjointSets {

#[cfg(test)]
mod tests {
use crate::DisjointSets;
use crate::structures::disjoint_sets::DisjointSets;

#[test]
fn basic_test() {
Expand Down
4 changes: 2 additions & 2 deletions rust/structures/fenwick_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ impl<T: AddAssign + Copy + From<i32>> Fenwick<T> {
res += self.t[i as usize];
i = (i & (i + 1)) - 1;
}
return res;
res
}
}

#[cfg(test)]
mod tests {
use crate::Fenwick;
use crate::structures::fenwick_tree::Fenwick;

#[test]
fn basic_test() {
Expand Down
3 changes: 3 additions & 0 deletions rust/structures/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod disjoint_sets;
pub mod fenwick_tree;
pub mod persistent_tree;
2 changes: 1 addition & 1 deletion rust/structures/persistent_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl PersistentTree {

#[cfg(test)]
mod tests {
use crate::PersistentTree;
use crate::structures::persistent_tree::PersistentTree;

#[test]
fn basic_test() {
Expand Down
Loading