Not sure what do you need to do with the merged data, but assuming the individual elements are sufficiently large, what about using and keeping the 10% buffer as an "array of references" instead. It's true than when looping through the merged data, you'd have to do an array accesses and dereference instead of one array access, but it still might work out.

What I mean is that having

@A = qw(a d f i j k l m o q); @B = qw(c e g h p r s t v w);
you'd build
@ref = (\$A[0] \$B[0] \$A[1] \$B[1] \$A[2] \$B[2] \$B[3] \$A[3] \$A[4] + \$A[5] \$A[6] \$A[7] \$A[8] \$B[4] \$A[9] \$B[5] \$B[6] \$B[7] \$B[8 +] \$B[9]);
by a simple, O(n), merge and then the n-th element of the result would be ${$ref[$n]}.

You'd need the buffer to be able to hold 2*n references.

When merging with the next two buffers with their own reference array, you'd need another 4*n*size-of-reference buffer to do the merge and then you'd drop the two old reference arrays.

Jenda
Enoch was right!
Enjoy the last years of Rome.


In reply to Re: [OT] A measure of 'sortedness'? by Jenda
in thread [OT] A measure of 'sortedness'? by BrowserUk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.