17 extern void kmr_isort(
void *a,
size_t n,
size_t es,
int depth);
18 extern int kmr_scan_argv_strings(
void *mr,
char *s,
size_t len,
int arglim,
19 int *argc,
char **argv,
20 _Bool wssep,
char *msg);
25 static struct timeval tv0 = {.tv_sec = 0};
28 cc = gettimeofday(&tv, 0);
30 if (tv0.tv_sec == 0) {
32 assert(tv0.tv_sec != 0);
34 double dt = ((double)(tv.tv_sec - tv0.tv_sec)
35 + ((double)(tv.tv_usec - tv0.tv_usec) * 1e-6));
40 printablestring(
char *s,
int len)
44 assert(len < (
int)
sizeof(b));
45 for (
int i = 0; i < len; i++) {
48 }
else if (isblank(s[i])) {
50 }
else if (isprint(s[i])) {
61 check_isort(
int argc,
char *argv[])
68 long a0[20] = {19, 18, 17, 16, 15, 14, 13, 12, 11, 10,
69 9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
70 size_t n0 = (
sizeof(a0) /
sizeof(
long));
71 for (
int i = 0; i < (int)n0; i++) {
72 a0[i] += 1000000000000;
77 for (
int i = 0; i < (int)n0; i++) {
78 printf(
"%ld\n", a0[i]);
82 for (
int i = 0; i < (int)n0; i++) {
83 assert(a0[i] == (i + 1000000000000));
86 for (
int i = 0; i < (int)n0; i++) {
87 printf(
"%ld ", a0[i]);
96 long *a1 = malloc(
sizeof(
long) * n1);
99 printf(
"Generating random numbers...\n");
100 for (
long i = 0; i < n1; i++) {
101 a1[i] = ((((long)rand()) << 31) ^ ((long)rand()));
105 printf(
"Problem...\n");
106 for (
long i = 0; i < 10; i++) {
107 printf(
"%ld\n", a1[i]);
112 printf(
"Sorting...\n");
117 printf(
"Result...\n");
118 for (
long i = 0; i < 10; i++) {
119 printf(
"%ld\n", a1[i]);
124 printf(
"Checking...\n");
126 for (
long i = 0; i < n1; i++) {
141 long *a5 = malloc(
sizeof(
long) * (
size_t)n5);
144 printf(
"CHECK kmr_isort...\n");
146 for (
int loop = 0; loop <= 40; loop++) {
153 threads = omp_get_num_threads();
157 printf(
"Generating random numbers...\n");
158 for (
long i = 0; i < n5; i++) {
159 a5[i] = ((((long)rand()) << 31) ^ ((long)rand()));
162 printf(
"Sorting (threads=%d)...\n", threads);
164 kmr_isort(a5, (
size_t)n5,
sizeof(
long), 5);
166 printf(
"dt=%f\n", (t1 - t0));
168 printf(
"Checking...\n");
170 for (
long i = 0; i < n5; i++) {
171 assert(a5[i] >= lb5);
187 check_string_scan(
int argc,
char *argv[])
193 printf(
"CHECK kmr_scan_argv_strings...\n");
198 printf(
"s=(%s)\n", s0);
199 kmr_scan_argv_strings(0, s0,
sizeof(s0), 128, &argsc, argsv, 1,
"s0");
202 char s1[] =
"abc bad cab";
203 printf(
"s=(%s)\n", s1);
204 kmr_scan_argv_strings(0, s1,
sizeof(s1), 128, &argsc, argsv, 1,
"s1");
206 assert(strcmp(argsv[0],
"abc") == 0
207 && strcmp(argsv[1],
"bad") == 0
208 && strcmp(argsv[2],
"cab") == 0);
210 char s2[] =
" abc bad cab ";
211 printf(
"s=(%s)\n", s2);
212 kmr_scan_argv_strings(0, s2,
sizeof(s2), 128, &argsc, argsv, 1,
"s2");
214 assert(strcmp(argsv[0],
"abc") == 0
215 && strcmp(argsv[1],
"bad") == 0
216 && strcmp(argsv[2],
"cab") == 0);
219 printf(
"s=(%s)\n", s3);
220 kmr_scan_argv_strings(0, s3,
sizeof(s3), 128, &argsc, argsv, 1,
"s3");
222 assert(strcmp(argsv[0],
"abc") == 0);
225 printf(
"s=(%s)\n", s4);
226 kmr_scan_argv_strings(0, s4,
sizeof(s4), 128, &argsc, argsv, 1,
"s4");
228 assert(strcmp(argsv[0],
"abc") == 0);
233 printf(
"s=(%s)\n", s5);
234 kmr_scan_argv_strings(0, s5,
sizeof(s5), 128, &argsc, argsv, 0,
"s5");
237 char s6[] =
"abc\0bad\0cab";
238 printf(
"s=(%s)\n", printablestring(s6,
sizeof(s6)));
239 kmr_scan_argv_strings(0, s6,
sizeof(s6), 128, &argsc, argsv, 0,
"s6");
241 assert(strcmp(argsv[0],
"abc") == 0
242 && strcmp(argsv[1],
"bad") == 0
243 && strcmp(argsv[2],
"cab") == 0);
245 char s7[] =
" abc bad \0\0 cab ";
246 printf(
"s=(%s)\n", printablestring(s7,
sizeof(s7)));
247 kmr_scan_argv_strings(0, s7,
sizeof(s7), 128, &argsc, argsv, 0,
"s7");
249 assert(strcmp(argsv[0],
" abc bad ") == 0
250 && strcmp(argsv[1],
"") == 0
251 && strcmp(argsv[2],
" cab ") == 0);
254 printf(
"s=(%s)\n", s8);
255 kmr_scan_argv_strings(0, s8,
sizeof(s8), 128, &argsc, argsv, 0,
"s8");
257 assert(strcmp(argsv[0],
"abc") == 0);
260 printf(
"s=(%s)\n", s9);
261 kmr_scan_argv_strings(0, s9,
sizeof(s9), 128, &argsc, argsv, 0,
"s9");
263 assert(strcmp(argsv[0],
" abc ") == 0);
272 main(
int argc,
char **argv)
274 check_isort(argc, argv);
275 check_string_scan(argc, argv);
void kmr_isort(void *a, size_t n, size_t es, int depth)
Sorts by comparator on long integers.