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

Function CountNextOnes

cpp/src/arrow/util/bit_run_reader.h:354–402  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

352 }
353
354 int64_t CountNextOnes() {
355 assert(current_word_ & kFirstBit);
356
357 int64_t len;
358 if (~current_word_) {
359 const auto num_ones = CountFirstZeros(~current_word_);
360 assert(num_ones <= current_num_bits_);
361 assert(num_ones <= remaining_);
362 remaining_ -= num_ones;
363 current_word_ = ConsumeBits(current_word_, num_ones);
364 current_num_bits_ -= num_ones;
365 if (current_num_bits_) {
366 // Run of ones ends here
367 return num_ones;
368 }
369 len = num_ones;
370 } else {
371 // current_word_ is all ones
372 remaining_ -= 64;
373 current_num_bits_ = 0;
374 len = 64;
375 }
376
377 while (ARROW_PREDICT_TRUE(remaining_ >= 64)) {
378 current_word_ = LoadFullWord();
379 const auto num_ones = CountFirstZeros(~current_word_);
380 len += num_ones;
381 remaining_ -= num_ones;
382 if (num_ones < 64) {
383 // Run of ones ends here
384 current_word_ = ConsumeBits(current_word_, num_ones);
385 current_num_bits_ = 64 - num_ones;
386 return len;
387 }
388 }
389 // Run of ones continues in last bitmap word
390 if (remaining_ > 0) {
391 current_word_ = LoadPartialWord(/*bit_offset=*/0, remaining_);
392 current_num_bits_ = static_cast<int32_t>(remaining_);
393 const auto num_ones = CountFirstZeros(~current_word_);
394 assert(num_ones <= current_num_bits_);
395 assert(num_ones <= remaining_);
396 current_word_ = ConsumeBits(current_word_, num_ones);
397 current_num_bits_ -= num_ones;
398 remaining_ -= num_ones;
399 len += num_ones;
400 }
401 return len;
402 }
403
404 SetBitRun FindCurrentRun() {
405 // Skip any pending zeros

Callers 1

NextRunFunction · 0.85

Calls 2

LoadFullWordFunction · 0.85
LoadPartialWordFunction · 0.85

Tested by

no test coverage detected