Add functions to generate permutation tables

Adds functions to generate permutation tables off of a bunch of either
fixed length or zero-terminated blocks, using a simple quick-sort.
The resulting table contains unsigned offsets relative to the original
index. This means reordering the elements via the permutation table
looks like this:

    uint16_t *perm = make_permutation_table(unsorted, len, elem_size);
    for (i = 0; i < len; i++)
        sorted[i] = unsorted[(perm[i] + i) % len];
    free(perm);