private static void tandemMerge ( final double [ ] keySrc , final long [ ] valSrc , final int arrStart1 , final int arrLen1 , final int arrStart2 , final int arrLen2 , final double [ ] keyDst , final long [ ] valDst , final int arrStart3 ) { final int arrStop1 = arrStart1 + arrLen1 ; final int arrStop2 = arrStart2 + arrLen2 ; int i1 = arrStart1 ; int i2 = arrStart2 ; int i3 = arrStart3 ; while ( ( i1 < arrStop1 ) && ( i2 < arrStop2 ) ) { if ( keySrc [ i2 ] < keySrc [ i1 ] ) { keyDst [ i3 ] = keySrc [ i2 ] ; valDst [ i3 ] = valSrc [ i2 ] ; i2 ++ ; } else { keyDst [ i3 ] = keySrc [ i1 ] ; valDst [ i3 ] = valSrc [ i1 ] ; i1 ++ ; } i3 ++ ; } if ( i1 < arrStop1 ) { arraycopy ( keySrc , i1 , keyDst , i3 , arrStop1 - i1 ) ; arraycopy ( valSrc , i1 , valDst , i3 , arrStop1 - i1 ) ; } else { assert i2 < arrStop2 ; arraycopy ( keySrc , i2 , keyDst , i3 , arrStop2 - i2 ) ; arraycopy ( valSrc , i2 , valDst , i3 , arrStop2 - i2 ) ; } }
Performs two merges in tandem . One of them provides the sort keys while the other one passively undergoes the same data motion .