Skip to content

style: include needless_pass_by_ref_mut #748

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 13, 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
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ imprecise_flops = { level = "allow", priority = 1 }
iter_on_single_items = { level = "allow", priority = 1 }
missing_const_for_fn = { level = "allow", priority = 1 }
needless_collect = { level = "allow", priority = 1 }
needless_pass_by_ref_mut = { level = "allow", priority = 1 }
nonstandard_macro_braces = { level = "allow", priority = 1 }
option_if_let_else = { level = "allow", priority = 1 }
redundant_clone = { level = "allow", priority = 1 }
Expand Down
6 changes: 3 additions & 3 deletions src/data_structures/floyds_algorithm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

use crate::data_structures::linked_list::LinkedList; // Import the LinkedList from linked_list.rs

pub fn detect_cycle<T>(linked_list: &mut LinkedList<T>) -> Option<usize> {
pub fn detect_cycle<T>(linked_list: &LinkedList<T>) -> Option<usize> {
let mut current = linked_list.head;
let mut checkpoint = linked_list.head;
let mut steps_until_reset = 1;
Expand Down Expand Up @@ -70,7 +70,7 @@ mod tests {

assert!(!has_cycle(&linked_list));

assert_eq!(detect_cycle(&mut linked_list), None);
assert_eq!(detect_cycle(&linked_list), None);
}

#[test]
Expand All @@ -90,6 +90,6 @@ mod tests {
}

assert!(has_cycle(&linked_list));
assert_eq!(detect_cycle(&mut linked_list), Some(3));
assert_eq!(detect_cycle(&linked_list), Some(3));
}
}
26 changes: 13 additions & 13 deletions src/graph/ford_fulkerson.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::collections::VecDeque;

const V: usize = 6; // Number of vertices in graph

pub fn bfs(r_graph: &mut [Vec<i32>], s: usize, t: usize, parent: &mut [i32]) -> bool {
pub fn bfs(r_graph: &[Vec<i32>], s: usize, t: usize, parent: &mut [i32]) -> bool {
let mut visited = [false; V];
visited[s] = true;
parent[s] = -1;
Expand All @@ -41,12 +41,12 @@ pub fn bfs(r_graph: &mut [Vec<i32>], s: usize, t: usize, parent: &mut [i32]) ->
false
}

pub fn ford_fulkerson(graph: &mut [Vec<i32>], s: usize, t: usize) -> i32 {
pub fn ford_fulkerson(graph: &[Vec<i32>], s: usize, t: usize) -> i32 {
let mut r_graph = graph.to_owned();
let mut parent = vec![-1; V];
let mut max_flow = 0;

while bfs(&mut r_graph, s, t, &mut parent) {
while bfs(&r_graph, s, t, &mut parent) {
let mut path_flow = i32::MAX;
let mut v = t;

Expand Down Expand Up @@ -76,66 +76,66 @@ mod tests {

#[test]
fn test_example_1() {
let mut graph = vec![
let graph = vec![
vec![0, 12, 0, 13, 0, 0],
vec![0, 0, 10, 0, 0, 0],
vec![0, 0, 0, 13, 3, 15],
vec![0, 0, 7, 0, 15, 0],
vec![0, 0, 6, 0, 0, 17],
vec![0, 0, 0, 0, 0, 0],
];
assert_eq!(ford_fulkerson(&mut graph, 0, 5), 23);
assert_eq!(ford_fulkerson(&graph, 0, 5), 23);
}

#[test]
fn test_example_2() {
let mut graph = vec![
let graph = vec![
vec![0, 4, 0, 3, 0, 0],
vec![0, 0, 4, 0, 8, 0],
vec![0, 0, 0, 3, 0, 2],
vec![0, 0, 0, 0, 6, 0],
vec![0, 0, 6, 0, 0, 6],
vec![0, 0, 0, 0, 0, 0],
];
assert_eq!(ford_fulkerson(&mut graph, 0, 5), 7);
assert_eq!(ford_fulkerson(&graph, 0, 5), 7);
}

#[test]
fn test_example_3() {
let mut graph = vec![
let graph = vec![
vec![0, 10, 0, 10, 0, 0],
vec![0, 0, 4, 2, 8, 0],
vec![0, 0, 0, 0, 0, 10],
vec![0, 0, 0, 0, 9, 0],
vec![0, 0, 6, 0, 0, 10],
vec![0, 0, 0, 0, 0, 0],
];
assert_eq!(ford_fulkerson(&mut graph, 0, 5), 19);
assert_eq!(ford_fulkerson(&graph, 0, 5), 19);
}

#[test]
fn test_example_4() {
let mut graph = vec![
let graph = vec![
vec![0, 8, 0, 0, 3, 0],
vec![0, 0, 9, 0, 0, 0],
vec![0, 0, 0, 0, 7, 2],
vec![0, 0, 0, 0, 0, 5],
vec![0, 0, 7, 4, 0, 0],
vec![0, 0, 0, 0, 0, 0],
];
assert_eq!(ford_fulkerson(&mut graph, 0, 5), 6);
assert_eq!(ford_fulkerson(&graph, 0, 5), 6);
}

#[test]
fn test_example_5() {
let mut graph = vec![
let graph = vec![
vec![0, 16, 13, 0, 0, 0],
vec![0, 0, 10, 12, 0, 0],
vec![0, 4, 0, 0, 14, 0],
vec![0, 0, 9, 0, 0, 20],
vec![0, 0, 0, 7, 0, 4],
vec![0, 0, 0, 0, 0, 0],
];
assert_eq!(ford_fulkerson(&mut graph, 0, 5), 23);
assert_eq!(ford_fulkerson(&graph, 0, 5), 23);
}
}