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 cad2352

Browse files
authored
fix: resolve new clippy warnings (TheAlgorithms#926)
1 parent ed7a42e commit cad2352

File tree

17 files changed

+27
-30
lines changed

17 files changed

+27
-30
lines changed

‎src/ciphers/aes.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ fn key_expansion(init_key: &[Byte], num_rounds: usize) -> Vec<Byte> {
318318
}
319319

320320
fn add_round_key(data: &mut [Byte], round_key: &[Byte]) {
321-
assert!(data.len() % AES_BLOCK_SIZE == 0 && round_key.len() == AES_BLOCK_SIZE);
321+
assert!(data.len().is_multiple_of(AES_BLOCK_SIZE) && round_key.len() == AES_BLOCK_SIZE);
322322
let num_blocks = data.len() / AES_BLOCK_SIZE;
323323
data.iter_mut()
324324
.zip(round_key.repeat(num_blocks))
@@ -348,7 +348,7 @@ fn mix_column_blocks(data: &mut [Byte], mode: AesMode) {
348348
}
349349

350350
fn padding<T: Clone + Default>(data: &[T], block_size: usize) -> Vec<T> {
351-
if data.len() % block_size == 0 {
351+
if data.len().is_multiple_of(block_size) {
352352
Vec::from(data)
353353
} else {
354354
let num_blocks = data.len() / block_size + 1;

‎src/ciphers/blake2b.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ fn add(a: &mut Word, b: Word) {
5555

5656
#[inline]
5757
const fn ceil(dividend: usize, divisor: usize) -> usize {
58-
(dividend / divisor) + ((dividend % divisor != 0) as usize)
58+
(dividend / divisor) + (!dividend.is_multiple_of(divisor) as usize)
5959
}
6060

6161
fn g(v: &mut [Word; 16], a: usize, b: usize, c: usize, d: usize, x: Word, y: Word) {

‎src/ciphers/diffie_hellman.rs‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,7 @@ impl DiffieHellman {
228228
// Both parties now have the same shared secret key s which can be used for encryption or authentication.
229229

230230
pub fn new(group: Option<u8>) -> Self {
231-
let mut _group: u8 = 14;
232-
if let Some(x) = group {
233-
_group = x;
234-
}
231+
let _group = group.unwrap_or(14);
235232

236233
if !PRIMES.contains_key(&_group) {
237234
panic!("group not in primes")

‎src/ciphers/sha3.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,10 @@ fn h2b(h: &[u8], n: usize) -> Vec<bool> {
271271
}
272272

273273
fn b2h(s: &[bool]) -> Vec<u8> {
274-
let m = if s.len() % U8BITS != 0 {
275-
(s.len() / 8) + 1
276-
} else {
274+
let m = if s.len().is_multiple_of(U8BITS) {
277275
s.len() / 8
276+
} else {
277+
(s.len() / 8) + 1
278278
};
279279
let mut bytes = vec![0u8; m];
280280

‎src/data_structures/probabilistic/bloom_filter.rs‎

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

110110
impl MultiBinaryBloomFilter {
111111
pub fn with_dimensions(filter_size: usize, hash_count: usize) -> Self {
112-
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
112+
let bytes_count = filter_size / 8 + usize::from(!filter_size.is_multiple_of(8)); // we need 8 times less entries in the array, since we are using bytes. Careful that we have at least one element though
113113
Self {
114114
filter_size,
115115
bytes: vec![0; bytes_count],

‎src/general/permutations/heap.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn heap_recurse<T: Clone + Debug>(arr: &mut [T], k: usize, collector: &mut Vec<V
2323
// Heap's algorithm has a more clever way of permuting the elements so that we never need to swap back!
2424
for i in 0..k {
2525
// now deal with [a, b]
26-
let swap_idx = if k % 2 == 0 { i } else { 0 };
26+
let swap_idx = if k.is_multiple_of(2) { i } else { 0 };
2727
arr.swap(swap_idx, k - 1);
2828
heap_recurse(arr, k - 1, collector);
2929
}

‎src/machine_learning/loss_function/kl_divergence_loss.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub fn kld_loss(actual: &[f64], predicted: &[f64]) -> f64 {
1616
let loss: f64 = actual
1717
.iter()
1818
.zip(predicted.iter())
19-
.map(|(&a, &p)| ((a + eps) * ((a + eps) / (p + eps)).ln()))
19+
.map(|(&a, &p)| (a + eps) * ((a + eps) / (p + eps)).ln())
2020
.sum();
2121
loss
2222
}

‎src/math/aliquot_sum.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub fn aliquot_sum(number: u64) -> u64 {
1111
panic!("Input has to be positive.")
1212
}
1313

14-
(1..=number / 2).filter(|&d| number % d == 0).sum()
14+
(1..=number / 2).filter(|&d| number.is_multiple_of(d)).sum()
1515
}
1616

1717
#[cfg(test)]

‎src/math/collatz_sequence.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pub fn sequence(mut n: usize) -> Option<Vec<usize>> {
66
let mut list: Vec<usize> = vec![];
77
while n != 1 {
88
list.push(n);
9-
if n % 2 == 0 {
9+
if n.is_multiple_of(2) {
1010
n /= 2;
1111
} else {
1212
n = 3 * n + 1;

‎src/math/factors.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub fn factors(number: u64) -> Vec<u64> {
77
let mut factors: Vec<u64> = Vec::new();
88

99
for i in 1..=((number as f64).sqrt() as u64) {
10-
if number % i == 0 {
10+
if number.is_multiple_of(i) {
1111
factors.push(i);
1212
if i != number / i {
1313
factors.push(number / i);

0 commit comments

Comments
(0)

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