#include <stdlib.h>
#include <stdio.h>
#include <string.h>
Go to the source code of this file.
|
static int | compute_minrun (const uint64_t) |
|
static int | clzll (uint64_t) |
|
void | BINARY_INSERTION_SORT (SORT_TYPE *dst, const size_t size) |
|
void | TIM_SORT (SORT_TYPE *dst, const size_t size) |
|
static __inline size_t | BINARY_INSERTION_FIND (SORT_TYPE *dst, const SORT_TYPE x, const size_t size) |
|
static void | BINARY_INSERTION_SORT_START (SORT_TYPE *dst, const size_t start, const size_t size) |
|
static __inline void | REVERSE_ELEMENTS (SORT_TYPE *dst, size_t start, size_t end) |
|
static size_t | COUNT_RUN (SORT_TYPE *dst, const size_t start, const size_t size) |
|
static int | CHECK_INVARIANT (TIM_SORT_RUN_T *stack, const int stack_curr) |
|
static void | TIM_SORT_RESIZE (TEMP_STORAGE_T *store, const size_t new_size) |
|
static void | TIM_SORT_MERGE (SORT_TYPE *dst, const TIM_SORT_RUN_T *stack, const int stack_curr, TEMP_STORAGE_T *store) |
|
static int | TIM_SORT_COLLAPSE (SORT_TYPE *dst, TIM_SORT_RUN_T *stack, int stack_curr, TEMP_STORAGE_T *store, const size_t size) |
|
static __inline int | PUSH_NEXT (SORT_TYPE *dst, const size_t size, TEMP_STORAGE_T *store, const size_t minrun, TIM_SORT_RUN_T *run_stack, size_t *stack_curr, size_t *curr) |
|
◆ BINARY_INSERTION_FIND
◆ BINARY_INSERTION_SORT
◆ BINARY_INSERTION_SORT_START
◆ CHECK_INVARIANT
◆ CLZ
◆ COUNT_RUN
◆ MAX
◆ MIN
◆ REVERSE_ELEMENTS
◆ SORT_CMP
#define SORT_CMP |
( |
|
x, |
|
|
|
y |
|
) |
| ((x) < (y) ? -1 : ((x) == (y) ? 0 : 1)) |
◆ SORT_COMMON_H
◆ SORT_CONCAT
◆ SORT_MAKE_STR
◆ SORT_MAKE_STR1
◆ SORT_SWAP
◆ TIM_SORT
◆ TIM_SORT_COLLAPSE
◆ TIM_SORT_MERGE
◆ TIM_SORT_RESIZE
◆ TIM_SORT_STACK_SIZE
#define TIM_SORT_STACK_SIZE 128 |
◆ BINARY_INSERTION_FIND()
Definition at line 177 of file timsort.h.
178 {
184
185
187 return 0;
190 }
191
193
194 while (1) {
196
200 }
201
203 } else {
206 }
207
209 }
210
211 c =
l + ((
r -
l) >> 1);
213 }
214}
GLint GLint GLint GLint GLint x
GLdouble GLdouble GLdouble r
◆ BINARY_INSERTION_SORT()
Definition at line 247 of file timsort.h.
247 {
248
250 return;
251 }
252
254}
#define BINARY_INSERTION_SORT_START
◆ BINARY_INSERTION_SORT_START()
Definition at line 217 of file timsort.h.
217 {
219
224
225
227 continue;
228 }
229
230
233
236
238 break;
239 }
240 }
241
243 }
244}
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
#define location(file, line)
#define BINARY_INSERTION_FIND
◆ CHECK_INVARIANT()
Definition at line 322 of file timsort.h.
322 {
324
325 if (stack_curr < 2) {
326 return 1;
327 }
328
329 if (stack_curr == 2) {
330 const size_t A1 =
stack[stack_curr - 2].length;
331 const size_t B1 =
stack[stack_curr - 1].length;
332
334 return 0;
335 }
336
337 return 1;
338 }
339
340 A =
stack[stack_curr - 3].length;
341 B =
stack[stack_curr - 2].length;
342 C =
stack[stack_curr - 1].length;
343
344 if ((
A <=
B +
C) || (
B <=
C)) {
345 return 0;
346 }
347
348 return 1;
349}
◆ clzll()
Definition at line 84 of file timsort.h.
84 {
86
88 return 64;
89 }
90
92
93 if (
x <= 0x00000000FFFFFFFFL) {
96 }
97
98 if (
x <= 0x0000FFFFFFFFFFFFL) {
101 }
102
103 if (
x <= 0x00FFFFFFFFFFFFFFL) {
106 }
107
108 if (
x <= 0x0FFFFFFFFFFFFFFFL) {
111 }
112
113 if (
x <= 0x3FFFFFFFFFFFFFFFL) {
116 }
117
118 if (
x <= 0x7FFFFFFFFFFFFFFFL) {
120 }
121
123}
◆ compute_minrun()
Definition at line 129 of file timsort.h.
129 {
130 const int top_bit = 64 -
CLZ(
size);
131 const int shift =
MAX(top_bit, 6) - 6;
134
136 return minrun + 1;
137 }
138
139 return minrun;
140}
Referenced by TIM_SORT().
◆ COUNT_RUN()
Definition at line 270 of file timsort.h.
270 {
271 size_t curr;
272
274 return 1;
275 }
276
280 }
281
282 return 2;
283 }
284
286
288
289 while (1) {
290 if (curr ==
size - 1) {
291 break;
292 }
293
295 break;
296 }
297
298 curr++;
299 }
300
302 } else {
303
304 while (1) {
305 if (curr ==
size - 1) {
306 break;
307 }
308
310 break;
311 }
312
313 curr++;
314 }
315
316
319 }
320}
◆ PUSH_NEXT()
Definition at line 488 of file timsort.h.
494 {
496 size_t run = minrun;
497
498 if (run >
size - *curr) {
500 }
501
505 }
506
507 run_stack[*stack_curr].
start = *curr;
509 (*stack_curr)++;
511
513
514 while (*stack_curr > 1) {
516 run_stack[*stack_curr - 2].
length += run_stack[*stack_curr - 1].
length;
517 (*stack_curr)--;
518 }
519
523 }
524
525 return 0;
526 }
527
528 return 1;
529}
Referenced by TIM_SORT().
◆ REVERSE_ELEMENTS()
Definition at line 258 of file timsort.h.
258 {
259 while (1) {
261 return;
262 }
263
267 }
268}
◆ TIM_SORT()
Definition at line 531 of file timsort.h.
531 {
532 size_t minrun;
535 size_t stack_curr = 0;
536 size_t curr = 0;
537
538
540 return;
541 }
542
545 return;
546 }
547
548
550
551 store = &_store;
554
556 return;
557 }
558
560 return;
561 }
562
564 return;
565 }
566
567 while (1) {
570 continue;
571 }
572
574 return;
575 }
576 }
577}
#define TIM_SORT_COLLAPSE
#define TIM_SORT_STACK_SIZE
static int compute_minrun(const uint64_t)
#define BINARY_INSERTION_SORT
static __inline int PUSH_NEXT(SORT_TYPE *dst, const size_t size, TEMP_STORAGE_T *store, const size_t minrun, TIM_SORT_RUN_T *run_stack, size_t *stack_curr, size_t *curr)
◆ TIM_SORT_COLLAPSE()
Definition at line 424 of file timsort.h.
425 {
426 while (1) {
429
430
431 if (stack_curr <= 1) {
432 break;
433 }
434
435
439 stack_curr--;
440 break;
441 }
442
446 stack_curr--;
447 break;
448 } else if (stack_curr == 2) {
449 break;
450 }
451
452 B =
stack[stack_curr - 3].length;
453 C =
stack[stack_curr - 2].length;
454 D =
stack[stack_curr - 1].length;
455
456 if (stack_curr >= 4) {
457 A =
stack[stack_curr - 4].length;
459 } else {
461 }
462
465
466
468 break;
469 }
470
471
474 stack[stack_curr - 3].length +=
stack[stack_curr - 2].length;
475 stack[stack_curr - 2] =
stack[stack_curr - 1];
476 stack_curr--;
477 } else {
478
480 stack[stack_curr - 2].length +=
stack[stack_curr - 1].length;
481 stack_curr--;
482 }
483 }
484
485 return stack_curr;
486}
GLuint GLsizei GLsizei * length
◆ TIM_SORT_MERGE()
Definition at line 371 of file timsort.h.
372 {
373 const size_t A =
stack[stack_curr - 2].length;
374 const size_t B =
stack[stack_curr - 1].length;
375 const size_t curr =
stack[stack_curr - 2].start;
380
381
386
387 for (
k = curr;
k < curr +
A +
B;
k++) {
388 if ((
i <
A) && (
j < curr +
A +
B)) {
390 dst[
k] = storage[
i++];
391 } else {
393 }
395 dst[
k] = storage[
i++];
396 } else {
397 break;
398 }
399 }
400 } else {
401
406
409 if ((
i > 0) && (
j > curr)) {
412 } else {
413 dst[
k] = storage[--
i];
414 }
416 dst[
k] = storage[--
i];
417 } else {
418 break;
419 }
420 }
421 }
422}
#define memcpy(s1, s2, n)
◆ TIM_SORT_RESIZE()
Definition at line 356 of file timsort.h.
356 {
357 if (store->
alloc < new_size) {
359
360 if (tempstore ==
NULL) {
361 fprintf(
stderr,
"Error allocating temporary storage for tim sort: need %lu bytes",
362 (
unsigned long)(
sizeof(
SORT_TYPE) * new_size));
364 }
365
367 store->
alloc = new_size;
368 }
369}
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)