Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Runs

In this step, we will extract all the runs for a page encoded using RLE Bit-packing Hybrid Encoding.

RLE bit-packed hybrid format

The length is optional and might not be included, this is documented in the spec.

Page kindRLE-encoded data kindPrepend length?
Data page v1Definition levelsY
Repetition levelsY
Dictionary indicesN
Boolean valuesY

Task

Implement the read_rle_bit_packed_runs function in src/decoder/rle_bit_packing_hybrid.rs. It takes the encoded page and returns all the runs.

pub fn read_rle_bit_packed_runs(
    encoded_data: Bytes,
    bit_width: u8,
    prepend_length: bool,
) -> Result<Vec<RleBitPackedRun>> {
    todo!("step10-03: extract all runs")
}

You need to check the prepend_length argument to correctly extract the multiple packed runs.

Test

Test case for this step is step10_03_runs.

Hints and Solution

Hint (how to get all the runs)

Similar to the Data Page section, you should extract the run from the encoded data until there are no bytes left.

while !page_data.is_empty() {
    let (run, remaining) = read_rle_bit_packed_run(/* ... */);
    // ...
    page_data = remaining;
}
Solution
pub fn read_rle_bit_packed_runs(
    encoded_data: Bytes,
    bit_width: u8,
    prepend_length: bool,
) -> Result<Vec<RleBitPackedRun>> {
    let mut encoded_data = encoded_data;

    if prepend_length {
        let length = encoded_data.get_u32_le();
        encoded_data = encoded_data.slice(..length as usize);
    }

    let mut runs = Vec::new();
    while !encoded_data.is_empty() {
        let (run, remaining) = read_rle_bit_packed_run(encoded_data, bit_width)?;
        runs.push(run);
        encoded_data = remaining;
    }

    Ok(runs)
}