Skip to content

style: include needless_for_each #857

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
Jan 15, 2025
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 @@ -57,7 +57,6 @@ missing_fields_in_debug = { level = "allow", priority = 1 }
missing_panics_doc = { level = "allow", priority = 1 }
module_name_repetitions = { level = "allow", priority = 1 }
must_use_candidate = { level = "allow", priority = 1 }
needless_for_each = { level = "allow", priority = 1 }
needless_pass_by_value = { level = "allow", priority = 1 }
range_plus_one = { level = "allow", priority = 1 }
redundant_closure_for_method_calls = { level = "allow", priority = 1 }
Expand Down
26 changes: 11 additions & 15 deletions src/ciphers/transposition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ pub fn transposition(decrypt_mode: bool, msg: &str, key: &str) -> String {

for cipher_key in keys.iter() {
let mut key_order: Vec<usize> = Vec::new();
let mut counter: u8 = 0;

// Removes any non-alphabet characters from 'msg'
cipher_msg = cipher_msg
Expand All @@ -36,10 +35,9 @@ pub fn transposition(decrypt_mode: bool, msg: &str, key: &str) -> String {

key_ascii.sort_by_key(|&(_, key)| key);

key_ascii.iter_mut().for_each(|(_, key)| {
*key = counter;
counter += 1;
});
for (counter, (_, key)) in key_ascii.iter_mut().enumerate() {
*key = counter as u8;
}

key_ascii.sort_by_key(|&(index, _)| index);

Expand Down Expand Up @@ -91,18 +89,16 @@ fn encrypt(mut msg: String, key_order: Vec<usize>) -> String {
// alphabetical order of the keyword's characters
let mut indexed_vec: Vec<(usize, &String)> = Vec::new();
let mut indexed_msg: String = String::from("");
let mut counter: usize = 0;

key_order.into_iter().for_each(|key_index| {
for (counter, key_index) in key_order.into_iter().enumerate() {
indexed_vec.push((key_index, &encrypted_vec[counter]));
counter += 1;
});
}

indexed_vec.sort();

indexed_vec.into_iter().for_each(|(_, column)| {
for (_, column) in indexed_vec {
indexed_msg.push_str(column);
});
}

// Split the message by a space every nth character, determined by
// 'message length divided by keyword length' to the next highest integer.
Expand Down Expand Up @@ -153,19 +149,19 @@ fn decrypt(mut msg: String, key_order: Vec<usize>) -> String {
msg.replace_range(range, "");
});

split_small.iter_mut().for_each(|key_index| {
for key_index in split_small.iter_mut() {
let (slice, rest_of_msg) = msg.split_at(split_size);
indexed_vec.push((*key_index, (slice.to_string())));
msg = rest_of_msg.to_string();
});
}

indexed_vec.sort();

key_order.into_iter().for_each(|key| {
for key in key_order {
if let Some((_, column)) = indexed_vec.iter().find(|(key_index, _)| key_index == &key) {
decrypted_vec.push(column.to_string());
}
});
}

// Concatenate the columns into a string, determined by the
// alphabetical order of the keyword's characters
Expand Down
4 changes: 2 additions & 2 deletions src/graph/two_satisfiability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ pub fn solve_two_satisfiability(
let mut sccs = SCCs::new(num_verts);
let mut adj = Graph::new();
adj.resize(num_verts, vec![]);
expression.iter().for_each(|cond| {
for cond in expression.iter() {
let v1 = variable(cond.0);
let v2 = variable(cond.1);
adj[v1 ^ 1].push(v2);
adj[v2 ^ 1].push(v1);
});
}
sccs.find_components(&adj);
result.resize(num_variables + 1, false);
for var in (2..num_verts).step_by(2) {
Expand Down
4 changes: 2 additions & 2 deletions src/searching/moore_voting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub fn moore_voting(arr: &[i32]) -> i32 {
let mut cnt = 0; // initializing cnt
let mut ele = 0; // initializing ele

arr.iter().for_each(|&item| {
for &item in arr.iter() {
if cnt == 0 {
cnt = 1;
ele = item;
Expand All @@ -55,7 +55,7 @@ pub fn moore_voting(arr: &[i32]) -> i32 {
} else {
cnt -= 1;
}
});
}

let cnt_check = arr.iter().filter(|&&x| x == ele).count();

Expand Down
Loading