コード例 #1
0
 /// <summary>
 /// Фаза разделения, разделяем данный на два файла по сортированным фазам длинной step
 /// </summary>
 /// <param name="reader">Источник</param>
 /// <param name="writerOne">Первый получатель</param>
 /// <param name="writerTwo">Второй получатель</param>
 /// <param name="step">Длина сортированной фазы</param>
 private void Devision <TInnerType>(IExternalReader <TInnerType> reader, IExternalWriter <TInnerType> writerOne,
                                    IExternalWriter <TInnerType> writerTwo, long step)
     where TInnerType : class, IComparable
 {
     while (reader.IsNext())
     {
         writerOne.Write(reader.Current);
         for (long i = 1; (i < step) && reader.IsNext(); i++)
         {
             writerOne.Write(reader.Current);
         }
         for (long i = 0; (i < step) && reader.IsNext(); i++)
         {
             writerTwo.Write(reader.Current);
         }
     }
 }
コード例 #2
0
        private void DoPhase <TInnerType>(IExternalReader <TInnerType> readerOne, IExternalReader <TInnerType> readerTwo,
                                          IExternalWriter <TInnerType> writer, long step)
            where TInnerType : class, IComparable
        {
            var stepOne = step;
            var stepTwo = step;

            TInnerType currentFirst  = null;
            TInnerType currentSecond = null;

            while (true)
            {
                currentFirst  = ReadNextStudentInPhase(stepOne, readerOne, currentFirst);
                currentSecond = ReadNextStudentInPhase(stepTwo, readerTwo, currentSecond);

                if (currentFirst == null && currentSecond == null)
                {
                    return;
                }

                if (currentFirst == null && currentSecond != null)
                {
                    FillRest(stepTwo, readerTwo, writer, currentSecond);
                    return;
                }

                if (currentFirst != null && currentSecond == null)
                {
                    FillRest(stepOne, readerOne, writer, currentFirst);
                    return;
                }

                if (currentFirst.CompareTo(currentSecond) > 0)
                {
                    writer.Write(currentSecond);
                    stepTwo--;
                    currentSecond = null;
                }
                else
                {
                    writer.Write(currentFirst);
                    stepOne--;
                    currentFirst = null;
                }
            }
        }
コード例 #3
0
        private void FillRest <TInnerType>(long step, IExternalReader <TInnerType> reader,
                                           IExternalWriter <TInnerType> writer, TInnerType student)
            where TInnerType : class, IComparable
        {
            var localStep    = step;
            var localStudent = student;

            while (localStudent != null)
            {
                writer.Write(localStudent);
                localStep--;
                localStudent = ReadNextStudentInPhase(localStep, reader, null);
            }
        }