public static JobHandle MergeSlices <T>(
                NativeList <T> result,
                NativeList <T>[] buffers,
                ref SortState state,
                JobHandle inputDeps)
                where T : struct, IComparable <T>
            {
                var proceedToNextBuffer = false;
                var mergeAmount         = state.ProcessAmount * state.ConcurrentSorts;
                var leftIndexUnit       = new NativeUnit <int>(state.LeftIndex, Allocator.TempJob);
                var rightIndexUnit      = new NativeUnit <int>(state.RightIndex, Allocator.TempJob);
                var resultIndexUnit     = new NativeUnit <int>(state.ResultIndex, Allocator.TempJob);

                state.WriteBufferIndex += state.WriteBufferIndex == 0 ? state.BaseSliceCount : 0;
                while (state.WriteBufferIndex < buffers.Length && mergeAmount > 0)
                {
                    var mergeInputDeps = default(JobHandle);
                    if (state.ResultIndex == 0)
                    {
                        mergeInputDeps = buffers[state.WriteBufferIndex].Resize(buffers[state.ReadBufferIndex].Length + buffers[state.ReadBufferIndex + 1].Length, inputDeps);
                    }
                    mergeInputDeps = new Merge <T> {
                        LeftArray     = buffers[state.ReadBufferIndex].AsDeferredJobArray(),
                        RightArray    = buffers[state.ReadBufferIndex + 1].AsDeferredJobArray(),
                        Target        = buffers[state.WriteBufferIndex].AsDeferredJobArray(),
                        LeftIndex     = leftIndexUnit,
                        RightIndex    = rightIndexUnit,
                        ResultIndex   = resultIndexUnit,
                        MaxMergeCount = mergeAmount
                    }.Schedule(mergeInputDeps);
                    mergeInputDeps.Complete();
                    mergeAmount -= resultIndexUnit.Value - state.ResultIndex;
                    // We've reached the end of the write buffer so we can proceed to the next one
                    proceedToNextBuffer = resultIndexUnit.Value == buffers[state.WriteBufferIndex].Length;
                    if (proceedToNextBuffer)
                    {
                        state.ReadBufferIndex += 2;
                        state.WriteBufferIndex++;
                        leftIndexUnit.Value = rightIndexUnit.Value = resultIndexUnit.Value = 0;
                        state.LeftIndex     = state.RightIndex = state.ResultIndex = 0;
                    }
                    else
                    {
                        break;
                    }
                }

                state.LeftIndex   = proceedToNextBuffer ? 0 : leftIndexUnit.Value;
                state.RightIndex  = proceedToNextBuffer ? 0 : rightIndexUnit.Value;
                state.ResultIndex = proceedToNextBuffer ? 0 : resultIndexUnit.Value;

                leftIndexUnit.Dispose();
                rightIndexUnit.Dispose();
                resultIndexUnit.Dispose();
                return(inputDeps);
            }