24
23
#include "sort_QuickSort_Impl.h"
24
#include "sidl_NotImplementedException.h"
25
#include "sidl_Exception.h"
26
#ifndef included_sidl_MemAllocException_h
27
#include "sidl_MemAllocException.h"
26
#line 26 "../../../../babel/regression/sort/libC/sort_QuickSort_Impl.c"
30
#line 31 "/home/epperly/current/release_1.2.0/linux_dist/../babel_branch/regression/sort/libC/sort_QuickSort_Impl.c"
27
31
/* DO-NOT-DELETE splicer.begin(sort.QuickSort._includes) */
28
32
#include "sort_Container.h"
29
33
#include "sort_Counter.h"
30
34
#include "sort_Comparator.h"
31
35
#include "sidl_String.h"
37
#include "sidl_Exception.h"
35
40
* Choose the middle of the first, middle and last element of the
40
45
sort_Comparator comp,
49
sidl_BaseInterface *_ex)
45
51
int32_t pivot = (start + end) >> 1;
46
52
if ((end - start) > 4) {
47
53
int32_t mid = pivot;
48
sort_Counter_inc(cmp);
49
if (sort_Container_compare(elems, start, mid, comp) <= 0) {
50
sort_Counter_inc(cmp);
51
if (sort_Container_compare(elems, mid, end - 1, comp) > 0) {
52
sort_Counter_inc(cmp);
53
if (sort_Container_compare(elems, start, end - 1, comp) < 0) {
54
sort_Counter_inc(cmp, _ex); SIDL_REPORT(*_ex);
55
if (sort_Container_compare(elems, start, mid, comp, _ex) <= 0) {
57
sort_Counter_inc(cmp, _ex); SIDL_REPORT(*_ex);
58
if (sort_Container_compare(elems, mid, end - 1, comp, _ex) > 0) {
60
sort_Counter_inc(cmp, _ex); SIDL_REPORT(*_ex);
61
if (sort_Container_compare(elems, start, end - 1, comp, _ex) < 0) {
62
sort_Counter_inc(cmp);
63
if (sort_Container_compare(elems, mid, end - 1, comp) < 0) {
64
sort_Counter_inc(cmp);
65
if (sort_Container_compare(elems, start, end - 1, comp) > 0) {
73
sort_Counter_inc(cmp, _ex); SIDL_REPORT(*_ex);
74
if (sort_Container_compare(elems, mid, end - 1, comp, _ex) < 0) {
76
sort_Counter_inc(cmp, _ex); SIDL_REPORT(*_ex);
77
if (sort_Container_compare(elems, start, end - 1, comp, _ex) > 0) {
99
sidl_BaseInterface *_ex)
85
101
if ((end - start) > 1) {
86
int32_t pivot = choosePivot(elems, comp, cmp, start, end);
102
int32_t pivot = choosePivot(elems, comp, cmp, start, end, _ex); SIDL_REPORT(*_ex);
87
103
int32_t i = start;
89
105
if (pivot != start) {
90
sort_Counter_inc(swp);
91
sort_Container_swap(elems, start, pivot);
106
sort_Counter_inc(swp, _ex); SIDL_REPORT(*_ex);
108
sort_Container_swap(elems, start, pivot, _ex); SIDL_REPORT(*_ex);
96
sort_Counter_inc(cmp);
97
} while (sort_Container_compare(elems, start, j, comp) < 0);
114
sort_Counter_inc(cmp, _ex); SIDL_REPORT(*_ex);
115
} while (sort_Container_compare(elems, start, j, comp, _ex) < 0);
99
sort_Counter_inc(cmp);
100
if (sort_Container_compare(elems, start, i, comp) < 0) break;
118
const int icmp = sort_Container_compare(elems, start, i, comp, _ex);
120
sort_Counter_inc(cmp, _ex); SIDL_REPORT(*_ex);
102
123
if (i >= j) break;
103
sort_Counter_inc(swp);
104
sort_Container_swap(elems, i, j);
124
sort_Counter_inc(swp, _ex); SIDL_REPORT(*_ex);
125
sort_Container_swap(elems, i, j, _ex); SIDL_REPORT(*_ex);
106
127
if (j != start) {
107
sort_Counter_inc(swp);
108
sort_Container_swap(elems, start, j);
128
sort_Counter_inc(swp, _ex); SIDL_REPORT(*_ex);
129
sort_Container_swap(elems, start, j, _ex); SIDL_REPORT(*_ex);
110
quickSort(elems, comp, cmp, swp, start, j);
111
quickSort(elems, comp, cmp, swp, j + 1, end);
131
quickSort(elems, comp, cmp, swp, start, j, _ex); SIDL_REPORT(*_ex);
132
quickSort(elems, comp, cmp, swp, j + 1, end, _ex); SIDL_REPORT(*_ex);
114
136
/* DO-NOT-DELETE splicer.end(sort.QuickSort._includes) */
115
#line 115 "sort_QuickSort_Impl.c"
137
#line 137 "../regression/sort/libC/sort_QuickSort_Impl.c"
139
#define SIDL_IOR_MAJOR_VERSION 2
140
#define SIDL_IOR_MINOR_VERSION 0
118
142
* Static class initializer called exactly once before any user-defined method is dispatched
122
146
#define __FUNC__ "impl_sort_QuickSort__load"
125
152
impl_sort_QuickSort__load(
153
/* out */ sidl_BaseInterface *_ex)
128
#line 126 "../../../../babel/regression/sort/libC/sort_QuickSort_Impl.c"
129
/* DO-NOT-DELETE splicer.begin(sort.QuickSort._load) */
157
#line 158 "/home/epperly/current/release_1.2.0/linux_dist/../babel_branch/regression/sort/libC/sort_QuickSort_Impl.c"
158
/* DO-NOT-DELETE splicer.begin(sort.QuickSort._load) */
130
159
/* Insert the implementation of the static class initializer method here... */
131
/* DO-NOT-DELETE splicer.end(sort.QuickSort._load) */
132
#line 132 "sort_QuickSort_Impl.c"
160
/* DO-NOT-DELETE splicer.end(sort.QuickSort._load) */
161
#line 161 "../regression/sort/libC/sort_QuickSort_Impl.c"
135
165
* Class constructor called when the class is created.
139
169
#define __FUNC__ "impl_sort_QuickSort__ctor"
142
175
impl_sort_QuickSort__ctor(
143
/* in */ sort_QuickSort self)
176
/* in */ sort_QuickSort self,
177
/* out */ sidl_BaseInterface *_ex)
145
#line 141 "../../../../babel/regression/sort/libC/sort_QuickSort_Impl.c"
146
/* DO-NOT-DELETE splicer.begin(sort.QuickSort._ctor) */
181
#line 182 "/home/epperly/current/release_1.2.0/linux_dist/../babel_branch/regression/sort/libC/sort_QuickSort_Impl.c"
182
/* DO-NOT-DELETE splicer.begin(sort.QuickSort._ctor) */
147
183
/* Insert the implementation of the constructor method here... */
148
/* DO-NOT-DELETE splicer.end(sort.QuickSort._ctor) */
149
#line 149 "sort_QuickSort_Impl.c"
184
/* DO-NOT-DELETE splicer.end(sort.QuickSort._ctor) */
185
#line 185 "../regression/sort/libC/sort_QuickSort_Impl.c"
190
* Special Class constructor called when the user wants to wrap his own private data.
194
#define __FUNC__ "impl_sort_QuickSort__ctor2"
200
impl_sort_QuickSort__ctor2(
201
/* in */ sort_QuickSort self,
202
/* in */ void* private_data,
203
/* out */ sidl_BaseInterface *_ex)
207
#line 208 "/home/epperly/current/release_1.2.0/linux_dist/../babel_branch/regression/sort/libC/sort_QuickSort_Impl.c"
208
/* DO-NOT-DELETE splicer.begin(sort.QuickSort._ctor2) */
209
/* Insert-Code-Here {sort.QuickSort._ctor2} (special constructor method) */
210
/* DO-NOT-DELETE splicer.end(sort.QuickSort._ctor2) */
211
#line 211 "../regression/sort/libC/sort_QuickSort_Impl.c"
153
215
* Class destructor called when the class is deleted.
157
219
#define __FUNC__ "impl_sort_QuickSort__dtor"
160
225
impl_sort_QuickSort__dtor(
161
/* in */ sort_QuickSort self)
226
/* in */ sort_QuickSort self,
227
/* out */ sidl_BaseInterface *_ex)
163
#line 157 "../../../../babel/regression/sort/libC/sort_QuickSort_Impl.c"
164
/* DO-NOT-DELETE splicer.begin(sort.QuickSort._dtor) */
231
#line 232 "/home/epperly/current/release_1.2.0/linux_dist/../babel_branch/regression/sort/libC/sort_QuickSort_Impl.c"
232
/* DO-NOT-DELETE splicer.begin(sort.QuickSort._dtor) */
165
233
/* Insert the implementation of the destructor method here... */
166
/* DO-NOT-DELETE splicer.end(sort.QuickSort._dtor) */
167
#line 167 "sort_QuickSort_Impl.c"
234
/* DO-NOT-DELETE splicer.end(sort.QuickSort._dtor) */
235
#line 235 "../regression/sort/libC/sort_QuickSort_Impl.c"
175
244
#define __FUNC__ "impl_sort_QuickSort_sort"
178
250
impl_sort_QuickSort_sort(
179
251
/* in */ sort_QuickSort self,
180
252
/* in */ sort_Container elems,
181
/* in */ sort_Comparator comp)
253
/* in */ sort_Comparator comp,
254
/* out */ sidl_BaseInterface *_ex)
183
#line 175 "../../../../babel/regression/sort/libC/sort_QuickSort_Impl.c"
184
/* DO-NOT-DELETE splicer.begin(sort.QuickSort.sort) */
185
const int32_t num = sort_Container_getLength(elems);
186
sort_Counter cmp = sort_QuickSort_getCompareCounter(self);
187
sort_Counter swp = sort_QuickSort_getSwapCounter(self);
188
quickSort(elems, comp, cmp, swp, 0, num);
189
sort_Counter_deleteRef(cmp);
190
sort_Counter_deleteRef(swp);
191
/* DO-NOT-DELETE splicer.end(sort.QuickSort.sort) */
192
#line 192 "sort_QuickSort_Impl.c"
258
#line 259 "/home/epperly/current/release_1.2.0/linux_dist/../babel_branch/regression/sort/libC/sort_QuickSort_Impl.c"
259
/* DO-NOT-DELETE splicer.begin(sort.QuickSort.sort) */
260
sort_Counter cmp = NULL;
261
sort_Counter swp = NULL;
262
const int32_t num = sort_Container_getLength(elems, _ex); SIDL_REPORT(*_ex);
263
cmp = sort_QuickSort_getCompareCounter(self, _ex); SIDL_REPORT(*_ex);
264
swp = sort_QuickSort_getSwapCounter(self, _ex); SIDL_REPORT(*_ex);
265
quickSort(elems, comp, cmp, swp, 0, num, _ex); SIDL_REPORT(*_ex);
268
sidl_BaseInterface throwaway_exception;
269
if (cmp) sort_Counter_deleteRef(cmp, &throwaway_exception);
270
if (swp) sort_Counter_deleteRef(swp, &throwaway_exception);
272
/* DO-NOT-DELETE splicer.end(sort.QuickSort.sort) */
273
#line 273 "../regression/sort/libC/sort_QuickSort_Impl.c"
200
282
#define __FUNC__ "impl_sort_QuickSort_getName"
203
288
impl_sort_QuickSort_getName(
204
/* in */ sort_QuickSort self)
289
/* in */ sort_QuickSort self,
290
/* out */ sidl_BaseInterface *_ex)
206
#line 196 "../../../../babel/regression/sort/libC/sort_QuickSort_Impl.c"
207
/* DO-NOT-DELETE splicer.begin(sort.QuickSort.getName) */
294
#line 295 "/home/epperly/current/release_1.2.0/linux_dist/../babel_branch/regression/sort/libC/sort_QuickSort_Impl.c"
295
/* DO-NOT-DELETE splicer.begin(sort.QuickSort.getName) */
208
296
return sidl_String_strdup("Quick sort");
209
/* DO-NOT-DELETE splicer.end(sort.QuickSort.getName) */
210
#line 210 "sort_QuickSort_Impl.c"
297
/* DO-NOT-DELETE splicer.end(sort.QuickSort.getName) */
298
#line 298 "../regression/sort/libC/sort_QuickSort_Impl.c"
301
/* Babel internal methods, Users should not edit below this line. */
303
#line 304 "/home/epperly/current/release_1.2.0/linux_dist/../babel_branch/regression/sort/libC/sort_QuickSort_Impl.c"
304
/* DO-NOT-DELETE splicer.begin(_misc) */
305
/* Insert-Code-Here {_misc} (miscellaneous code) */
306
/* DO-NOT-DELETE splicer.end(_misc) */
307
#line 307 "../regression/sort/libC/sort_QuickSort_Impl.c"