少年修仙传客户端基础资源
hch
2024-04-01 d01413b00ef631ac20347716b23818b0b811f65f
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/**
 * \file
 * Fast inline sorting
 *
 * Copyright (C) 2014 Xamarin Inc
 *
 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
 */
#ifndef __MONO_SGENQSORT_H__
#define __MONO_SGENQSORT_H__
 
/* Copied from non-inline implementation in sgen-qsort.c */
#define DEF_QSORT_INLINE(name, type, compare) \
static inline void \
qsort_swap_##name (type array[], const ssize_t i, const ssize_t j, type *const swap_tmp) \
{ \
    *swap_tmp = array [i]; \
    array [i] = array [j]; \
    array [j] = *swap_tmp; \
} \
\
static void \
qsort_rec_##name ( \
    type array[], \
    ssize_t begin, \
    ssize_t end, \
    type *const pivot_tmp, \
    type *const swap_tmp) \
{ \
    ssize_t left, right, middle, pivot; \
    while (begin < end) { \
        left = begin; \
        right = end; \
        middle = begin + (end - begin) / 2; \
        if (compare (array [middle], array [left]) < 0) \
            qsort_swap_##name (array, middle, left, swap_tmp); \
        if (compare (array [right], array [left]) < 0) \
            qsort_swap_##name (array, right, left, swap_tmp); \
        if (compare (array [right], array [middle]) < 0) \
            qsort_swap_##name (array, right, middle, swap_tmp); \
        pivot = middle; \
        *pivot_tmp = array [pivot]; \
        for (;;) { \
            while (left <= right && compare (array [left], *pivot_tmp) <= 0) \
                ++left; \
            while (left <= right && compare (array [right], *pivot_tmp) > 0) \
                --right; \
            if (left > right) \
                break; \
            qsort_swap_##name (array, left, right, swap_tmp); \
            if (pivot == right) \
                pivot = left; \
            ++left; \
            --right; \
        } \
        array [pivot] = array [right]; \
        array [right] = *pivot_tmp; \
        --right; \
        if (right - begin < end - left) { \
            qsort_rec_##name (array, begin, right, pivot_tmp, swap_tmp); \
            begin = left; \
        } else { \
            qsort_rec_##name (array, left, end, pivot_tmp, swap_tmp); \
            end = right; \
        } \
    } \
}    \
\
static inline void \
qsort_##name (type array[], size_t count) \
{ \
    type pivot_tmp; \
    type swap_tmp; \
    qsort_rec_##name (array, 0, (ssize_t)count - 1, &pivot_tmp, &swap_tmp); \
}
 
#endif