forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'simplify/b12' into simplify/w1a

Browse files at this commit

4b2a84483a96e15c08e142b8e62fc351c95ac563Ahmet Kaan GümüşParent: 8fc2fda15e454e
crates/ec-vorbis/src/codebook.rsmodified+2 -3
@@ -392,8 +392,7 @@ impl CodebookSpec {
392392 /// does the cost is a fraction of a bit on the rarest symbol.
393393 fn huffman_lengths(weights: &[f64]) -> Vec<u8> {
394394 let n = weights.len();
395- assert!(n > 0, "a codebook needs at least one entry");
396- if n == 1 {
395+ if n <= 1 {
397396 return vec![1];
398397 }
399398 let floor = weights.iter().cloned().fold(0.0f64, f64::max) / 8_388_608.0;
@@ -405,7 +404,7 @@ fn huffman_lengths(weights: &[f64]) -> Vec<u8> {
405404 // Leaves first, then merged nodes, tracked as a forest over `parent`.
406405 let mut parent = vec![usize::MAX; n];
407406 let mut heap: Vec<(f64, usize)> = nodes.clone();
408- heap.sort_by(|a, b| b.0.partial_cmp(&a.0).unwrap());
407+ heap.sort_by(|a, b| b.0.total_cmp(&a.0));
409408 let mut merged: Vec<(f64, usize)> = Vec::new();
410409 let mut next_id = n;
411410 while heap.len() + merged.len() > 1 {