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

Function should_use_rle

nodedb-array/src/codec/coord_rle.rs:31–45  ·  view source on GitHub ↗
(indices: &[u32])

Source from the content-addressed store, hash-verified

29const RLE_BENEFIT_DENOMINATOR: usize = 2;
30
31fn should_use_rle(indices: &[u32]) -> bool {
32 if indices.len() < 4 {
33 return false;
34 }
35 let mut run_count = 1usize;
36 for i in 1..indices.len() {
37 if indices[i] != indices[i - 1] {
38 run_count += 1;
39 }
40 }
41 // RLE cells needed: run_count * 8 bytes (value + length pairs)
42 // Delta cells approx: indices.len() * 1.5 bytes average
43 // Use simpler heuristic: worth it if run_count < indices.len() / 2
44 run_count * RLE_BENEFIT_DENOMINATOR < indices.len() * RLE_BENEFIT_NUMERATOR
45}
46
47/// RLE mode sentinel: u32::MAX. This value can never appear as a dict count
48/// because a DimDict with u32::MAX distinct values would require ~16 GB of

Callers 1

encode_coord_axis_rleFunction · 0.85

Calls 1

lenMethod · 0.45

Tested by

no test coverage detected