]> mj.ucw.cz Git - libucw.git/blobdiff - ucw/sorter/array.h
Main: Removing an already removed event is always safe.
[libucw.git] / ucw / sorter / array.h
index 740b9b6e6814c13b5c2e2c0709db6a9fe241b982..e6e0199d0f9bdff4984b2d996adee5beb410dc9e 100644 (file)
@@ -9,7 +9,7 @@
 
 /*
  *  This is a generator of routines for sorting huge arrays, similar to the one
 
 /*
  *  This is a generator of routines for sorting huge arrays, similar to the one
- *  in ucw/arraysort.h. It cannot handle discontiguous arrays, but it is able
+ *  in ucw/sorter/array-simple.h. It cannot handle discontiguous arrays, but it is able
  *  to employ radix-sorting if a monotone hash function is available and also
  *  use several threads in parallel on SMP systems (this assumes that all
  *  callbacks you provide are thread-safe).
  *  to employ radix-sorting if a monotone hash function is available and also
  *  use several threads in parallel on SMP systems (this assumes that all
  *  callbacks you provide are thread-safe).
@@ -284,11 +284,25 @@ static void Q(radix_split)(void *src_ptr, void *dest_ptr, uns num_elts, uns *ptr
 
 #endif
 
 
 #endif
 
-static Q(key) *Q(sort)(Q(key) *array, uns num_elts
 #ifdef ASORT_HASH
 #ifdef ASORT_HASH
-  , Q(key) *buffer, uns hash_bits
+#define ASORT_HASH_ARGS , Q(key) *buffer, uns hash_bits
+#else
+#define ASORT_HASH_ARGS
 #endif
 #endif
-  )
+
+/**
+ * The generated function. The @array is the data to be sorted, @num_elts tells
+ * how many elements the array has.  If you did not provide `ASORT_HASH`, then
+ * the `ASORT_HASH_ARGS` is empty (there are only the two parameters in that
+ * case).  When you provide it, the function gains two more parameters in the
+ * `ASORT_HASH_ARGS` macro. They are `ASORT_KEY_TYPE *@buffer`, which must be a
+ * memory buffer of the same size as the input array, and `uns @hash_bits`,
+ * specifying how many significant bits the hash function returns.
+ *
+ * The function returns pointer to the sorted data, either the @array or the
+ * @buffer argument.
+ **/
+static ASORT_KEY_TYPE *ASORT_PREFIX(sort)(ASORT_KEY_TYPE *array, uns num_elts ASORT_HASH_ARGS)
 {
   struct asort_context ctx = {
     .array = array,
 {
   struct asort_context ctx = {
     .array = array,
@@ -318,4 +332,5 @@ static Q(key) *Q(sort)(Q(key) *array, uns num_elts
 #undef ASORT_RADIX_MASK
 #undef ASORT_SWAP
 #undef ASORT_THRESHOLD
 #undef ASORT_RADIX_MASK
 #undef ASORT_SWAP
 #undef ASORT_THRESHOLD
+#undef ASORT_HASH_ARGS
 #undef Q
 #undef Q