* Process the array contents. * * @ignore * * @param {array} array - The array to process. * @param {function} compare - The comparison function. * * @return {array} - The processed array.
(array, compare)
| 33 | * @return {array} - The processed array. |
| 34 | */ |
| 35 | function Process (array, compare) |
| 36 | { |
| 37 | // Short-circuit when there's nothing to sort. |
| 38 | var len = array.length; |
| 39 | |
| 40 | if (len <= 1) |
| 41 | { |
| 42 | return array; |
| 43 | } |
| 44 | |
| 45 | // Rather than dividing input, simply iterate chunks of 1, 2, 4, 8, etc. |
| 46 | // Chunks are the size of the left or right hand in merge sort. |
| 47 | // Stop when the left-hand covers all of the array. |
| 48 | var buffer = new Array(len); |
| 49 | |
| 50 | for (var chk = 1; chk < len; chk *= 2) |
| 51 | { |
| 52 | RunPass(array, compare, chk, buffer); |
| 53 | |
| 54 | var tmp = array; |
| 55 | |
| 56 | array = buffer; |
| 57 | |
| 58 | buffer = tmp; |
| 59 | } |
| 60 | |
| 61 | return array; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Run a single pass with the given chunk size. |
no test coverage detected
searching dependent graphs…