Exemple #1
0
        public static void Sort <T>(T[] collection, int index, int length, IComparer <T> comparer)
        {
            if (length <= 0)
            {
                return;
            }

            var state = SortState.Acquire();

            try
            {
                // Initial partition
                state.Partitions.Enqueue(new SortRange(index, length - 1));

                // Sort recursively
                state.AddReference();
                Sort(collection, MaxDegreeOfParallelism, comparer, state);

                // Wait for all work to finish
                if (state.ActiveWorkerCount != 0)
                {
                    state.Finished.WaitOne();
                }
            }
            finally
            {
                state.Release();
            }
        }
Exemple #2
0
        public static void Sort <T>(T[] collection, int index, int length, IComparer <T> comparer)
        {
            if (length <= 0)
            {
                return;
            }

            var state = SortState.Acquire(MaxDegreeOfParallelism);

            try
            {
                // Initial partition
                Interlocked.Increment(ref state.OpLeft);
                state.Partitions.Enqueue(new SortRange(index, length - 1));

                // Sort recursively
                state.AddReference();
                SortOnThread(collection, comparer, state);

                // Wait for all work to finish
                state.WaitCompletion();
            }
            finally
            {
                state.Release();
            }
        }