MCPcopy Create free account
hub / github.com/apache/arrow-rs / encode

Function encode

arrow-row/src/run.rs:51–80  ·  view source on GitHub ↗

Encodes the provided `RunEndEncodedArray` to `out` with the provided `SortOptions` `rows` should contain the encoded values

(
    data: &mut [u8],
    offsets: &mut [usize],
    rows: &Rows,
    opts: SortOptions,
    array: &RunArray<R>,
)

Source from the content-addressed store, hash-verified

49///
50/// `rows` should contain the encoded values
51pub fn encode<R: RunEndIndexType>(
52 data: &mut [u8],
53 offsets: &mut [usize],
54 rows: &Rows,
55 opts: SortOptions,
56 array: &RunArray<R>,
57) {
58 let run_ends = array.run_ends().sliced_values();
59 let mut logical_idx = 0;
60 let mut offset_idx = 1; // Skip first offset
61
62 // Iterate over each run
63 for (physical_idx, run_end) in run_ends.enumerate() {
64 let run_end = run_end.as_usize();
65 let iteration_count = run_end - logical_idx;
66
67 let first_offset = offsets[offset_idx];
68 let out = &mut data[first_offset..];
69 let bytes_written = variable::encode_one(out, Some(rows.row(physical_idx).data), opts);
70 offsets[offset_idx] += bytes_written;
71 // now if there are multiple logical positions in this run, we can just copy the same encoded data to the next offsets without re-encoding
72 for i in 1..iteration_count {
73 let dst = offsets[offset_idx + i];
74 data.copy_within(first_offset..first_offset + bytes_written, dst);
75 offsets[offset_idx + i] += bytes_written;
76 }
77 logical_idx = run_end;
78 offset_idx += iteration_count;
79 }
80}
81
82/// Decodes a RunEndEncodedArray from `rows` with the provided `options`
83///

Callers 1

encode_columnFunction · 0.70

Calls 5

sliced_valuesMethod · 0.80
run_endsMethod · 0.80
as_usizeMethod · 0.80
encode_oneFunction · 0.70
rowMethod · 0.45

Tested by

no test coverage detected