ASORT_ELT is no longer mandatory; if it is not used, the sorting function
gets a pointer of an array to be sorted as its first argument.
- * UCW Library -- Universal Array Sorter
+ * UCW Library -- Universal Simple Array Sorter
- * (c) 2003 Martin Mares <mj@ucw.cz>
+ * (c) 2003--2008 Martin Mares <mj@ucw.cz>
*
* This software may be freely distributed and used according to the terms
* of the GNU Lesser General Public License.
*
* This software may be freely distributed and used according to the terms
* of the GNU Lesser General Public License.
* ASORT_PREFIX(x) [*] add a name prefix (used on all global names
* defined by the sorter)
* ASORT_KEY_TYPE [*] data type of a single array entry key
* ASORT_PREFIX(x) [*] add a name prefix (used on all global names
* defined by the sorter)
* ASORT_KEY_TYPE [*] data type of a single array entry key
- * ASORT_ELT(i) [*] returns the key of i-th element
+ * ASORT_ELT(i) returns the key of i-th element; if this macro is not
+ * defined, the function gets a pointer to an array to be sorted
* 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 an l-value and swap just the keys)
* 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 an l-value and swap just the keys)
* visible in all the macros supplied above), starts with comma
*
* After including this file, a function ASORT_PREFIX(sort)(uns array_size)
* 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.
+ * or ASORT_PREFIX(sort)(ASORT_KEY_TYPE *array, uns array_size) [if ASORT_ELT
+ * is not defined] is declared and all parameter macros are automatically
+ * undef'd.
#define ASORT_EXTRA_ARGS
#endif
#define ASORT_EXTRA_ARGS
#endif
-static void ASORT_PREFIX(sort)(uns array_size ASORT_EXTRA_ARGS)
+#ifndef ASORT_ELT
+#define ASORT_ARRAY_ARG
+#define ASORT_ELT(i) array[i]
+#endif
+
+static void ASORT_PREFIX(sort)(
+#ifdef ASORT_ARRAY_ARG
+ ASORT_KEY_TYPE *array,
+#endif
+ uns array_size ASORT_EXTRA_ARGS)
{
struct stk { int l, r; } stack[8*sizeof(uns)];
int l, r, left, right, m;
{
struct stk { int l, r; } stack[8*sizeof(uns)];
int l, r, left, right, m;
#undef ASORT_SWAP
#undef ASORT_THRESHOLD
#undef ASORT_EXTRA_ARGS
#undef ASORT_SWAP
#undef ASORT_THRESHOLD
#undef ASORT_EXTRA_ARGS
#define ASORT_PREFIX(x) s5m_##x
#define ASORT_KEY_TYPE u32
#define ASORT_PREFIX(x) s5m_##x
#define ASORT_KEY_TYPE u32
-#define ASORT_ELT(i) ary[i]
-#define ASORT_EXTRA_ARGS , u32 *ary
#include "ucw/sorter/array-simple.h"
static void s5_write_merged(struct fastbuf *f, struct key5 **keys, void **data, uns n, void *buf)
#include "ucw/sorter/array-simple.h"
static void s5_write_merged(struct fastbuf *f, struct key5 **keys, void **data, uns n, void *buf)
memcpy(&a[m], data[i], 4*keys[i]->cnt);
m += keys[i]->cnt;
}
memcpy(&a[m], data[i], 4*keys[i]->cnt);
m += keys[i]->cnt;
}
keys[0]->cnt = m;
bwrite(f, keys[0], sizeof(struct key5));
bwrite(f, a, 4*m);
keys[0]->cnt = m;
bwrite(f, keys[0], sizeof(struct key5));
bwrite(f, a, 4*m);