sdlQsort function stdinc

void sdlQsort(
  1. Pointer<NativeType> base,
  2. int nmemb,
  3. int size,
  4. Pointer<NativeFunction<SdlCompareCallback>> compare,
)

Sort an array.

For example:

typedef struct {
int key;
const char *string;
} data;

int SDLCALL compare(const void *a, const void *b)
{
const data *A = (const data *)a;
const data *B = (const data *)b;

if (A->n < B->n) {
return -1;
} else if (B->n < A->n) {
return 1;
} else {
return 0;
}
}

data values[] = {
{ 3, "third" }, { 1, "first" }, { 2, "second" }
};

SDL_qsort(values, SDL_arraysize(values), sizeof(values[0]), compare);

\param base a pointer to the start of the array. \param nmemb the number of elements in the array. \param size the size of the elements in the array. \param compare a function used to compare elements in the array.

\threadsafety It is safe to call this function from any thread.

\since This function is available since SDL 3.2.0.

\sa SDL_bsearch \sa SDL_qsort_r

extern SDL_DECLSPEC void SDLCALL SDL_qsort(void *base, size_t nmemb, size_t size, SDL_CompareCallback compare)

Implementation

void sdlQsort(
  Pointer<NativeType> base,
  int nmemb,
  int size,
  Pointer<NativeFunction<SdlCompareCallback>> compare,
) {
  final sdlQsortLookupFunction = _libSdl
      .lookupFunction<
        Void Function(
          Pointer<NativeType> base,
          Uint32 nmemb,
          Uint32 size,
          Pointer<NativeFunction<SdlCompareCallback>> compare,
        ),
        void Function(
          Pointer<NativeType> base,
          int nmemb,
          int size,
          Pointer<NativeFunction<SdlCompareCallback>> compare,
        )
      >('SDL_qsort');
  return sdlQsortLookupFunction(base, nmemb, size, compare);
}