Luna/libluna/include/luna/Sort.h

27 lines
752 B
C
Raw Normal View History

2023-05-02 18:42:48 +00:00
#pragma once
#include <luna/Types.h>
typedef int (*compar_t)(const void*, const void*);
void c_quicksort(void* base, usize nmemb, usize size, compar_t compar);
template <typename T> void sort(T* base, usize nmemb, int (*compar)(const T*, const T*))
{
return c_quicksort(base, nmemb, sizeof(T), (compar_t)compar);
}
template <typename T> void sort(T* base, usize nmemb, compar_t compar)
{
return c_quicksort(base, nmemb, sizeof(T), compar);
}
template <typename T> void sort(T* begin, T* end, int (*compar)(const T*, const T*))
{
return c_quicksort(begin, end - begin, sizeof(T), (compar_t)compar);
}
template <typename T> void sort(T* begin, T* end, compar_t compar)
{
return c_quicksort(begin, end - begin, sizeof(T), compar);
}