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 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
|
/*
* File: sort_HeapSort_Impl.c
* Symbol: sort.HeapSort-v0.1
* Symbol Type: class
* Babel Version: 0.10.2
* Description: Server-side implementation for sort.HeapSort
*
* WARNING: Automatically generated; only changes within splicers preserved
*
* babel-version = 0.10.2
*/
/*
* DEVELOPERS ARE EXPECTED TO PROVIDE IMPLEMENTATIONS
* FOR THE FOLLOWING METHODS BETWEEN SPLICER PAIRS.
*/
/*
* Symbol "sort.HeapSort" (version 0.1)
*
* Heap sort
*/
#include "sort_HeapSort_Impl.h"
#line 26 "../../../../babel/regression/sort/libC/sort_HeapSort_Impl.c"
/* DO-NOT-DELETE splicer.begin(sort.HeapSort._includes) */
#include "sidl_String.h"
#include "sort_Container.h"
static void remakeHeap(sort_Container elem,
sort_Comparator comp,
sort_Counter cmp,
sort_Counter swp,
const int32_t last,
int32_t first)
{
const int32_t half = (last >> 1) - 1;
int32_t child;
while (first <= half) {
child = first + first + 1;
if ((child+1) < last) {
sort_Counter_inc(cmp);
if (sort_Container_compare(elem, child, child+1, comp) < 0) ++child;
}
sort_Counter_inc(cmp);
if (sort_Container_compare(elem,first, child,comp) >= 0) break;
sort_Counter_inc(swp);
sort_Container_swap(elem, first, child);
first = child;
}
}
/* DO-NOT-DELETE splicer.end(sort.HeapSort._includes) */
#line 54 "sort_HeapSort_Impl.c"
/*
* Static class initializer called exactly once before any user-defined method is dispatched
*/
#undef __FUNC__
#define __FUNC__ "impl_sort_HeapSort__load"
void
impl_sort_HeapSort__load(
void)
{
#line 65 "../../../../babel/regression/sort/libC/sort_HeapSort_Impl.c"
/* DO-NOT-DELETE splicer.begin(sort.HeapSort._load) */
/* Insert the implementation of the static class initializer method here... */
/* DO-NOT-DELETE splicer.end(sort.HeapSort._load) */
#line 71 "sort_HeapSort_Impl.c"
}
/*
* Class constructor called when the class is created.
*/
#undef __FUNC__
#define __FUNC__ "impl_sort_HeapSort__ctor"
void
impl_sort_HeapSort__ctor(
/* in */ sort_HeapSort self)
{
#line 80 "../../../../babel/regression/sort/libC/sort_HeapSort_Impl.c"
/* DO-NOT-DELETE splicer.begin(sort.HeapSort._ctor) */
/* Insert the implementation of the constructor method here... */
/* DO-NOT-DELETE splicer.end(sort.HeapSort._ctor) */
#line 88 "sort_HeapSort_Impl.c"
}
/*
* Class destructor called when the class is deleted.
*/
#undef __FUNC__
#define __FUNC__ "impl_sort_HeapSort__dtor"
void
impl_sort_HeapSort__dtor(
/* in */ sort_HeapSort self)
{
#line 96 "../../../../babel/regression/sort/libC/sort_HeapSort_Impl.c"
/* DO-NOT-DELETE splicer.begin(sort.HeapSort._dtor) */
/* Insert the implementation of the destructor method here... */
/* DO-NOT-DELETE splicer.end(sort.HeapSort._dtor) */
#line 106 "sort_HeapSort_Impl.c"
}
/*
* Sort elements using Heap Sort.
*/
#undef __FUNC__
#define __FUNC__ "impl_sort_HeapSort_sort"
void
impl_sort_HeapSort_sort(
/* in */ sort_HeapSort self,
/* in */ sort_Container elems,
/* in */ sort_Comparator comp)
{
#line 114 "../../../../babel/regression/sort/libC/sort_HeapSort_Impl.c"
/* DO-NOT-DELETE splicer.begin(sort.HeapSort.sort) */
int32_t i;
const int32_t num = sort_Container_getLength(elems);
sort_Counter cmp = sort_HeapSort_getCompareCounter(self);
sort_Counter swp = sort_HeapSort_getSwapCounter(self);
/* make the heap */
for(i = ((num/2) - 1); i >= 0; --i) {
remakeHeap(elems, comp, cmp, swp, num, i);
}
/* put top of heap at back and remake the heap */
i = num - 1;
while (i > 0) {
sort_Counter_inc(swp);
sort_Container_swap(elems, 0, i);
remakeHeap(elems, comp, cmp, swp, i--, 0);
}
sort_Counter_deleteRef(cmp);
sort_Counter_deleteRef(swp);
/* DO-NOT-DELETE splicer.end(sort.HeapSort.sort) */
#line 142 "sort_HeapSort_Impl.c"
}
/*
* Return heap sort.
*/
#undef __FUNC__
#define __FUNC__ "impl_sort_HeapSort_getName"
char*
impl_sort_HeapSort_getName(
/* in */ sort_HeapSort self)
{
#line 146 "../../../../babel/regression/sort/libC/sort_HeapSort_Impl.c"
/* DO-NOT-DELETE splicer.begin(sort.HeapSort.getName) */
return sidl_String_strdup("Heap sort");
/* DO-NOT-DELETE splicer.end(sort.HeapSort.getName) */
#line 160 "sort_HeapSort_Impl.c"
}
|