Exemplo n.º 1
0
        /// <exception cref="System.IO.IOException"/>
        public static void WriteFile <K, V>(RawKeyValueIterator records, IFile.Writer <K, V
                                                                                       > writer, Progressable progressable, Configuration conf)
        {
            long progressBar = conf.GetLong(JobContext.RecordsBeforeProgress, 10000);
            long recordCtr   = 0;

            while (records.Next())
            {
                writer.Append(records.GetKey(), records.GetValue());
                if (((recordCtr++) % progressBar) == 0)
                {
                    progressable.Progress();
                }
            }
        }
Exemplo n.º 2
0
        public void Sort(IndexedSortable s, int p, int r, Progressable rep)
        {
            int N = r - p;
            // build heap w/ reverse comparator, then write in-place from end
            int t = int.HighestOneBit(N);

            for (int i = t; i > 1; i = (int)(((uint)i) >> 1))
            {
                for (int j = (int)(((uint)i) >> 1); j < i; ++j)
                {
                    DownHeap(s, p - 1, j, N + 1);
                }
                if (null != rep)
                {
                    rep.Progress();
                }
            }
            for (int i_1 = r - 1; i_1 > p; --i_1)
            {
                s.Swap(p, i_1);
                DownHeap(s, p - 1, 1, i_1 - p + 1);
            }
        }
Exemplo n.º 3
0
 private static void SortInternal(IndexedSortable s, int p, int r, Progressable rep
                                  , int depth)
 {
     if (null != rep)
     {
         rep.Progress();
     }
     while (true)
     {
         if (r - p < 13)
         {
             for (int i = p; i < r; ++i)
             {
                 for (int j = i; j > p && s.Compare(j - 1, j) > 0; --j)
                 {
                     s.Swap(j, j - 1);
                 }
             }
             return;
         }
         if (--depth < 0)
         {
             // give up
             alt.Sort(s, p, r, rep);
             return;
         }
         // select, move pivot into first position
         Fix(s, (int)(((uint)(p + r)) >> 1), p);
         Fix(s, (int)(((uint)(p + r)) >> 1), r - 1);
         Fix(s, p, r - 1);
         // Divide
         int i_1 = p;
         int j_1 = r;
         int ll  = p;
         int rr  = r;
         int cr;
         while (true)
         {
             while (++i_1 < j_1)
             {
                 if ((cr = s.Compare(i_1, p)) > 0)
                 {
                     break;
                 }
                 if (0 == cr && ++ll != i_1)
                 {
                     s.Swap(ll, i_1);
                 }
             }
             while (--j_1 > i_1)
             {
                 if ((cr = s.Compare(p, j_1)) > 0)
                 {
                     break;
                 }
                 if (0 == cr && --rr != j_1)
                 {
                     s.Swap(rr, j_1);
                 }
             }
             if (i_1 < j_1)
             {
                 s.Swap(i_1, j_1);
             }
             else
             {
                 break;
             }
         }
         j_1 = i_1;
         // swap pivot- and all eq values- into position
         while (ll >= p)
         {
             s.Swap(ll--, --i_1);
         }
         while (rr < r)
         {
             s.Swap(rr++, j_1++);
         }
         // Conquer
         // Recurse on smaller interval first to keep stack shallow
         System.Diagnostics.Debug.Assert(i_1 != j_1);
         if (i_1 - p < r - j_1)
         {
             SortInternal(s, p, i_1, rep, depth);
             p = j_1;
         }
         else
         {
             SortInternal(s, j_1, r, rep, depth);
             r = i_1;
         }
     }
 }