MCPcopy Create free account
hub / github.com/coreutils/coreutils / mergelines_node

Function mergelines_node

src/sort.c:3694–3756  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3692 the name of TFP, or is null if TFP is standard output. */
3693
3694static void
3695mergelines_node (struct merge_node *restrict node, size_t total_lines,
3696 FILE *tfp, char const *temp_output)
3697{
3698 struct line *lo_orig = node->lo;
3699 struct line *hi_orig = node->hi;
3700 size_t to_merge = MAX_MERGE (total_lines, node->level);
3701 size_t merged_lo;
3702 size_t merged_hi;
3703
3704 if (node->level > MERGE_ROOT)
3705 {
3706 /* Merge to destination buffer. */
3707 struct line *dest = *node->dest;
3708 while (node->lo != node->end_lo && node->hi != node->end_hi && to_merge--)
3709 if (compare (node->lo - 1, node->hi - 1) <= 0)
3710 *--dest = *--node->lo;
3711 else
3712 *--dest = *--node->hi;
3713
3714 merged_lo = lo_orig - node->lo;
3715 merged_hi = hi_orig - node->hi;
3716
3717 if (node->nhi == merged_hi)
3718 while (node->lo != node->end_lo && to_merge--)
3719 *--dest = *--node->lo;
3720 else if (node->nlo == merged_lo)
3721 while (node->hi != node->end_hi && to_merge--)
3722 *--dest = *--node->hi;
3723 *node->dest = dest;
3724 }
3725 else
3726 {
3727 /* Merge directly to output. */
3728 while (node->lo != node->end_lo && node->hi != node->end_hi && to_merge--)
3729 {
3730 if (compare (node->lo - 1, node->hi - 1) <= 0)
3731 write_unique (--node->lo, tfp, temp_output);
3732 else
3733 write_unique (--node->hi, tfp, temp_output);
3734 }
3735
3736 merged_lo = lo_orig - node->lo;
3737 merged_hi = hi_orig - node->hi;
3738
3739 if (node->nhi == merged_hi)
3740 {
3741 while (node->lo != node->end_lo && to_merge--)
3742 write_unique (--node->lo, tfp, temp_output);
3743 }
3744 else if (node->nlo == merged_lo)
3745 {
3746 while (node->hi != node->end_hi && to_merge--)
3747 write_unique (--node->hi, tfp, temp_output);
3748 }
3749 }
3750
3751 /* Update NODE. */

Callers 1

merge_loopFunction · 0.85

Calls 2

compareFunction · 0.85
write_uniqueFunction · 0.85

Tested by

no test coverage detected