~ubuntu-branches/ubuntu/raring/babel/raring-proposed

« back to all changes in this revision

Viewing changes to regression/sort/libC/sort_QuickSort_Impl.c

  • Committer: Bazaar Package Importer
  • Author(s): Adam C. Powell, IV
  • Date: 2008-08-01 07:56:58 UTC
  • mfrom: (3.1.2 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080801075658-9ezcrbh8dcs8lg70
Tags: 1.2.0.dfsg-6
Added libparsifal-dev as dependency to libsidl-dev (closes: #483324).

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * File:          sort_QuickSort_Impl.c
3
3
 * Symbol:        sort.QuickSort-v0.1
4
4
 * Symbol Type:   class
5
 
 * Babel Version: 0.10.2
 
5
 * Babel Version: 1.2.0
6
6
 * Description:   Server-side implementation for sort.QuickSort
7
7
 * 
8
8
 * WARNING: Automatically generated; only changes within splicers preserved
9
9
 * 
10
 
 * babel-version = 0.10.2
11
10
 */
12
11
 
13
12
/*
22
21
 */
23
22
 
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"
 
28
#endif
25
29
 
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"
32
36
#include <stdio.h>
 
37
#include "sidl_Exception.h"
33
38
 
34
39
/**
35
40
 * Choose the middle of the first, middle and last element of the
40
45
            sort_Comparator comp,
41
46
            sort_Counter    cmp,
42
47
            int32_t         start,
43
 
            int32_t         end)
 
48
            int32_t         end, 
 
49
            sidl_BaseInterface *_ex)
44
50
{
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) {
 
56
      SIDL_REPORT(*_ex);
 
57
      sort_Counter_inc(cmp, _ex); SIDL_REPORT(*_ex);
 
58
      if (sort_Container_compare(elems, mid, end - 1, comp, _ex) > 0) {
 
59
        SIDL_REPORT(*_ex);
 
60
        sort_Counter_inc(cmp, _ex); SIDL_REPORT(*_ex);
 
61
        if (sort_Container_compare(elems, start, end - 1, comp, _ex) < 0) {
 
62
          SIDL_REPORT(*_ex);
54
63
          pivot = end - 1;
55
64
        }
56
65
        else {
 
66
          SIDL_REPORT(*_ex);
57
67
          pivot = start;
58
68
        }
59
69
      }
60
70
    }
61
71
    else {
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) {
 
72
      SIDL_REPORT(*_ex);
 
73
      sort_Counter_inc(cmp, _ex); SIDL_REPORT(*_ex);
 
74
      if (sort_Container_compare(elems, mid, end - 1, comp, _ex) < 0) {
 
75
        SIDL_REPORT(*_ex);
 
76
        sort_Counter_inc(cmp, _ex); SIDL_REPORT(*_ex);
 
77
        if (sort_Container_compare(elems, start, end - 1, comp, _ex) > 0) {
 
78
          SIDL_REPORT(*_ex);
66
79
          pivot = end - 1;
67
80
        }
68
81
        else {
 
82
          SIDL_REPORT(*_ex);
69
83
          pivot = start;
70
84
        }
71
85
      }
72
86
    }
73
87
  }
 
88
 EXIT:
74
89
  return pivot;
75
90
}
76
91
 
80
95
          sort_Counter    cmp,
81
96
          sort_Counter    swp,
82
97
          int32_t         start,
83
 
          int32_t         end)
 
98
          int32_t         end,
 
99
          sidl_BaseInterface *_ex)
84
100
{
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;
88
104
    int32_t j = end;
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);
 
107
 
 
108
      sort_Container_swap(elems, start, pivot, _ex); SIDL_REPORT(*_ex);
92
109
    }
93
110
    for(;;) {
94
111
      do {
 
112
        SIDL_REPORT(*_ex);
95
113
        --j;
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);
 
116
      SIDL_REPORT(*_ex);
98
117
      while (++i < j) {
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); 
 
119
        SIDL_REPORT(*_ex);
 
120
        sort_Counter_inc(cmp, _ex); SIDL_REPORT(*_ex);
 
121
        if (icmp < 0) break;
101
122
      }
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);
105
126
    }
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);
109
130
    }
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);
112
133
  }
 
134
 EXIT:;
113
135
}
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"
116
138
 
 
139
#define SIDL_IOR_MAJOR_VERSION 2
 
140
#define SIDL_IOR_MINOR_VERSION 0
117
141
/*
118
142
 * Static class initializer called exactly once before any user-defined method is dispatched
119
143
 */
121
145
#undef __FUNC__
122
146
#define __FUNC__ "impl_sort_QuickSort__load"
123
147
 
 
148
#ifdef __cplusplus
 
149
extern "C"
 
150
#endif
124
151
void
125
152
impl_sort_QuickSort__load(
126
 
  void)
 
153
  /* out */ sidl_BaseInterface *_ex)
127
154
{
128
 
#line 126 "../../../../babel/regression/sort/libC/sort_QuickSort_Impl.c"
129
 
  /* DO-NOT-DELETE splicer.begin(sort.QuickSort._load) */
 
155
  *_ex = 0;
 
156
  {
 
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"
 
162
  }
133
163
}
134
164
/*
135
165
 * Class constructor called when the class is created.
138
168
#undef __FUNC__
139
169
#define __FUNC__ "impl_sort_QuickSort__ctor"
140
170
 
 
171
#ifdef __cplusplus
 
172
extern "C"
 
173
#endif
141
174
void
142
175
impl_sort_QuickSort__ctor(
143
 
  /* in */ sort_QuickSort self)
 
