diff --git a/src/graph/lowest_common_ancestor.rs b/src/graph/lowest_common_ancestor.rs index 2485f9cb216..60fa3ff13ca 100644 --- a/src/graph/lowest_common_ancestor.rs +++ b/src/graph/lowest_common_ancestor.rs @@ -205,7 +205,7 @@ mod tests { } } let mut offline_answers = offline.answer_queries(1, &tree); - offline_answers.sort_unstable_by(|a1, a2| a1.query_id.cmp(&a2.query_id)); + offline_answers.sort_unstable_by_key(|a| a.query_id); assert_eq!(offline_answers, online_answers); } } diff --git a/src/greedy/job_sequencing.rs b/src/greedy/job_sequencing.rs index 54133e4ae1f..6b45e4d33cd 100644 --- a/src/greedy/job_sequencing.rs +++ b/src/greedy/job_sequencing.rs @@ -85,7 +85,7 @@ pub fn schedule_jobs(mut jobs: Vec) -> ScheduleResult { } // Step 1 – sort jobs by profit, highest first. - jobs.sort_unstable_by(|a, b| b.profit.cmp(&a.profit)); + jobs.sort_unstable_by_key(|a| std::cmp::Reverse(a.profit)); // Step 2 – allocate slots. // At most n jobs can ever be scheduled, so cap the slot count at jobs.len() diff --git a/src/string/burrows_wheeler_transform.rs b/src/string/burrows_wheeler_transform.rs index 3ecef7b9ab3..071b16e9f56 100644 --- a/src/string/burrows_wheeler_transform.rs +++ b/src/string/burrows_wheeler_transform.rs @@ -26,7 +26,7 @@ pub fn inv_burrows_wheeler_transform>(input: (T, usize)) -> String table.push((i, input.0.as_ref().chars().nth(i).unwrap())); } - table.sort_by(|a, b| a.1.cmp(&b.1)); + table.sort_by_key(|a| a.1); let mut decoded = String::new(); let mut idx = input.1; diff --git a/src/string/manacher.rs b/src/string/manacher.rs index e45a3f15612..aa0a102533c 100644 --- a/src/string/manacher.rs +++ b/src/string/manacher.rs @@ -54,8 +54,7 @@ pub fn manacher(s: String) -> String { radius += 1; // 2: Checking palindrome. // Need to care about overflow usize. - while i >= radius && i + radius <= chars.len() - 1 && chars[i - radius] == chars[i + radius] - { + while i >= radius && i + radius < chars.len() && chars[i - radius] == chars[i + radius] { length_of_palindrome[i] += 2; radius += 1; }