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

Function encode_generic_byte_array

arrow-row/src/variable.rs:95–134  ·  view source on GitHub ↗

Calls [`encode`] with optimized iterator for generic byte arrays

(
    data: &mut [u8],
    offsets: &mut [usize],
    input_array: &GenericByteArray<T>,
    opts: SortOptions,
)

Source from the content-addressed store, hash-verified

93
94/// Calls [`encode`] with optimized iterator for generic byte arrays
95pub(crate) fn encode_generic_byte_array<T: ByteArrayType>(
96 data: &mut [u8],
97 offsets: &mut [usize],
98 input_array: &GenericByteArray<T>,
99 opts: SortOptions,
100) {
101 let input_offsets = input_array.value_offsets();
102 let bytes = input_array.values().as_slice();
103
104 if let Some(null_buffer) = input_array.nulls().filter(|x| x.null_count() > 0) {
105 let input_iter =
106 input_offsets
107 .windows(2)
108 .zip(null_buffer.iter())
109 .map(|(start_end, is_valid)| {
110 if is_valid {
111 let item_range = start_end[0].as_usize()..start_end[1].as_usize();
112 // SAFETY: the offsets of the input are valid by construction
113 // so it is ok to use unsafe here
114 let item = unsafe { bytes.get_unchecked(item_range) };
115 Some(item)
116 } else {
117 None
118 }
119 });
120
121 encode(data, offsets, input_iter, opts);
122 } else {
123 // Skip null checks
124 let input_iter = input_offsets.windows(2).map(|start_end| {
125 let item_range = start_end[0].as_usize()..start_end[1].as_usize();
126 // SAFETY: the offsets of the input are valid by construction
127 // so it is ok to use unsafe here
128 let item = unsafe { bytes.get_unchecked(item_range) };
129 Some(item)
130 });
131
132 encode(data, offsets, input_iter, opts);
133 }
134}
135
136pub fn encode_null(out: &mut [u8], opts: SortOptions) -> usize {
137 out[0] = null_sentinel(opts);

Callers

nothing calls this directly

Calls 10

filterMethod · 0.80
zipMethod · 0.80
as_usizeMethod · 0.80
encodeFunction · 0.70
value_offsetsMethod · 0.45
as_sliceMethod · 0.45
valuesMethod · 0.45
nullsMethod · 0.45
null_countMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected