Find the optimal cut position that minimizes the dictionary size. Tries cut positions from 44 to 56 bits (typical for f64) and picks the one that produces the fewest unique front values.
(values: &[f64])
| 232 | /// Tries cut positions from 44 to 56 bits (typical for f64) and picks |
| 233 | /// the one that produces the fewest unique front values. |
| 234 | fn find_best_cut(values: &[f64]) -> u8 { |
| 235 | let sample_end = values.len().min(CODEC_SAMPLE_SIZE); |
| 236 | let sample = &values[..sample_end]; |
| 237 | let bits: Vec<u64> = sample.iter().map(|v| v.to_bits()).collect(); |
| 238 | |
| 239 | let mut best_cut = 48u8; |
| 240 | let mut best_unique = usize::MAX; |
| 241 | |
| 242 | // Try cut positions from 40 to 56 (covering typical f64 patterns). |
| 243 | for cut in 40..=56 { |
| 244 | let mut fronts: Vec<u64> = bits.iter().map(|&b| b >> cut).collect(); |
| 245 | fronts.sort_unstable(); |
| 246 | fronts.dedup(); |
| 247 | |
| 248 | if fronts.len() < best_unique { |
| 249 | best_unique = fronts.len(); |
| 250 | best_cut = cut; |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | best_cut |
| 255 | } |
| 256 | |
| 257 | #[cfg(test)] |
| 258 | mod tests { |