Variable-width bitpacking for `u32` arrays. Packs an array of u32 values using the minimum number of bits per value. 2-byte block header stores `num_values` (u16) followed by 1-byte `bit_width`. Each value is stored in exactly `bit_width` bits, packed contiguously. Used for both delta-encoded doc IDs and term frequencies. Compute the minimum number of bits needed to represent `max_val`. Returns
(max_val: u32)
| 11 | /// Compute the minimum number of bits needed to represent `max_val`. |
| 12 | /// Returns 0 for max_val == 0, 1 for max_val == 1, etc. |
| 13 | pub fn bits_needed(max_val: u32) -> u8 { |
| 14 | if max_val == 0 { |
| 15 | return 0; |
| 16 | } |
| 17 | 32 - max_val.leading_zeros() as u8 |
| 18 | } |
| 19 | |
| 20 | /// Pack a slice of u32 values into a compact byte buffer. |
| 21 | /// |