diff --git a/src/graph.rs b/src/graph.rs index a2c87e8..c7cfc6c 100644 --- a/src/graph.rs +++ b/src/graph.rs @@ -180,7 +180,7 @@ impl Graph { let n = degrees.len(); if n < 2 { return 0.0; } - degrees.sort_by(|a, b| a.partial_cmp(b).unwrap()); + degrees.sort_by(|a, b| a.partial_cmp(b).unwrap_or(std::cmp::Ordering::Equal)); let mean = degrees.iter().sum::() / n as f64; if mean < 1e-10 { return 0.0; } @@ -448,7 +448,7 @@ fn label_propagation( // Adopt the label with most votes if let Some((&best_label, _)) = votes.iter() - .max_by(|a, b| a.1.partial_cmp(b.1).unwrap()) + .max_by(|a, b| a.1.partial_cmp(b.1).unwrap_or(std::cmp::Ordering::Equal)) { let current = labels[key]; if best_label != current { @@ -670,7 +670,7 @@ Categories: core={core} tech={tech} gen={gen} obs={obs} task={task}", // Show history trend if we have enough data points if history.len() >= 3 { report.push_str("\n\nMetrics history (last 5):\n"); - for snap in history.iter().rev().take(5).collect::>().into_iter().rev() { + for snap in &history[history.len().saturating_sub(5)..] { report.push_str(&format!(" {} — σ={:.1} α={:.2} gini={:.3} cc={:.4} fit={:.3}\n", snap.date, snap.sigma, snap.alpha, snap.gini, snap.avg_cc, snap.avg_schema_fit)); } diff --git a/src/similarity.rs b/src/similarity.rs index 53fe742..38a399c 100644 --- a/src/similarity.rs +++ b/src/similarity.rs @@ -100,7 +100,7 @@ pub fn pairwise_similar( } } - results.sort_by(|a, b| b.2.partial_cmp(&a.2).unwrap()); + results.sort_by(|a, b| b.2.partial_cmp(&a.2).unwrap_or(std::cmp::Ordering::Equal)); results }