diff --git a/okolors/src/kmeans.rs b/okolors/src/kmeans.rs index e12b10d..9a34a32 100644 --- a/okolors/src/kmeans.rs +++ b/okolors/src/kmeans.rs @@ -158,7 +158,7 @@ fn kmeans_plus_plus( *weight = f32::min(*weight, D::squared_distance(color, centroid)); } - match WeightedIndex::new(weights.iter().copied()) { + match WeightedIndex::new(&*weights) { Ok(sampler) => centroids.push(colors[sampler.sample(rng)]), Err(AllWeightsZero) => return, // all points exactly match a centroid Err(InvalidWeight | NoItem | TooMany) => { diff --git a/okolors/src/lib.rs b/okolors/src/lib.rs index 8ef53b8..122c0fb 100644 --- a/okolors/src/lib.rs +++ b/okolors/src/lib.rs @@ -431,7 +431,7 @@ mod tests { fn test_colors() -> Vec> { let range = (0..u8::MAX).step_by(16); - let mut colors = Vec::new(); + let mut colors = Vec::with_capacity(range.len().pow(3)); for r in range.clone() { for g in range.clone() {