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

Function ValidateRleBitPacked

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

Validates encoding of values by encoding and decoding them. If expected_encoding != NULL, also validates that the encoded buffer is exactly 'expected_encoding'. if expected_len is not -1, it will validate the encoded size is correct.

Source from the content-addressed store, hash-verified

641// exactly 'expected_encoding'.
642// if expected_len is not -1, it will validate the encoded size is correct.
643void ValidateRleBitPacked(const std::vector<int>& values, int bit_width,
644 uint8_t* expected_encoding, int expected_len) {
645 const int len = 64 * 1024;
646#ifdef __EMSCRIPTEN__
647 // don't make this on the stack as it is
648 // too big for emscripten
649 std::vector<uint8_t> buffer_vec(static_cast<size_t>(len));
650 uint8_t* buffer = buffer_vec.data();
651#else
652 uint8_t buffer[len];
653#endif
654 EXPECT_LE(expected_len, len);
655
656 RleBitPackedEncoder encoder(buffer, len, bit_width);
657 for (size_t i = 0; i < values.size(); ++i) {
658 bool result = encoder.Put(values[i]);
659 EXPECT_TRUE(result);
660 }
661 int encoded_len = encoder.Flush();
662
663 if (expected_len != -1) {
664 EXPECT_EQ(encoded_len, expected_len);
665 }
666 if (expected_encoding != NULL && encoded_len == expected_len) {
667 EXPECT_EQ(memcmp(buffer, expected_encoding, encoded_len), 0);
668 }
669
670 // Verify read
671 {
672 RleBitPackedDecoder<uint64_t> decoder(buffer, len, bit_width);
673 for (size_t i = 0; i < values.size(); ++i) {
674 uint64_t val;
675 bool result = decoder.Get(&val);
676 EXPECT_TRUE(result);
677 EXPECT_EQ(values[i], val);
678 }
679 }
680
681 // Verify batch read
682 {
683 RleBitPackedDecoder<int> decoder(buffer, len, bit_width);
684 std::vector<int> values_read(values.size());
685 ASSERT_EQ(values.size(),
686 decoder.GetBatch(values_read.data(), static_cast<int>(values.size())));
687 EXPECT_EQ(values, values_read);
688 }
689}
690
691// A version of ValidateRle that round-trips the values and returns false if
692// the returned values are not all the same

Callers 2

TESTFunction · 0.85
TestRleValuesFunction · 0.85

Calls 6

dataMethod · 0.45
sizeMethod · 0.45
PutMethod · 0.45
FlushMethod · 0.45
GetMethod · 0.45
GetBatchMethod · 0.45

Tested by

no test coverage detected