timsort.js
/**
 * Ensures that the external array tmp has at least the specified
 * number of elements, increasing its size if necessary.  The size
 * increases exponentially to ensure amortized linear time complexity. 
 * @param {TimSort} tim 
 * @param {Number} minCapacity 
 * @returns {Array}
 */
Ensures that the external array tmp has at least the specified
number of elements, increasing its size if necessary.  The size
increases exponentially to ensure amortized linear time complexity.
@param {TimSort} tim
@param {Number} minCapacity
@returns {Array}
Ensures that the external array tmp has at least the specified number of elements increasing its size if necessary . The size increases exponentially to ensure amortized linear time complexity . @param { TimSort } tim @param { Number } minCapacity @returns { Array }
function ensureCapacity(tim, minCapacity){
    let tmp = tim.tmp;
    if (tmp.length < minCapacity) {
        let newSize = minCapacity;
        newSize |= newSize >> 1;
        newSize |= newSize >> 2;
        newSize |= newSize >> 4;
        newSize |= newSize >> 8;
        newSize |= newSize >> 16;
        newSize++;
        if (newSize < 0) 
            newSize = minCapacity;
        else
            newSize = Math.min(newSize, tim.arr.length >>> 1);
        let newArray = new tim.T(newSize);
        tmp = newArray;
    }
    return tmp;
}
function ensureCapacity ( tim , minCapacity ) { let tmp = tim . tmp ; if ( tmp . length < minCapacity ) { let newSize = minCapacity ; newSize |= newSize >> 1 ; newSize |= newSize >> 2 ; newSize |= newSize >> 4 ; newSize |= newSize >> 8 ; newSize |= newSize >> 16 ; newSize ++ ; if ( newSize < 0 ) newSize = minCapacity ; else newSize = Math . min ( newSize , tim . arr . length >>> 1 ) ; let newArray = new tim . T ( newSize ) ; tmp = newArray ; } return tmp ; }
Ensures that the external array tmp has at least the specified
 number of elements, increasing its size if necessary.
Ensures that the external array tmp has at least the specified number of elements increasing its size if necessary .
// Compute smallest power of 2 > minCapacity
 // Not bloody likely!
