]> git.proxmox.com Git - proxmox-resource-scheduling.git/commitdiff
simplifications
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Fri, 11 Nov 2022 10:41:01 +0000 (11:41 +0100)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Fri, 11 Nov 2022 12:50:42 +0000 (13:50 +0100)
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
src/topsis.rs

index 90145fad6f3a159d6ce4c647ca30217a0acaf026..a1bd9a3ebf11fef4935dadaef25db55232bb3e80 100644 (file)
@@ -10,10 +10,7 @@ fn differences<const N: usize>(xs: &[f64; N], ys: &[f64; N]) -> [f64; N] {
 
 /// Calculate the L^2-norm of the given values.
 fn l2_norm(values: &[f64]) -> f64 {
-    values
-        .iter()
-        .fold(0.0, |sum_of_squares, value| sum_of_squares + value * value)
-        .sqrt()
+    values.into_iter().map(|v| v * v).sum::<f64>().sqrt()
 }
 
 /// A criterion that can be used when scoring with the TOPSIS algorithm.
@@ -54,9 +51,7 @@ impl<const N: usize> Criteria<N> {
     ///
     /// Assumes that the sum of weights can be calculated to a finite, non-zero value.
     pub fn new(mut criteria: [Criterion; N]) -> Result<Self, Error> {
-        let divisor = criteria
-            .iter()
-            .fold(0.0, |sum, criterion| sum + criterion.weight);
+        let divisor: f64 = criteria.iter().map(|c| c.weight).sum();
 
         if divisor == 0.0 {
             bail!("no criterion has a non-zero weight");