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

style: include bool_to_int_with_if #867

Merged
merged 1 commit into from
Feb 2, 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 @@ -24,7 +24,6 @@ restriction = "warn"
nursery = "warn"
cargo = "warn"
# pedantic-lints:
bool_to_int_with_if = { level = "allow", priority = 1 }
cast_lossless = { level = "allow", priority = 1 }
cast_possible_truncation = { level = "allow", priority = 1 }
cast_possible_wrap = { level = "allow", priority = 1 }
Expand Down
2 changes: 1 addition & 1 deletion src/data_structures/probabilistic/bloom_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ pub struct MultiBinaryBloomFilter {

impl MultiBinaryBloomFilter {
pub fn with_dimensions(filter_size: usize, hash_count: usize) -> Self {
let bytes_count = filter_size / 8 + if filter_size % 8 > 0 { 1 } else { 0 }; // we need 8 times less entries in the array, since we are using bytes. Careful that we have at least one element though
let bytes_count = filter_size / 8 + usize::from(filter_size % 8 > 0); // we need 8 times less entries in the array, since we are using bytes. Careful that we have at least one element though
Self {
filter_size,
bytes: vec![0; bytes_count],
Expand Down
6 changes: 1 addition & 5 deletions src/string/levenshtein_distance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,7 @@ pub fn naive_levenshtein_distance(string1: &str, string2: &str) -> usize {

let updated_matrix = (1..=string1.len()).fold(distance_matrix, |matrix, i| {
(1..=string2.len()).fold(matrix, |mut inner_matrix, j| {
let cost = if string1.as_bytes()[i - 1] == string2.as_bytes()[j - 1] {
0
} else {
1
};
let cost = usize::from(string1.as_bytes()[i - 1] != string2.as_bytes()[j - 1]);
inner_matrix[i][j] = (inner_matrix[i - 1][j - 1] + cost)
.min(inner_matrix[i][j - 1] + 1)
.min(inner_matrix[i - 1][j] + 1);
Expand Down
6 changes: 3 additions & 3 deletions src/string/shortest_palindrome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub fn compute_suffix(chars: &[char]) -> Vec<usize> {
while j > 0 && chars[j] != chars[i] {
j = suffix[j - 1];
}
suffix[i] = j + if chars[j] == chars[i] { 1 } else { 0 };
suffix[i] = j + (chars[j] == chars[i]) as usize;
}
suffix
}
Expand All @@ -72,13 +72,13 @@ pub fn compute_suffix(chars: &[char]) -> Vec<usize> {
/// `reversed[0..=i]`.
pub fn compute_prefix_match(original: &[char], reversed: &[char], suffix: &[usize]) -> Vec<usize> {
let mut match_table = vec![0; original.len()];
match_table[0] = if original[0] == reversed[0] { 1 } else { 0 };
match_table[0] = usize::from(original[0] == reversed[0]);
for i in 1..original.len() {
let mut j = match_table[i - 1];
while j > 0 && reversed[i] != original[j] {
j = suffix[j - 1];
}
match_table[i] = j + if reversed[i] == original[j] { 1 } else { 0 };
match_table[i] = j + usize::from(reversed[i] == original[j]);
}
match_table
}
Expand Down