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

Function ValidateRleBitPacked

cpp/src/arrow/util/rle_encoding_test.cc:669–715  ·  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

667// exactly 'expected_encoding'.
668// if expected_len is not -1, it will validate the encoded size is correct.
669void ValidateRleBitPacked(const std::vector<int>& values, int bit_width,
670 uint8_t* expected_encoding, int expected_len) {
671 const int len = 64 * 1024;
672#ifdef __EMSCRIPTEN__
673 // don't make this on the stack as it is
674 // too big for emscripten
675 std::vector<uint8_t> buffer_vec(static_cast<size_t>(len));
676 uint8_t* buffer = buffer_vec.data();
677#else
678 uint8_t buffer[len];
679#endif
680 EXPECT_LE(expected_len, len);
681
682 RleBitPackedEncoder encoder(buffer, len, bit_width);
683 for (size_t i = 0; i < values.size(); ++i) {
684 bool result = encoder.Put(values[i]);
685 EXPECT_TRUE(result);
686 }
687 int encoded_len = encoder.Flush();
688
689 if (expected_len != -1) {
690 EXPECT_EQ(encoded_len, expected_len);
691 }
692 if (expected_encoding != NULL && encoded_len == expected_len) {
693 EXPECT_EQ(memcmp(buffer, expected_encoding, encoded_len), 0);
694 }
695
696 // Verify read
697 {
698 RleBitPackedDecoder<uint64_t> decoder(buffer, len, bit_width);
699 for (size_t i = 0; i < values.size(); ++i) {
700 uint64_t val;
701 bool result = decoder.Get(&val);
702 EXPECT_TRUE(result);
703 EXPECT_EQ(values[i], val);
704 }
705 }
706
707 // Verify batch read
708 {
709 RleBitPackedDecoder<int> decoder(buffer, len, bit_width);
710 std::vector<int> values_read(values.size());
711 ASSERT_EQ(values.size(),
712 decoder.GetBatch(values_read.data(), static_cast<int>(values.size())));
713 EXPECT_EQ(values, values_read);
714 }
715}
716
717// A version of ValidateRle that round-trips the values and returns false if
718// 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