Skip to content

style: include match_bool #858

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 16, 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 @@ -48,7 +48,6 @@ manual_assert = { level = "allow", priority = 1 }
manual_let_else = { level = "allow", priority = 1 }
manual_string_new = { level = "allow", priority = 1 }
many_single_char_names = { level = "allow", priority = 1 }
match_bool = { level = "allow", priority = 1 }
match_on_vec_items = { level = "allow", priority = 1 }
match_same_arms = { level = "allow", priority = 1 }
match_wildcard_for_single_variants = { level = "allow", priority = 1 }
Expand Down
14 changes: 8 additions & 6 deletions src/ciphers/transposition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ pub fn transposition(decrypt_mode: bool, msg: &str, key: &str) -> String {
let key_uppercase: String = key.to_uppercase();
let mut cipher_msg: String = msg.to_string();

let keys: Vec<&str> = match decrypt_mode {
false => key_uppercase.split_whitespace().collect(),
true => key_uppercase.split_whitespace().rev().collect(),
let keys: Vec<&str> = if decrypt_mode {
key_uppercase.split_whitespace().rev().collect()
} else {
key_uppercase.split_whitespace().collect()
};

for cipher_key in keys.iter() {
Expand Down Expand Up @@ -47,9 +48,10 @@ pub fn transposition(decrypt_mode: bool, msg: &str, key: &str) -> String {

// Determines whether to encrypt or decrypt the message,
// and returns the result
cipher_msg = match decrypt_mode {
false => encrypt(cipher_msg, key_order),
true => decrypt(cipher_msg, key_order),
cipher_msg = if decrypt_mode {
decrypt(cipher_msg, key_order)
} else {
encrypt(cipher_msg, key_order)
};
}

Expand Down
7 changes: 4 additions & 3 deletions src/general/huffman_encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,10 @@ impl HuffmanEncoding {
result.push(state.symbol.unwrap());
state = &dict.root;
}
match self.get_bit(i) {
false => state = state.left.as_ref().unwrap(),
true => state = state.right.as_ref().unwrap(),
state = if self.get_bit(i) {
state.right.as_ref().unwrap()
} else {
state.left.as_ref().unwrap()
}
}
if self.num_bits > 0 {
Expand Down
19 changes: 9 additions & 10 deletions src/sorting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,16 @@ where
{
use std::collections::HashSet;

match a.len() == b.len() {
true => {
// This is O(n^2) but performs better on smaller data sizes
//b.iter().all(|item| a.contains(item))
if a.len() == b.len() {
// This is O(n^2) but performs better on smaller data sizes
//b.iter().all(|item| a.contains(item))

// This is O(n), performs well on larger data sizes
let set_a: HashSet<&T> = a.iter().collect();
let set_b: HashSet<&T> = b.iter().collect();
set_a == set_b
}
false => false,
// This is O(n), performs well on larger data sizes
let set_a: HashSet<&T> = a.iter().collect();
let set_b: HashSet<&T> = b.iter().collect();
set_a == set_b
} else {
false
}
}

Expand Down
Loading