Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
KillingSpark committed Oct 12, 2024
1 parent 3cb5d04 commit b067615
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/huff0/huff0_encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,16 @@ fn distribute_weights(amount: usize) -> Vec<usize> {
}

fn redistribute_weights(weights: &mut [usize], max_num_bits: usize) {
let weight_sum = weights.iter().copied().map(|x| 1 << x).sum::<usize>().ilog2() as usize;
let weight_sum = weights
.iter()
.copied()
.map(|x| 1 << x)
.sum::<usize>()
.ilog2() as usize;
if weight_sum + 1 <= max_num_bits {
return;
}
let decrease_weights_by = weight_sum - max_num_bits + 1;
let decrease_weights_by = weight_sum - max_num_bits + 1;
let mut added_weights = 0;
for weight in weights.iter_mut() {
if *weight < decrease_weights_by {
Expand Down Expand Up @@ -250,7 +255,11 @@ fn weights() {
.map(|weight| 1 << weight)
.sum::<usize>();
assert!(sum.is_power_of_two());
assert!(sum.ilog2() <= 11, "Max bits too big: sum: {} {weights:?}", sum);
assert!(
sum.ilog2() <= 11,
"Max bits too big: sum: {} {weights:?}",
sum
);

let codes = HuffmanTable::build_from_weights(&weights).codes;
for (code, num_bits) in codes.iter().copied() {
Expand Down

0 comments on commit b067615

Please sign in to comment.