add struct and union at usages for C

This commit is contained in:
Richard Thier 2023-04-18 16:33:08 +02:00
parent 4e24903b18
commit fc3f4d5cfe

View File

@ -266,7 +266,7 @@ struct tselem {
/* Forward decl of internal code */
static inline void thiersort8_internal(
const tselem *arr,
struct tselem *arr,
uint32_t length,
void* (*malloc)(size_t size),
void (*free)(void *ptr),
@ -309,7 +309,7 @@ static inline const int ts_lt_float(
* Sort {key, index32} elements where key is 32 bit integer.
*/
static inline void thiersort8_intkey(
const tselem *arr,
struct tselem *arr,
uint32_t length,
void* (*malloc)(size_t size),
void (*free)(void *ptr)) {
@ -329,7 +329,7 @@ static inline void thiersort8_intkey(
* Sort {key, index32} elements where key is unsigned 32 bit integer.
*/
static inline void thiersort8_uintkey(
const tselem *arr,
struct tselem *arr,
uint32_t length,
void* (*malloc)(size_t size),
void (*free)(void *ptr)) {
@ -349,7 +349,7 @@ static inline void thiersort8_uintkey(
* Sort {key, index32} elements where key is 32 bit integer.
*/
static inline void thiersort8_floatkey(
const tselem *arr,
struct tselem *arr,
uint32_t length,
void* (*malloc)(size_t size),
void (*free)(void *ptr)) {
@ -443,14 +443,14 @@ static inline void ts_quicksort_inplace(
TSU32 len = (to - from);
TSU32 mid = from + len / 2;
tskey pivotkey = arr[mid].key;
const union tskey pivotkey = arr[mid].key;
TSU32 pivoti = arr[mid].i;
TSU32 left = from;
TSU32 right = to - 1;
while(left < right) {
// Step over rightly positioned elems from left
tskey leftkey = arr[left].key;
const union tskey leftkey = arr[left].key;
TSU32 lefti = arr[left].i;
while((left < right) && lt(leftkey, pivotkey, lefti, pivoti, reent_data)) {
++left;
@ -459,7 +459,7 @@ static inline void ts_quicksort_inplace(
}
// Step over rightly positioned elems from right
tskey rightkey = arr[right].key;
const union tskey rightkey = arr[right].key;
TSU32 righti = arr[right].i;
while((left < right) && lt(pivotkey, rightkey, pivoti, righti, reent_data)) {
--right;
@ -469,7 +469,7 @@ static inline void ts_quicksort_inplace(
// Swap wrongly positioned element
if(left < right) {
tselem tmp = arr[left];
const struct tselem tmp = arr[left];
arr[left] = arr[right];
arr[right] = tmp;
++left;
@ -479,7 +479,7 @@ static inline void ts_quicksort_inplace(
/* Fix left to be after the point of separation in odd lengths */
if(left == right) {
tskey leftkey = arr[left].key;
const union tskey leftkey = arr[left].key;
TSU32 lefti = arr[left].i;
left += (lt(pivotkey, leftkey, pivoti, lefti, reent_data));
}
@ -509,13 +509,13 @@ static inline void ts_quicksort_fromto(
TSU32 len = (to - from);
TSU32 mid = from + len / 2;
tskey pivotkey = src[mid].key;
const union tskey pivotkey = src[mid].key;
TSU32 pivoti = src[mid].i;
TSU32 li = from;
TSU32 ri = to - 1;
for(TSU32 i = from; i < to; ++i) {
tselem e = src[i];
const struct tselem e = src[i];
if(lt(e.key, pivotkey, e.i, pivoti, reent_data)) {
dst[li++] = e;
} else {
@ -549,7 +549,7 @@ static inline void thiersort8_internal(
uint32_t radics[256] = {0};
/* [from, to) index: only where prefix sums change - usually nonfull */
uint32_t real_radics[256 * 2] = {0};
tselem *arr2 = malloc((sizeof struct tselem) * length);
struct tselem *arr2 = malloc((sizeof struct tselem) * length);
/* Step 1) Bucketing */
#ifdef TS_SSE2