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

Function NullDiff

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

Source from the content-addressed store, hash-verified

560};
561
562Result<std::shared_ptr<StructArray>> NullDiff(const Array& base, const Array& target,
563 MemoryPool* pool) {
564 bool insert = base.length() < target.length();
565 auto run_length = std::min(base.length(), target.length());
566 auto edit_count = std::max(base.length(), target.length()) - run_length;
567
568 TypedBufferBuilder<bool> insert_builder(pool);
569 RETURN_NOT_OK(insert_builder.Resize(edit_count + 1));
570 insert_builder.UnsafeAppend(false);
571 TypedBufferBuilder<int64_t> run_length_builder(pool);
572 RETURN_NOT_OK(run_length_builder.Resize(edit_count + 1));
573 run_length_builder.UnsafeAppend(run_length);
574 if (edit_count > 0) {
575 insert_builder.UnsafeAppend(edit_count, insert);
576 run_length_builder.UnsafeAppend(edit_count, 0);
577 }
578
579 std::shared_ptr<Buffer> insert_buf, run_length_buf;
580 RETURN_NOT_OK(insert_builder.Finish(&insert_buf));
581 RETURN_NOT_OK(run_length_builder.Finish(&run_length_buf));
582
583 return StructArray::Make({std::make_shared<BooleanArray>(edit_count + 1, insert_buf),
584 std::make_shared<Int64Array>(edit_count + 1, run_length_buf)},
585 {field("insert", boolean()), field("run_length", int64())});
586}
587
588using Formatter = std::function<void(const Array&, int64_t index, std::ostream*)>;
589

Callers 1

DiffFunction · 0.85

Calls 6

MakeFunction · 0.70
fieldFunction · 0.50
lengthMethod · 0.45
ResizeMethod · 0.45
UnsafeAppendMethod · 0.45
FinishMethod · 0.45

Tested by

no test coverage detected