static public void Copy(IMemoryAcessor source, long sourceIndex, IMemoryAcessor destination, long destinationIndex, long length, CancellationToken token) { for (long index = 0; index < length; ++index) { token.ThrowIfCancellationRequested(); destination.Write(destinationIndex + index, source.Read(sourceIndex + index)); } }
static void Merge(IMemoryAcessor aux, IMemoryAcessor ma, long start, long mid, long end, CancellationToken token) { Utils.Copy(ma, start, aux, start, mid - start, token); long left = start; long right = mid; long index = start; while (left < mid && right < end) { token.ThrowIfCancellationRequested(); if (aux.Read(left) < ma.Read(right)) { ma.Write(index++, aux.Read(left++)); } else { ma.Write(index++, ma.Read(right++)); } } Utils.Copy(aux, left, ma, index, mid - left, token); }