-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathstd-sorts.cpp
47 lines (38 loc) · 1.38 KB
/
std-sorts.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "common.hpp"
#include <algorithm>
#include <stdlib.h>
#include <inttypes.h>
/**
* The sorts offered by the C and C++ standard library.
*/
void qsort_copy(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *));
// int compare_uint64_t(const void *l_, const void *r_) {
// uint64_t l = *(const uint64_t *)l_;
// uint64_t r = *(const uint64_t *)r_;
// return (l > r) - (l < r);
// }
int compare_uint64_t(const void *l_, const void *r_) {
uint64_t l = *(const uint64_t *)l_;
uint64_t r = *(const uint64_t *)r_;
if (l < r) return -1;
if (l > r) return 1;
return 0;
}
void qsort_sort(uint64_t* input, size_t size) {
qsort(input, size, sizeof(uint64_t), compare_uint64_t);
}
/**
* The source for qsort, but recompiled locally with the current compiler flags, etc.
*/
void qsort_recompiled(uint64_t* input, size_t size) {
qsort_copy(input, size, sizeof(uint64_t), compare_uint64_t);
}
void std_sort(uint64_t* input, size_t size) {
return std::sort(input, input + size);
}
void std_stable_sort(uint64_t* input, size_t size) {
return std::stable_sort(input, input + size);
}
void std_partial_sort(uint64_t* input, size_t size) {
return std::partial_sort(input, input + size, input + size);
}