Macaulay2 Engine
Loading...
Searching...
No Matches

◆ sortD()

template<typename Sorter>
void QuickSorter< Sorter >::sortD ( )
private

Definition at line 322 of file monsort.hpp.

323{
324 unsigned long i, ir, j, l;
325 value rra;
326 long ncmps;
327
328 ncmps = 0;
329 if (len < 2) return;
330 l = (len >> 1) + 1;
331 ir = len;
332 for (;;)
333 {
334 if (l > 1)
335 {
336 rra = elems[--l];
337 }
338 else
339 {
340 rra = elems[ir];
341 elems[ir] = elems[1];
342 if (--ir == 1)
343 {
344 elems[1] = rra;
345 break;
346 }
347 }
348 i = l;
349 j = l + l;
350 while (j <= ir)
351 {
352 if (j < ir)
353 {
354 ncmps++;
355 if (M->compare(elems[j], elems[j + 1]) < 0) j++;
356 }
357 ncmps++;
358 if (M->compare(rra, elems[j]) < 0)
359 {
360 elems[i] = elems[j];
361 i = j;
362 j <<= 1;
363 }
364 else
365 j = ir + 1;
366 }
367 elems[i] = rra;
368 }
369 fprintf(stderr, "hpsort: %ld, %ld\n", len, ncmps);
370}
Sorter * M
Definition monsort.hpp:50
value * elems
Definition monsort.hpp:51
Sorter::value value
Definition monsort.hpp:49

References elems, len, and M.

Referenced by sort().