in reply to Re^3: [OT] A measure of 'sortedness'?
in thread [OT] A measure of 'sortedness'?

The only little chance of saving anything, I think, is if you have a chunk of data at the beginning or end of the combined buffer that doesn't have to move.

That's exactly what the pre-scan is doing. "Topping and tailing" the two buffers for bits that either don't need to move, or only need to be block-moved rather than merged:

|---| ---| | ___ --- | ___--- --- | ___--- --- |__--- ---| | --- | |

Don't read too much into the ascii art, but there are obviously two chunks, the left and right ends of the left buffer, that can be either left where they are or just block-moved into place, respectively.

There are 5 other possibilities:

  1. 1 requires no further processing: all of the left buffer is less than all of the right buffer.

    (Full scan required.)

  2. 1 requires a single block swap; all of the left buffer is greater than all of the right buffer.

    (Full scan required.

  3. 4 (including the above) that either leave in place or block-move two smaller chunks and need to recurse on the other two.

    (Partial scan if left in place or full if moved.)

What I was looking for was something discoverable or doable during that first scan, that abetted the next stage.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I'm with torvalds on this
In the absence of evidence, opinion is indistinguishable from prejudice. Agile (and TDD) debunked