merge_overlapping_writes

Function merge_overlapping_writes 

Source
pub fn merge_overlapping_writes<D: AsRef<[u8]> + Send + 'static>(
    writes: impl IntoIterator<Item = WriteRequest<D>>,
) -> BTreeMap<u64, (u64, Vec<u8>)>
Expand description

Merges a sequence of writes that may overlap, producing a minimal set of non-overlapping writes. Later writes win where there are overlaps.

Returns a BTreeMap where keys are start offsets and values are (end_offset, merged_data). The result contains only non-overlapping intervals with the final data for each byte position.

§Complexity

  • O(N log N) typical case for N writes with few overlaps
  • O(N² log N) worst case if every write overlaps everything

§Example

let writes = vec![
  WriteRequest::new(0, vec![1, 2, 3, 4]),
  WriteRequest::new(2, vec![5, 6]),  // Overlaps and wins
];
let merged = merge_overlapping_writes(writes);
// Result: {0 => (2, [1, 2]), 2 => (4, [5, 6])}