| 560 | }; |
| 561 | |
| 562 | Result<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 | |
| 588 | using Formatter = std::function<void(const Array&, int64_t index, std::ostream*)>; |
| 589 | |