`<` operator.
- `ASORT_SWAP(i,j)` -- Swap elements with indices `i` and `j`. If not
provided, it assumes `ASORT_ELT` is l-value and it just swaps keys.
-- `ASORT_TRESHOLD` -- Sequences of at most this amount of elements are
+- `ASORT_THRESHOLD` -- Sequences of at least this amount of elements are
sorted by quick-sort, smaller are sorted by insert-sort. Defaults to
`8` (result of experimentation).
- `ASORT_EXTRA_ARGS` -- Pass some extra arguments to the function.
Let's sort an array of integers, in the usual way.
#define ASORT_PREFIX(X) intarr_##X
- #define ASORT_TYPE int
+ #define ASORT_KEY_TYPE int
#include <ucw/sorter/array-simple.h>
-This generates an intarr_sort(int *array, uns array_size) function that
+This generates an intarr_sort(int *array, uint array_size) function that
can be used the obvious way.
A more complicated example could be sorting a structure, where items
#include <string.h> // Because of strcmp
#define ASORT_PREFIX(X) complicated_##X
- #define ASORT_TYPE struct elem
+ #define ASORT_KEY_TYPE struct elem
#define ASORT_ELT(i) ((i % 2 ? even_array : odd_array)[i / 2])
#define ASORT_LT(x, y) (strcmp((x).string, (y).string) < 0)
#define ASORT_EXTRA_ARGS , struct elem *odd_array, struct elem *even_array
- #include <ucw/sorter/sorter/array-simple.h>
+ #include <ucw/sorter/array-simple.h>
-Now we got a complicated_sort(uns array_size, struct elem *odd_array,
+Now we got a complicated_sort(uint array_size, struct elem *odd_array,
struct *even_array) function to perform our sorting.
[[array]]
- `ASORT_LT(x,y)` -- Comparing macro. Uses the `<` operator if not
provided.
- `ASORT_HASH(x)` -- A monotone hash function (or macro). Should
- return `uns`.
+ return `uint`.
- `ASORT_LONG_HASH(x)` -- Like `ASORT_HASH(x)`, but returns 64-bit
number instead of 32-bit.
-- `ASORT_TRESHOLD` -- How small should a chunk of data be to be sorted
+- `ASORT_THRESHOLD` -- How small should a chunk of data be to be sorted
by insert-sort? Defaults to `8` elements.
- `ASORT_RADIX_BITS` -- How many bits of the hash function should be
used at once for radix-sort? The default is guessed from your
When you want to use it, define `SORT_HASH_BITS` and set it to the
number of significant bits the hashing function provides. Then provide
-a callback function `uns SORT_PREFIX(hash)(SORT_KEY *key)`.
+a callback function `uint SORT_PREFIX(hash)(SORT_KEY *key)`.
[[merge-external]]
Merging items with identical keys
and provide these functions:
- `void SORT_PREFIX(write_merged)(struct fastbuf \*dest, SORT_KEY
- \*\*keys, void \*\*data, uns n, void *buf)`
+ \*\*keys, void \*\*data, uint n, void *buf)`
-- This function takes @n records in memory and writes a single
record into the @dest <<fastbuf:,fastbuf>>. The @keys and @data are
just the records. The @buf parameter points to a workspace memory.
macro over all the keys. The function is allowed to modify all its
parameters.
- `void SORT_PREFIX(copy_merged)(SORT_KEY \*\*keys, struct fastbuf
-\*\*data, uns n, struct fastbuf \*dest)`
+\*\*data, uint n, struct fastbuf \*dest)`
-- This one is similar to the above one, but the data are still in
the <<fastbuf:,fastbufs>> @data and no workspace is provided. This
is only used when `SORT_DATA_SIZE` or `SORT_UNIFY_WORKSPACE` is