+ if (++num_decode_errors < 10) {
+ fprintf(stderr, "Decode error:\n");
+ for (unsigned j = 0; j < num_docids; ++j) {
+ fprintf(stderr, "%3u: reference=%u ours=%u (diff=%d)\n", j, out1[j], out2[j], out1[j] - out2[j]);
+ }
+ }
+ break;
+ }
+ }
+
+ // Test encoding, by encoding with out own implementation
+ // and checking that decoding with the reference gives
+ // the same result. We do not measure performance (we're slow).
+ uint32_t deltas[128];
+ unsigned char *ptr = reinterpret_cast<unsigned char *>(&encoded_pl[0]);
+ ptr = write_baseval(out1[0], ptr);
+ for (unsigned i = 1; i < num_docids; i += 128) {
+ unsigned num_docids_this_block = std::min(num_docids - i, 128u);
+ for (unsigned j = 0; j < num_docids_this_block; ++j) {
+ deltas[j] = out1[i + j] - out1[i + j - 1] - 1;
+ }
+ bool interleaved = (num_docids_this_block == 128);
+ ptr = encode_pfor_single_block<128>(deltas, num_docids_this_block, interleaved, ptr);
+ }
+ own_posting_list_bytes += ptr - reinterpret_cast<unsigned char *>(&encoded_pl[0]);
+
+ pldata = reinterpret_cast<unsigned char *>(&encoded_pl[0]);
+ p4nd1dec128v32(pldata, num_docids, &out2[0]);
+ for (unsigned i = 0; i < num_docids; ++i) {
+ if (out1[i] != out2[i]) {
+ if (++num_encode_errors < 10) {
+ fprintf(stderr, "Encode error:\n");
+ for (unsigned j = 0; j < num_docids; ++j) {
+ fprintf(stderr, "%3u: reference=%u ours=%u (diff=%d)\n", j, out1[j], out2[j], out1[j] - out2[j]);
+ }