Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 798c73a

Browse files
authored
style: include bool_to_int_with_if (TheAlgorithms#867)
1 parent c149ad5 commit 798c73a

File tree

4 files changed

+5
-10
lines changed

4 files changed

+5
-10
lines changed

‎Cargo.toml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ restriction = "warn"
2424
nursery = "warn"
2525
cargo = "warn"
2626
# pedantic-lints:
27-
bool_to_int_with_if = { level = "allow", priority = 1 }
2827
cast_lossless = { level = "allow", priority = 1 }
2928
cast_possible_truncation = { level = "allow", priority = 1 }
3029
cast_possible_wrap = { level = "allow", priority = 1 }

‎src/data_structures/probabilistic/bloom_filter.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ pub struct MultiBinaryBloomFilter {
108108

109109
impl MultiBinaryBloomFilter {
110110
pub fn with_dimensions(filter_size: usize, hash_count: usize) -> Self {
111-
let bytes_count = filter_size / 8 + iffilter_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
111+
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
112112
Self {
113113
filter_size,
114114
bytes: vec![0; bytes_count],

‎src/string/levenshtein_distance.rs‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,7 @@ pub fn naive_levenshtein_distance(string1: &str, string2: &str) -> usize {
5050

5151
let updated_matrix = (1..=string1.len()).fold(distance_matrix, |matrix, i| {
5252
(1..=string2.len()).fold(matrix, |mut inner_matrix, j| {
53-
let cost = if string1.as_bytes()[i - 1] == string2.as_bytes()[j - 1] {
54-
0
55-
} else {
56-
1
57-
};
53+
let cost = usize::from(string1.as_bytes()[i - 1] != string2.as_bytes()[j - 1]);
5854
inner_matrix[i][j] = (inner_matrix[i - 1][j - 1] + cost)
5955
.min(inner_matrix[i][j - 1] + 1)
6056
.min(inner_matrix[i - 1][j] + 1);

‎src/string/shortest_palindrome.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub fn compute_suffix(chars: &[char]) -> Vec<usize> {
5151
while j > 0 && chars[j] != chars[i] {
5252
j = suffix[j - 1];
5353
}
54-
suffix[i] = j + ifchars[j] == chars[i]{1}else{0};
54+
suffix[i] = j + (chars[j] == chars[i])asusize;
5555
}
5656
suffix
5757
}
@@ -72,13 +72,13 @@ pub fn compute_suffix(chars: &[char]) -> Vec<usize> {
7272
/// `reversed[0..=i]`.
7373
pub fn compute_prefix_match(original: &[char], reversed: &[char], suffix: &[usize]) -> Vec<usize> {
7474
let mut match_table = vec![0; original.len()];
75-
match_table[0] = iforiginal[0] == reversed[0]{1}else{0};
75+
match_table[0] = usize::from(original[0] == reversed[0]);
7676
for i in 1..original.len() {
7777
let mut j = match_table[i - 1];
7878
while j > 0 && reversed[i] != original[j] {
7979
j = suffix[j - 1];
8080
}
81-
match_table[i] = j + ifreversed[i] == original[j]{1}else{0};
81+
match_table[i] = j + usize::from(reversed[i] == original[j]);
8282
}
8383
match_table
8484
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /