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

Function RunVisitWordsAndWriteLoop

cpp/src/arrow/util/bitmap.h:252–311  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

250
251 template <size_t N, size_t M, typename ReaderT, typename WriterT, typename Visitor>
252 static void RunVisitWordsAndWriteLoop(int64_t bit_length,
253 std::array<ReaderT, N>& readers,
254 std::array<WriterT, M>& writers,
255 Visitor&& visitor) {
256 using Word = decltype(readers[0].NextWord());
257 constexpr int64_t kBitWidth = sizeof(Word) * 8;
258
259 std::array<Word, N> visited_words;
260 std::array<Word, M> output_words;
261
262 // every reader will have same number of words, since they are same length'ed
263 // TODO($JIRA) this will be inefficient in some cases. When there are offsets beyond
264 // Word boundary, every Word would have to be created from 2 adjoining Words
265 auto n_words = readers[0].words();
266 bit_length -= n_words * kBitWidth;
267 while (n_words--) {
268 // first collect all words to visited_words array
269 for (size_t i = 0; i < N; i++) {
270 visited_words[i] = readers[i].NextWord();
271 }
272 visitor(visited_words, &output_words);
273 for (size_t i = 0; i < M; i++) {
274 writers[i].PutNextWord(output_words[i]);
275 }
276 }
277
278 // every reader will have same number of trailing bytes, because of the above reason
279 // tailing portion could be more than one word! (ref: BitmapWordReader constructor)
280 // remaining full/ partial words to write
281
282 if (bit_length) {
283 // convert the word visitor lambda to a byte_visitor
284 auto byte_visitor = [&](const std::array<uint8_t, N>& in,
285 std::array<uint8_t, M>* out) {
286 std::array<Word, N> in_words;
287 std::array<Word, M> out_words;
288 std::copy(in.begin(), in.end(), in_words.begin());
289 visitor(in_words, &out_words);
290 for (size_t i = 0; i < M; i++) {
291 out->at(i) = static_cast<uint8_t>(out_words[i]);
292 }
293 };
294
295 std::array<uint8_t, N> visited_bytes;
296 std::array<uint8_t, M> output_bytes;
297 int n_bytes = readers[0].trailing_bytes();
298 while (n_bytes--) {
299 visited_bytes.fill(0);
300 output_bytes.fill(0);
301 int valid_bits;
302 for (size_t i = 0; i < N; i++) {
303 visited_bytes[i] = readers[i].NextTrailingByte(valid_bits);
304 }
305 byte_visitor(visited_bytes, &output_bytes);
306 for (size_t i = 0; i < M; i++) {
307 writers[i].PutNextTrailingByte(output_bytes[i], valid_bits);
308 }
309 }

Callers 1

VisitWordsAndWriteFunction · 0.85

Calls 9

PutNextWordMethod · 0.80
trailing_bytesMethod · 0.80
fillMethod · 0.80
NextTrailingByteMethod · 0.80
PutNextTrailingByteMethod · 0.80
NextWordMethod · 0.45
wordsMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected