MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / find_best_cut

Function find_best_cut

nodedb-codec/src/alp_rd.rs:234–255  ·  view source on GitHub ↗

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])

Source from the content-addressed store, hash-verified

232/// Tries cut positions from 44 to 56 bits (typical for f64) and picks
233/// the one that produces the fewest unique front values.
234fn 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)]
258mod tests {

Callers 1

encodeFunction · 0.85

Calls 4

collectMethod · 0.80
dedupMethod · 0.80
lenMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected