/*
- * Sherlock Library -- Universal Array Sorter
+ * UCW Library -- Universal Array Sorter
*
* (c) 2003 Martin Mares <mj@ucw.cz>
*
* ASORT_ELT(i) [*] returns the key of i-th element
* ASORT_LT(x,y) x < y for ASORT_TYPE (default: "x<y")
* ASORT_SWAP(i,j) swap i-th and j-th element (default: assume _ELT
- * is a l-value and swap just the keys)
+ * is an l-value and swap just the keys)
* ASORT_THRESHOLD threshold for switching between quicksort and insertsort
+ * ASORT_EXTRA_ARGS extra arguments for the sort function (they are always
+ * visible in all the macros supplied above), starts with comma
*
* After including this file, a function ASORT_PREFIX(sort)(uns array_size)
* is declared and all parameter macros are automatically undef'd.
#define ASORT_THRESHOLD 8 /* Guesswork and experimentation */
#endif
-static void ASORT_PREFIX(sort)(uns array_size)
+#ifndef ASORT_EXTRA_ARGS
+#define ASORT_EXTRA_ARGS
+#endif
+
+static void ASORT_PREFIX(sort)(uns array_size ASORT_EXTRA_ARGS)
{
struct stk { int l, r; } stack[8*sizeof(uns)];
int l, r, left, right, m;
}
}
while (l <= r);
- if ((r - left) > ASORT_THRESHOLD && (right - l) > ASORT_THRESHOLD)
+ if ((r - left) >= ASORT_THRESHOLD && (right - l) >= ASORT_THRESHOLD)
{
/* Both partitions ok => push the larger one */
if ((r - left) > (right - l))
}
sp++;
}
- else if ((r - left) > ASORT_THRESHOLD)
+ else if ((r - left) >= ASORT_THRESHOLD)
{
/* Left partition OK, right undersize */
right = r;
}
- else if ((right - l) > ASORT_THRESHOLD)
+ else if ((right - l) >= ASORT_THRESHOLD)
{
/* Right partition OK, left undersize */
left = l;
}
#undef ASORT_PREFIX
-#undef ASORT_TYPE
+#undef ASORT_KEY_TYPE
#undef ASORT_ELT
-#undef ASORT_EQ
+#undef ASORT_LT
#undef ASORT_SWAP
#undef ASORT_THRESHOLD
+#undef ASORT_EXTRA_ARGS