From fc3f4d5cfe670cbbf5f8fe4501f3cf75fd4c7653 Mon Sep 17 00:00:00 2001 From: Richard Thier Date: Tue, 18 Apr 2023 16:33:08 +0200 Subject: [PATCH] add struct and union at usages for C --- thiersort.h | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/thiersort.h b/thiersort.h index c010340..f2d3cac 100644 --- a/thiersort.h +++ b/thiersort.h @@ -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