提交 8c35b856 编写于 作者: X xinsheng Ren 提交者: facetosea

fix/TS-2297/windows sort use stdlib (#19152)

Co-authored-by: Nfacetosea <25808407@qq.com>
上级 6e9b5d1b
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#define ALLOW_FORBID_FUNC #define ALLOW_FORBID_FUNC
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "os.h" #include "os.h"
#include <stdlib.h>
#ifdef WINDOWS #ifdef WINDOWS
void swapStr(char* j, char* J, int width) { void swapStr(char* j, char* J, int width) {
...@@ -33,16 +34,5 @@ void swapStr(char* j, char* J, int width) { ...@@ -33,16 +34,5 @@ void swapStr(char* j, char* J, int width) {
// todo refactor: 1) move away; 2) use merge sort instead; 3) qsort is not a stable sort actually. // todo refactor: 1) move away; 2) use merge sort instead; 3) qsort is not a stable sort actually.
void taosSort(void* arr, int64_t sz, int64_t width, __compar_fn_t compar) { void taosSort(void* arr, int64_t sz, int64_t width, __compar_fn_t compar) {
#ifdef WINDOWS
int64_t i, j;
for (i = 0; i < sz - 1; i++) {
for (j = 0; j < sz - 1 - i; j++) {
if (compar((char*)arr + j * width, (char*)arr + (j + 1) * width) > 0.00) {
swapStr((char*)arr + j * width, (char*)arr + (j + 1) * width, width);
}
}
}
#else
qsort(arr, sz, width, compar); qsort(arr, sz, width, compar);
#endif
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册