176
  /* in */ sort_QuickSort self,
 
177
  /* out */ sidl_BaseInterface *_ex)
144
178
{
145
 
#line 141 "../../../../babel/regression/sort/libC/sort_QuickSort_Impl.c"
146
 
  /* DO-NOT-DELETE splicer.begin(sort.QuickSort._ctor) */
 
179
  *_ex = 0;
 
180
  {
 
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"
150
 
}
151
 
 
 
184
    /* DO-NOT-DELETE splicer.end(sort.QuickSort._ctor) */
 
185
#line 185 "../regression/sort/libC/sort_QuickSort_Impl.c"
 
186
  }
 
187
}
 
188
 
 
189
/*
 
190
 * Special Class constructor called when the user wants to wrap his own private data.
 
191
 */
 
192
 
 
193
#undef __FUNC__
 
194
#define __FUNC__ "impl_sort_QuickSort__ctor2"
 
195
 
 
196
#ifdef __cplusplus
 
197
extern "C"
 
198
#endif
 
199
void
 
200
impl_sort_QuickSort__ctor2(
 
201
  /* in */ sort_QuickSort self,
 
202
  /* in */ void* private_data,
 
203
  /* out */ sidl_BaseInterface *_ex)
 
204
{
 
205
  *_ex = 0;
 
206
  {
 
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"
 
212
  }
 
213
}
152
214
/*
153
215
 * Class destructor called when the class is deleted.
154
216
 */
156
218
#undef __FUNC__
157
219
#define __FUNC__ "impl_sort_QuickSort__dtor"
158
220
 
 
221
#ifdef __cplusplus
 
222
extern "C"
 
223
#endif
159
224
void
160
225
impl_sort_QuickSort__dtor(
161
 
  /* in */ sort_QuickSort self)
 
226
  /* in */ sort_QuickSort self,
 
227
  /* out */ sidl_BaseInterface *_ex)
162
228
{
163
 
#line 157 "../../../../babel/regression/sort/libC/sort_QuickSort_Impl.c"
164
 
  /* DO-NOT-DELETE splicer.begin(sort.QuickSort._dtor) */
 
229
  *_ex = 0;
 
230
  {
 
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"
 
236
  }
168
237
}
169
238
 
170
239
/*
174
243
#undef __FUNC__
175
244
#define __FUNC__ "impl_sort_QuickSort_sort"
176
245
 
 
246
#ifdef __cplusplus
 
247
extern "C"
 
248
#endif
177
249
void
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)
182
255
{
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"
 
256
  *_ex = 0;
 
257
  {
 
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);
 
266
 EXIT:
 
267
  {
 
268
    sidl_BaseInterface throwaway_exception;
 
269
    if (cmp) sort_Counter_deleteRef(cmp, &throwaway_exception);
 
270
    if (swp) sort_Counter_deleteRef(swp, &throwaway_exception);
 
271
  }
 
272
    /* DO-NOT-DELETE splicer.end(sort.QuickSort.sort) */
 
273
#line 273 "../regression/sort/libC/sort_QuickSort_Impl.c"
 
274
  }
193
275
}
194
276
 
195
277
/*
199
281
#undef __FUNC__
200
282
#define __FUNC__ "impl_sort_QuickSort_getName"
201
283
 
 
284
#ifdef __cplusplus
 
285
extern "C"
 
286
#endif
202
287
char*
203
288
impl_sort_QuickSort_getName(
204
 
  /* in */ sort_QuickSort self)
 
289
  /* in */ sort_QuickSort self,
 
290
  /* out */ sidl_BaseInterface *_ex)
205
291
{
206
 
#line 196 "../../../../babel/regression/sort/libC/sort_QuickSort_Impl.c"
207
 
  /* DO-NOT-DELETE splicer.begin(sort.QuickSort.getName) */
 
292
  *_ex = 0;
 
293
  {
 
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"
 
299
  }
211
300
}
 
301
/* Babel internal methods, Users should not edit below this line. */
 
302
 
 
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"
 
308