Beispiel #1
0
 /// <summary>
 /// Moves over the last parts of the chunks.
 /// </summary>
 /// <param name="left">TimChunk of the left hand side.</param>
 /// <param name="right">TimChunk of the right hand side.</param>
 /// <param name="dest">The current target point for the remaining values.</param>
 private static void FinalizeMerge(TimChunk <T> left, TimChunk <T> right, int dest)
 {
     if (left.Remaining == 1)
     {
         Array.Copy(right.Array, right.Index, right.Array, dest, right.Remaining);
         right.Array[dest + right.Remaining] = left.Array[left.Index];
     }
     else if (left.Remaining == 0)
     {
         throw new ArgumentException("Comparison method violates its general contract!");
     }
     else
     {
         Array.Copy(left.Array, left.Index, right.Array, dest, left.Remaining);
     }
 }
Beispiel #2
0
        /// <summary>
        /// Check the chunks before getting in to a merge to make sure there's something to actually do.
        /// </summary>
        /// <param name="left">TimChunk of the left hand side.</param>
        /// <param name="right">TimChunk of the right hand side.</param>
        /// <param name="dest">The current target point for the remaining values.</param>
        /// <returns>If a merge is required.</returns>
        private static bool NeedsMerge(TimChunk <T> left, TimChunk <T> right, ref int dest)
        {
            right.Array[dest++] = right.Array[right.Index++];
            if (--right.Remaining == 0)
            {
                Array.Copy(left.Array, left.Index, right.Array, dest, left.Remaining);
                return(false);
            }

            if (left.Remaining == 1)
            {
                Array.Copy(right.Array, right.Index, right.Array, dest, right.Remaining);
                right.Array[dest + right.Remaining] = left.Array[left.Index];
                return(false);
            }

            return(true);
        }