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

Method TestUnpackAlternating

cpp/src/arrow/util/bpacking_test.cc:164–191  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

162 }
163
164 void TestUnpackAlternating(UnpackFunc<Int> unpack, const UnpackOptions& opts) {
165 const auto num_bytes = GetNumBytes(opts.batch_size, opts.bit_width, opts.bit_offset);
166
167 // Pick between two different bit patterns so that we always unpack starting with 1
168 const uint8_t byte = opts.bit_offset % 2 == 0 ? 0b10101010 : 0b01010101;
169 const std::vector<uint8_t> packed(static_cast<std::size_t>(num_bytes), byte);
170 const auto unpacked = UnpackValues(packed.data(), opts, unpack);
171
172 // Generate alternative bit sequence starting with either 0 or 1
173 Int one_zero_value = 0;
174 Int zero_one_value = 0;
175 for (int i = 0; i < opts.bit_width; ++i) {
176 zero_one_value = (zero_one_value << 1) | (i % 2);
177 one_zero_value = (one_zero_value << 1) | ((i + 1) % 2);
178 }
179
180 std::vector<Int> expected;
181 if (opts.bit_width % 2 == 0) {
182 // For even bit_width, the same pattern repeats every time
183 expected.resize(static_cast<std::size_t>(opts.batch_size), one_zero_value);
184 } else {
185 // For odd bit_width, we alternate a pattern leading with 0 and 1
186 for (int i = 0; i < opts.batch_size; ++i) {
187 expected.push_back(i % 2 == 0 ? zero_one_value : one_zero_value);
188 }
189 }
190 EXPECT_EQ(unpacked, expected);
191 }
192
193 void TestAll(UnpackFunc<Int> unpack) {
194 // There are actually many differences across the different sizes.

Callers

nothing calls this directly

Calls 5

UnpackValuesFunction · 0.85
resizeMethod · 0.80
push_backMethod · 0.80
GetNumBytesFunction · 0.70
dataMethod · 0.45

Tested by

no test coverage detected