Skip to content

Commit

Permalink
refactor: Apply fixable clippy suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfertel committed Jul 18, 2021
1 parent 51b2c44 commit 2458493
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/sorting/heap_sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ fn heapify<T: Ord>(array: &mut [T]) {
}

fn siftdown<T: Ord>(array: &mut [T], mut root: usize, end: usize) {
while 2 * root + 1 <= end {
while 2 * root < end {
let child = 2 * root + 1;
let mut swap = root;

if array[swap] < array[child] {
swap = child;
}
if child + 1 <= end && array[swap] < array[child + 1] {
if child < end && array[swap] < array[child + 1] {
swap = child + 1;
}

Expand Down
2 changes: 1 addition & 1 deletion src/sorting/insertion_sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub fn insertion_sort<T: Ord>(array: &mut [T]) {
let mut j = i;
while j > 0 && array[j] < array[j - 1] {
array.swap(j, j - 1);
j = j - 1;
j -= 1;
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/sorting/merge_sort.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub fn merge_sort<T: Ord + Copy>(array: &[T]) -> Vec<T> {
if array.len() < 2 {
return array.iter().cloned().collect();
return array.to_vec();
}

let middle = array.len() / 2;
Expand All @@ -15,10 +15,10 @@ fn merge<T: Ord + Copy>(left: &mut Vec<T>, right: &mut Vec<T>) -> Vec<T> {
let mut result = Vec::new();

for _ in 0..left.len() + right.len() {
if left.len() == 0 {
if left.is_empty() {
result.append(right);
break;
} else if right.len() == 0 {
} else if right.is_empty() {
result.append(left);
break;
} else if left[0] <= right[0] {
Expand Down
4 changes: 2 additions & 2 deletions src/string_matching/knuth_morris_pratt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fn precompute_table(pattern: &str) -> Vec<usize> {
}

if p[k] == p[q] {
k = k + 1;
k += 1;
}

pi[q] = k;
Expand All @@ -37,7 +37,7 @@ pub fn knuth_morris_pratt(text: &str, pattern: &str) -> Vec<usize> {
}

if p[q] == t[i - 1] {
q = q + 1;
q += 1;
}

if q == p.len() {
Expand Down

0 comments on commit 2458493

Please sign in to comment.