refactor(dosages): resolved clippy warnings

This commit is contained in:
2026-08-02 20:13:41 +10:00
committed by professor
parent 9702507f20
commit 0befcbfac5
3 changed files with 8 additions and 10 deletions
+3 -5
View File
@@ -62,7 +62,7 @@ impl ComboGraph {
.map(|(pos, combo)| (max(self.target.abs_diff(*pos), 1), combo.weight(), pos))
.min()?;
self.nodes.get(&closest.2)
self.nodes.get(closest.2)
}
/// Visit a combo and calculate its position and weight
@@ -110,8 +110,7 @@ impl ComboGraph {
let combo = self.nodes.get(&self.target)?;
Some(
(0..self.values.len())
.map(|i| vec![self.values[i]; combo[i] as usize])
.flatten()
.flat_map(|i| vec![self.values[i]; combo[i] as usize])
.collect(),
)
}
@@ -120,8 +119,7 @@ impl ComboGraph {
let combo = self.closest_node_target()?;
Some(
(0..self.values.len())
.map(|i| vec![self.values[i]; combo[i] as usize])
.flatten()
.flat_map(|i| vec![self.values[i]; combo[i] as usize])
.collect(),
)
}
+3 -3
View File
@@ -12,7 +12,7 @@ fn gcf(mut a: u32, mut b: u32) -> u32 {
}
/// Calculate gcf of vector
fn gcfv(v: &Vec<u32>) -> u32 {
fn gcfv(v: &[u32]) -> u32 {
let mut i = 1;
let mut cgcf = v[0]; // start with first item
let mut a;
@@ -33,13 +33,13 @@ fn gcfv(v: &Vec<u32>) -> u32 {
cgcf
}
pub fn factorise(strengths: &mut Vec<u32>) -> u32 {
pub fn factorise(strengths: &mut [u32]) -> u32 {
let factor = gcfv(strengths);
if factor == 1 {
return factor;
}
for s in strengths.iter_mut() {
*s = *s / factor;
*s /= factor;
}
factor
}
+2 -2
View File
@@ -16,7 +16,7 @@ use crate::factor::factorise;
/// ```
///
pub fn calculate_combo(mut target: u32, mut strengths: Vec<u32>) -> Vec<u32> {
if strengths.len() == 0 {
if strengths.is_empty() {
return vec![];
}
@@ -24,7 +24,7 @@ pub fn calculate_combo(mut target: u32, mut strengths: Vec<u32>) -> Vec<u32> {
let mut rounded = false;
if factor != 1 {
if target % factor != 0 {
if target.is_multiple_of(factor) {
let f_target: f64 = target as f64 / factor as f64;
target = f_target.round() as u32;
rounded = true;