Algorithm-RectanglesContainingDot_XS
view release on metacpan or search on metacpan
* Note that we merge runs 1 and 2 immediately after copying them,
* while they are still likely to be in fast cache. Similarly,
* run 3 is merged with run 12 while it still may be lingering in cache.
* This implementation should therefore enjoy much of the cache-friendly
* behavior that quicksort does. In addition, it does less copying
* than the original mergesort implementation (only runs 1 and 2 are copied)
* and the "balancing" of merges is better (merged runs comprise more nearly
* equal numbers of original runs).
*
* The actual cache-friendly implementation will use a pseudo-stack
* to avoid recursion, and will unroll processing of runs of length 2,
* but it is otherwise similar to the recursive implementation.
*/
typedef struct {
IV offset; /* offset of 1st of 2 runs at this level */
IV runs; /* how many runs must be combined into 1 */
} off_runs; /* pseudo-stack element */
static void
sortsv(pTHX_ SV **base, size_t nmemb, SVCOMPARE_t cmp)
--stackp;
t = list1; list1 = list2; list2 = t; /* swap lists */
} while ((runs = stackp->runs) == 0);
}
stackp->runs = 0; /* current run will finish level */
/* While there are more than 2 runs remaining,
* turn them into exactly 2 runs (at the "other" level),
* each made up of approximately half the runs.
* Stack the second half for later processing,
* and set about producing the first half now.
*/
while (runs > 2) {
++level;
++stackp;
stackp->offset = offset;
runs -= stackp->runs = runs / 2;
}
/* We must construct a single run from 1 or 2 runs.
* All the original runs are in which[0] == base.
( run in 0.295 second using v1.01-cache-2.11-cpan-8d75d55dd25 )