| 1205 | /// naive count over the original data. |
| 1206 | template <typename Type> |
| 1207 | void CheckCountUpTo(const Array& data, int bit_width, typename Type::c_type value) { |
| 1208 | using ArrayType = typename TypeTraits<Type>::ArrayType; |
| 1209 | using value_type = typename Type::c_type; |
| 1210 | |
| 1211 | const auto data_size = static_cast<rle_size_t>(data.length()); |
| 1212 | const value_type* data_values = |
| 1213 | arrow::internal::checked_cast<const ArrayType&>(data).raw_values(); |
| 1214 | |
| 1215 | ARROW_SCOPED_TRACE("bit_width = ", bit_width, ", data_size = ", data_size, |
| 1216 | ", value = ", value); |
| 1217 | |
| 1218 | // Encode all values into `buffer`. |
| 1219 | const auto buffer = EncodeTestArray<Type>(data, bit_width); |
| 1220 | |
| 1221 | RleBitPackedDecoder<value_type> decoder(buffer.data(), static_cast<int>(buffer.size()), |
| 1222 | bit_width); |
| 1223 | |
| 1224 | // Count in a `step` small relative to the data size, so we span many |
| 1225 | // iterations and repeatedly cross run boundaries. |
| 1226 | const rle_size_t step = std::max<rle_size_t>(data_size / 16, 1); |
| 1227 | rle_size_t pos = 0; |
| 1228 | rle_size_t total_matching = 0; |
| 1229 | while (pos < data_size) { |
| 1230 | const auto to_process = std::min(step, data_size - pos); |
| 1231 | const auto res = decoder.CountUpTo(value, to_process); |
| 1232 | ASSERT_EQ(res.processed_count, to_process); |
| 1233 | |
| 1234 | // The matching count of this batch must equal a naive count over the data. |
| 1235 | const auto expected = |
| 1236 | std::count(data_values + pos, data_values + pos + to_process, value); |
| 1237 | EXPECT_EQ(res.matching_count, static_cast<rle_size_t>(expected)) |
| 1238 | << "at position " << pos; |
| 1239 | |
| 1240 | pos += res.processed_count; |
| 1241 | total_matching += res.matching_count; |
| 1242 | } |
| 1243 | EXPECT_EQ(pos, data_size) << "Total number of values processed is off"; |
| 1244 | const auto total_expected = std::count(data_values, data_values + data_size, value); |
| 1245 | EXPECT_EQ(total_matching, static_cast<rle_size_t>(total_expected)); |
| 1246 | |
| 1247 | // The decoder is exhausted of the values we requested: counting further only |
| 1248 | // yields the padding values the encoder appended to the last literal group. |
| 1249 | const auto res = decoder.CountUpTo(value, data_size); |
| 1250 | EXPECT_LT(res.processed_count, 8); |
| 1251 | } |
| 1252 | |
| 1253 | template <typename T> |
| 1254 | struct DataTestRleBitPackedRandomPart { |