uint32 ->TSU32; prepare, apply skeleton
This commit is contained in:
parent
3a2f2d326b
commit
8784773800
72
thiersort.h
72
thiersort.h
@ -267,7 +267,7 @@ struct tselem {
|
||||
/* Forward decl of internal code */
|
||||
static inline void thiersort8_internal(
|
||||
struct tselem *arr,
|
||||
uint32_t length,
|
||||
TSU32 length,
|
||||
void* (*malloc)(size_t size),
|
||||
void (*free)(void *ptr),
|
||||
const TSBOOL (*lt)(
|
||||
@ -310,7 +310,7 @@ static inline const int ts_lt_float(
|
||||
*/
|
||||
static inline void thiersort8_intkey(
|
||||
struct tselem *arr,
|
||||
uint32_t length,
|
||||
TSU32 length,
|
||||
void* (*malloc)(size_t size),
|
||||
void (*free)(void *ptr)) {
|
||||
thiersort8_internal(
|
||||
@ -330,7 +330,7 @@ static inline void thiersort8_intkey(
|
||||
*/
|
||||
static inline void thiersort8_uintkey(
|
||||
struct tselem *arr,
|
||||
uint32_t length,
|
||||
TSU32 length,
|
||||
void* (*malloc)(size_t size),
|
||||
void (*free)(void *ptr)) {
|
||||
thiersort8_internal(
|
||||
@ -350,7 +350,7 @@ static inline void thiersort8_uintkey(
|
||||
*/
|
||||
static inline void thiersort8_floatkey(
|
||||
struct tselem *arr,
|
||||
uint32_t length,
|
||||
TSU32 length,
|
||||
void* (*malloc)(size_t size),
|
||||
void (*free)(void *ptr)) {
|
||||
thiersort8_internal(
|
||||
@ -364,6 +364,64 @@ static inline void thiersort8_floatkey(
|
||||
TSTRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create [key, index] pairs from your raw input data sequence. O(n) runtime.
|
||||
*
|
||||
* Useful if you have an seq/arr of elements to sort and what them prepared to be
|
||||
* properly thiersorted as key, index pairs. Then you can apply that reordering
|
||||
* later using thiersort_apply(..). Also useful for online data stream sources.
|
||||
*
|
||||
* BEWARE: The returned array must be freed by you - with a corresponding free.
|
||||
* An alternative is to do a thiersort_apply(..) call (for the array case).
|
||||
*
|
||||
* @param askey The sequence that generates input. Gives the ith elem as key.
|
||||
* @param length The length of input sequence.
|
||||
* @param malloc The function to use for allocating the key-index array.
|
||||
* @returns The array of keys and indices for that key to sort.
|
||||
*/
|
||||
static inline struct tselem *thiersort_prepare(
|
||||
union tskey (askey)(TSU32 i),
|
||||
TSU32 length,
|
||||
void* (*malloc)(size_t size)) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
/**
|
||||
* Create [key, index] pairs from your raw input data array. O(n) runtime.
|
||||
*
|
||||
* Useful if you have an array of elements to sort and what them prepared to be
|
||||
* properly thiersorted as key, index pairs. Then you can apply that reordering
|
||||
* later using thiersort_apply(..).
|
||||
*
|
||||
* BEWARE: The returned array must be freed by you - with a corresponding free.
|
||||
* An alternative is to do a thiersort_apply(..) call (for the array case).
|
||||
*
|
||||
* @param askey The sequence that generates input. Gives the ith elem as key.
|
||||
* @param length The length of input sequence.
|
||||
* @param malloc The function to use for allocating the key-index array.
|
||||
* @returns The array of keys and indices for that key to sort.
|
||||
*/
|
||||
static inline struct tselem *thiersort_prepare_array(
|
||||
void *arr,
|
||||
union tskey (askey)(void *elem),
|
||||
TSU32 length,
|
||||
TSU32 elemlen,
|
||||
void* (*malloc)(size_t size)) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the given [key,index] sort result back to an array.
|
||||
*/
|
||||
static inline void thiersort_apply(
|
||||
struct tselem *sortres,
|
||||
void *arr,
|
||||
TSU32 length,
|
||||
TSU32 elemlen,
|
||||
void (*free)(void *ptr)) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
/**
|
||||
* Do sign-trick based radix transform on nom-2s-complement 8 bit float!
|
||||
*
|
||||
@ -533,7 +591,7 @@ static inline void ts_quicksort_fromto(
|
||||
/** Internal code reuse (type-branches should be optimized out) */
|
||||
static inline void thiersort8_internal(
|
||||
struct tselem *arr,
|
||||
const uint32_t length,
|
||||
const TSU32 length,
|
||||
void* (*malloc)(size_t size),
|
||||
void (*free)(void *ptr),
|
||||
const TSBOOL (*lt)(
|
||||
@ -548,9 +606,9 @@ static inline void thiersort8_internal(
|
||||
void *reent_data) {
|
||||
|
||||
/* Preparation */
|
||||
uint32_t radics[256] = {0};
|
||||
TSU32 radics[256] = {0};
|
||||
/* [from, to) index: only where prefix sums change - usually nonfull */
|
||||
uint32_t real_radics[256 * 2] = {0};
|
||||
TSU32 real_radics[256 * 2] = {0};
|
||||
struct tselem *arr2 = malloc((sizeof struct tselem) * length);
|
||||
|
||||
/* Step 1) Bucketing */
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user