]> mj.ucw.cz Git - libucw.git/blobdiff - ucw/sorter/array-simple.h
ff-varints: Fixed really silly bug in handling fastbufs.
[libucw.git] / ucw / sorter / array-simple.h
index d5a9c787d3279643f7df1c5edfb3a52f95fee29a..5e442439f78e8df98ef40eb7cb2fbfbfa4bbaf3a 100644 (file)
@@ -1,7 +1,7 @@
 /*
 /*
- *     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.
@@ -25,7 +25,8 @@
  *  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)
@@ -34,7 +35,9 @@
  *                     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.
  */
 
 #ifndef ASORT_LT
  */
 
 #ifndef ASORT_LT
 #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 ASORT_KEY_TYPE *array,
+#define ASORT_ELT(i) array[i]
+#else
+#define ASORT_ARRAY_ARG
+#endif
+
+/**
+ * The generated sorting function. If `ASORT_ELT` macro is not provided, the
+ * @ASORT_ARRAY_ARG is equal to `ASORT_KEY_TYPE *array` and is the array to be
+ * sorted. If the macro is provided, this parameter is omitted. In that case,
+ * you can sort global variables or pass your structure by @ASORT_EXTRA_ARGS.
+ **/
+static void ASORT_PREFIX(sort)(ASORT_ARRAY_ARG 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;
@@ -172,3 +188,4 @@ static void ASORT_PREFIX(sort)(uns array_size ASORT_EXTRA_ARGS)
 #undef ASORT_SWAP
 #undef ASORT_THRESHOLD
 #undef ASORT_EXTRA_ARGS
 #undef ASORT_SWAP
 #undef ASORT_THRESHOLD
 #undef ASORT_EXTRA_ARGS
+#undef ASORT_ARRAY_ARG