MCPcopy Create free account
hub / github.com/apache/arrow / CheckAdvance

Function CheckAdvance

cpp/src/arrow/util/rle_encoding_test.cc:1153–1198  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1151/// crossed and partial runs consumed, verifying decoded values as we go.
1152template <typename Type>
1153void CheckAdvance(const Array& data, int bit_width) {
1154 using ArrayType = typename TypeTraits<Type>::ArrayType;
1155 using value_type = typename Type::c_type;
1156
1157 const auto data_size = static_cast<rle_size_t>(data.length());
1158 const value_type* data_values = static_cast<const ArrayType&>(data).raw_values();
1159
1160 ARROW_SCOPED_TRACE("bit_width = ", bit_width, ", data_size = ", data_size);
1161
1162 // Encode all values into `buffer`.
1163 const auto buffer = EncodeTestArray<Type>(data, bit_width);
1164
1165 // Interleave Advance and GetBatch, verifying decoded values against the original.
1166 RleBitPackedDecoder<value_type> decoder(buffer.data(), static_cast<int>(buffer.size()),
1167 bit_width);
1168 rle_size_t pos = 0;
1169 auto advance = [&](rle_size_t* pos, rle_size_t n) {
1170 n = std::min(n, data_size - *pos);
1171 EXPECT_EQ(decoder.Advance(n), n);
1172 *pos += n;
1173 };
1174 auto read = [&](rle_size_t* pos, rle_size_t n) {
1175 n = std::min(n, data_size - *pos);
1176 std::vector<value_type> got(n);
1177 EXPECT_EQ(decoder.GetBatch(got.data(), n), n);
1178 for (rle_size_t i = 0; i < n; ++i) {
1179 EXPECT_EQ(got[i], data_values[*pos + i]) << "at position " << (*pos + i);
1180 }
1181 *pos += n;
1182 };
1183
1184 // Advance in a `step` small relative to the data size, so we span many
1185 // iterations and repeatedly cross run boundaries.
1186 const rle_size_t step = std::max<rle_size_t>(data_size / 16, 1);
1187 int iter = 0;
1188 while (pos < data_size) {
1189 // Some way to make various successions of `read` of `advance`
1190 if (bit_width % 2 == iter % 3) {
1191 read(&pos, step);
1192 }
1193 advance(&pos, step);
1194 ++iter;
1195 }
1196 // Note: we do not assert exhaustion here because the encoder pads the last
1197 // literal group to a multiple of 8 with zeros, leaving up to 7 extra values.
1198}
1199
1200/// Check RleBitPackedDecoder::CountUpTo, which spans multiple runs through the
1201/// parser (unlike the per-run decoder CountUpTo).

Callers

nothing calls this directly

Calls 6

lengthMethod · 0.45
raw_valuesMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45
AdvanceMethod · 0.45
GetBatchMethod · 0.45

Tested by

no test coverage detected