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

Function CountNextOnes

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

Source from the content-addressed store, hash-verified

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

Callers 1

NextRunFunction · 0.85

Calls 2

LoadFullWordFunction · 0.85
LoadPartialWordFunction · 0.85

Tested by

no test coverage detected