| 162 | } |
| 163 | |
| 164 | int ValidateRleSkip( |
| 165 | const vector<int>& values, int bit_width, int skip_at, int skip_count) { |
| 166 | stringstream ss; |
| 167 | ss << "bit_width=" << bit_width |
| 168 | << " skip_at=" << skip_at |
| 169 | << " skip_count=" << skip_count |
| 170 | << " values.size()=" << values.size(); |
| 171 | const string& description = ss.str(); |
| 172 | const int len = 64 * 1024; |
| 173 | uint8_t buffer[len]; |
| 174 | |
| 175 | RleEncoder encoder(buffer, len, bit_width); |
| 176 | int encoded_len = 0; |
| 177 | |
| 178 | for (int i = 0; i < values.size(); ++i) { |
| 179 | bool result = encoder.Put(values[i]); |
| 180 | EXPECT_TRUE(result); |
| 181 | } |
| 182 | encoded_len = encoder.Flush(); |
| 183 | |
| 184 | vector<int> expected_values(values.begin(), values.begin() + skip_at); |
| 185 | for (int i = skip_at + skip_count; i < values.size(); ++i) { |
| 186 | expected_values.push_back(values[i]); |
| 187 | } |
| 188 | |
| 189 | // Verify read. |
| 190 | RleBatchDecoder<uint64_t> per_value_decoder(buffer, len, bit_width); |
| 191 | RleBatchDecoder<uint64_t> per_run_decoder(buffer, len, bit_width); |
| 192 | RleBatchDecoder<uint64_t> batch_decoder(buffer, len, bit_width); |
| 193 | // Ensure it returns the same results after Reset(). |
| 194 | for (int trial = 0; trial < 2; ++trial) { |
| 195 | for (int i = 0; i < skip_at; ++i) { |
| 196 | uint64_t val; |
| 197 | EXPECT_TRUE(per_value_decoder.GetSingleValue(&val)) << description; |
| 198 | EXPECT_EQ(expected_values[i], val) << description << " i=" << i << " trial=" |
| 199 | << trial; |
| 200 | } |
| 201 | per_value_decoder.SkipValues(skip_count); |
| 202 | for (int i = skip_at; i < expected_values.size(); ++i) { |
| 203 | uint64_t val; |
| 204 | EXPECT_TRUE(per_value_decoder.GetSingleValue(&val)) << description; |
| 205 | EXPECT_EQ(expected_values[i], val) << description << " i=" << i << " trial=" |
| 206 | << trial; |
| 207 | } |
| 208 | // Unpack everything at once from the other decoders. |
| 209 | vector<uint64_t> decoded_values1(expected_values.size()); |
| 210 | vector<uint64_t> decoded_values2(expected_values.size()); |
| 211 | EXPECT_TRUE( |
| 212 | GetRleValuesSkip(&per_run_decoder, values.size(), |
| 213 | decoded_values1.data(), skip_at, skip_count)) << description; |
| 214 | EXPECT_TRUE( |
| 215 | GetRleValuesBatchedSkip(&batch_decoder, values.size(), |
| 216 | decoded_values2.data(), skip_at, skip_count)) << description; |
| 217 | for (int i = 0; i < expected_values.size(); ++i) { |
| 218 | EXPECT_EQ(expected_values[i], decoded_values1[i]) << description << " i=" << i; |
| 219 | EXPECT_EQ(expected_values[i], decoded_values2[i]) << description << " i=" << i; |
| 220 | } |
| 221 | per_value_decoder.Reset(buffer, len, bit_width); |
nothing calls this directly
no test coverage detected