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

Method GetEdits

cpp/src/arrow/array/diff.cc:474–513  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

472 bool Done() { return finish_index_ != -1; }
473
474 Result<std::shared_ptr<StructArray>> GetEdits(MemoryPool* pool) {
475 DCHECK(Done());
476
477 int64_t length = edit_count_ + 1;
478 ARROW_ASSIGN_OR_RAISE(auto insert_buf, AllocateEmptyBitmap(length, pool));
479 ARROW_ASSIGN_OR_RAISE(auto run_length_buf,
480 AllocateBuffer(length * sizeof(int64_t), pool));
481 auto run_length = reinterpret_cast<int64_t*>(run_length_buf->mutable_data());
482
483 auto index = finish_index_;
484 auto endpoint = GetEditPoint(edit_count_, finish_index_);
485
486 for (int64_t i = edit_count_; i > 0; --i) {
487 bool insert = insert_[index];
488 bit_util::SetBitTo(insert_buf->mutable_data(), i, insert);
489
490 auto insertions_minus_deletions =
491 (endpoint.base - base_begin_) - (endpoint.target - target_begin_);
492 if (insert) {
493 ++insertions_minus_deletions;
494 } else {
495 --insertions_minus_deletions;
496 }
497 index = (i - 1 - insertions_minus_deletions) / 2 + StorageOffset(i - 1);
498
499 // endpoint of previous edit
500 auto previous = GetEditPoint(i - 1, index);
501 run_length[i] = endpoint.base - previous.base - !insert;
502 DCHECK_GE(run_length[i], 0);
503
504 endpoint = previous;
505 }
506 bit_util::SetBitTo(insert_buf->mutable_data(), 0, false);
507 run_length[0] = endpoint.base - base_begin_;
508
509 return StructArray::Make(
510 {std::make_shared<BooleanArray>(length, std::move(insert_buf)),
511 std::make_shared<Int64Array>(length, std::move(run_length_buf))},
512 {field("insert", boolean()), field("run_length", int64())});
513 }
514
515 public:
516 Result<std::shared_ptr<StructArray>> Diff() {

Callers

nothing calls this directly

Calls 4

MakeFunction · 0.70
SetBitToFunction · 0.50
fieldFunction · 0.50
mutable_dataMethod · 0.45

Tested by

no test coverage detected