Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/coreutils/src/gnulib/lib/mpsort.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||
---|---|---|---|---|---|---|---|---|
1 | - | |||||||
2 | - | |||||||
3 | - | |||||||
4 | - | |||||||
5 | - | |||||||
6 | - | |||||||
7 | typedef int (*comparison_function) (void const *, void const *); | - | ||||||
8 | - | |||||||
9 | static void mpsort_with_tmp (void const **__restrict, size_t, | - | ||||||
10 | void const **__restrict, comparison_function); | - | ||||||
11 | - | |||||||
12 | - | |||||||
13 | - | |||||||
14 | - | |||||||
15 | static void | - | ||||||
16 | mpsort_into_tmp (void const **__restrict base, size_t n, | - | ||||||
17 | void const **__restrict tmp, | - | ||||||
18 | comparison_function cmp) | - | ||||||
19 | { | - | ||||||
20 | size_t n1 = n / 2; | - | ||||||
21 | size_t n2 = n - n1; | - | ||||||
22 | size_t a = 0; | - | ||||||
23 | size_t alim = n1; | - | ||||||
24 | size_t b = n1; | - | ||||||
25 | size_t blim = n; | - | ||||||
26 | void const *ba; | - | ||||||
27 | void const *bb; | - | ||||||
28 | - | |||||||
29 | mpsort_with_tmp (base + n1, n2, tmp, cmp); | - | ||||||
30 | mpsort_with_tmp (base, n1, tmp, cmp); | - | ||||||
31 | - | |||||||
32 | ba = base[a]; | - | ||||||
33 | bb = base[b]; | - | ||||||
34 | - | |||||||
35 | for (;;) | - | ||||||
36 | if (cmp (ba, bb) <= 0
| 11-29 | ||||||
37 | { | - | ||||||
38 | *tmp++ = ba; | - | ||||||
39 | a++; | - | ||||||
40 | if (a == alim
| 14-15 | ||||||
41 | { | - | ||||||
42 | a = b; | - | ||||||
43 | alim = blim; | - | ||||||
44 | break; executed 15 times by 3 tests: break; Executed by:
| 15 | ||||||
45 | } | - | ||||||
46 | ba = base[a]; | - | ||||||
47 | } executed 14 times by 3 tests: end of block Executed by:
| 14 | ||||||
48 | else | - | ||||||
49 | { | - | ||||||
50 | *tmp++ = bb; | - | ||||||
51 | b++; | - | ||||||
52 | if (b == blim
| 5-6 | ||||||
53 | break; executed 5 times by 3 tests: break; Executed by:
| 5 | ||||||
54 | bb = base[b]; | - | ||||||
55 | } executed 6 times by 3 tests: end of block Executed by:
| 6 | ||||||
56 | - | |||||||
57 | memcpy (tmp, base + a, (alim - a) * sizeof *base); | - | ||||||
58 | } executed 20 times by 3 tests: end of block Executed by:
| 20 | ||||||
59 | - | |||||||
60 | - | |||||||
61 | - | |||||||
62 | - | |||||||
63 | - | |||||||
64 | static void | - | ||||||
65 | mpsort_with_tmp (void const **__restrict base, size_t n, | - | ||||||
66 | void const **__restrict tmp, | - | ||||||
67 | comparison_function cmp) | - | ||||||
68 | { | - | ||||||
69 | if (n <= 2
| 36-1124 | ||||||
70 | { | - | ||||||
71 | if (n == 2
| 33-1091 | ||||||
72 | { | - | ||||||
73 | void const *p0 = base[0]; | - | ||||||
74 | void const *p1 = base[1]; | - | ||||||
75 | if (! (cmp (p0, p1) <= 0)
| 8-25 | ||||||
76 | { | - | ||||||
77 | base[0] = p1; | - | ||||||
78 | base[1] = p0; | - | ||||||
79 | } executed 8 times by 3 tests: end of block Executed by:
| 8 | ||||||
80 | } executed 33 times by 3 tests: end of block Executed by:
| 33 | ||||||
81 | } executed 1124 times by 3 tests: end of block Executed by:
| 1124 | ||||||
82 | else | - | ||||||
83 | { | - | ||||||
84 | size_t n1 = n / 2; | - | ||||||
85 | size_t n2 = n - n1; | - | ||||||
86 | size_t i; | - | ||||||
87 | size_t t = 0; | - | ||||||
88 | size_t tlim = n1; | - | ||||||
89 | size_t b = n1; | - | ||||||
90 | size_t blim = n; | - | ||||||
91 | void const *bb; | - | ||||||
92 | void const *tt; | - | ||||||
93 | - | |||||||
94 | mpsort_with_tmp (base + n1, n2, tmp, cmp); | - | ||||||
95 | - | |||||||
96 | if (n1 < 2
| 16-20 | ||||||
97 | tmp[0] = base[0]; executed 16 times by 3 tests: tmp[0] = base[0]; Executed by:
| 16 | ||||||
98 | else | - | ||||||
99 | mpsort_into_tmp (base, n1, tmp, cmp); executed 20 times by 3 tests: mpsort_into_tmp (base, n1, tmp, cmp); Executed by:
| 20 | ||||||
100 | - | |||||||
101 | tt = tmp[t]; | - | ||||||
102 | bb = base[b]; | - | ||||||
103 | - | |||||||
104 | for (i = 0; ; ) | - | ||||||
105 | if (cmp (tt, bb) <= 0
| 36-75 | ||||||
106 | { | - | ||||||
107 | base[i++] = tt; | - | ||||||
108 | t++; | - | ||||||
109 | if (t == tlim
| 27-48 | ||||||
110 | break; executed 27 times by 3 tests: break; Executed by:
| 27 | ||||||
111 | tt = tmp[t]; | - | ||||||
112 | } executed 48 times by 3 tests: end of block Executed by:
| 48 | ||||||
113 | else | - | ||||||
114 | { | - | ||||||
115 | base[i++] = bb; | - | ||||||
116 | b++; | - | ||||||
117 | if (b == blim
| 9-27 | ||||||
118 | { | - | ||||||
119 | memcpy (base + i, tmp + t, (tlim - t) * sizeof *base); | - | ||||||
120 | break; executed 9 times by 3 tests: break; Executed by:
| 9 | ||||||
121 | } | - | ||||||
122 | bb = base[b]; | - | ||||||
123 | } executed 27 times by 3 tests: end of block Executed by:
| 27 | ||||||
124 | } executed 36 times by 3 tests: end of block Executed by:
| 36 | ||||||
125 | } | - | ||||||
126 | - | |||||||
127 | - | |||||||
128 | - | |||||||
129 | - | |||||||
130 | - | |||||||
131 | void | - | ||||||
132 | mpsort (void const **base, size_t n, comparison_function cmp) | - | ||||||
133 | { | - | ||||||
134 | mpsort_with_tmp (base, n, base + n, cmp); | - | ||||||
135 | } executed 1084 times by 3 tests: end of block Executed by:
| 1084 | ||||||
Switch to Source code | Preprocessed file |