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
|
//
// File: sort_MergeSort_Impl.cc
// Symbol: sort.MergeSort-v0.1
// Symbol Type: class
// Babel Version: 0.10.2
// Description: Server-side implementation for sort.MergeSort
//
// WARNING: Automatically generated; only changes within splicers preserved
//
// babel-version = 0.10.2
//
#include "sort_MergeSort_Impl.hh"
#line 14 "../../../../babel/regression/sort/libCxx/sort_MergeSort_Impl.cc"
// DO-NOT-DELETE splicer.begin(sort.MergeSort._includes)
static void
mergeLists(sort::Container &elems,
sort::Comparator &comp,
sort::Counter &cmp,
sort::Counter &swp,
int32_t start,
int32_t mid,
const int32_t end)
{
int32_t j;
while ((start < mid) && (mid < end)) {
cmp.inc();
if (elems.compare(start, mid, comp) > 0) {
/* move first element of upper list into place */
for(j = mid;j > start; --j) {
swp.inc();
elems.swap(j, j - 1);
}
++mid;
}
++start;
}
}
/**
* end is one past the end
*/
static void
mergeSort(sort::Container &elems,
sort::Comparator &comp,
sort::Counter &cmp,
sort::Counter &swp,
const int32_t start,
const int32_t end)
{
if ((end - start) > 1) {
int32_t mid = (start + end) >> 1;
mergeSort(elems, comp, cmp, swp, start, mid);
mergeSort(elems, comp, cmp, swp, mid, end);
mergeLists(elems, comp, cmp, swp, start, mid, end);
}
}
// DO-NOT-DELETE splicer.end(sort.MergeSort._includes)
#line 59 "sort_MergeSort_Impl.cc"
// user-defined constructor.
void sort::MergeSort_impl::_ctor() {
#line 61 "../../../../babel/regression/sort/libCxx/sort_MergeSort_Impl.cc"
// DO-NOT-DELETE splicer.begin(sort.MergeSort._ctor)
// add construction details here
// DO-NOT-DELETE splicer.end(sort.MergeSort._ctor)
#line 67 "sort_MergeSort_Impl.cc"
}
// user-defined destructor.
void sort::MergeSort_impl::_dtor() {
#line 68 "../../../../babel/regression/sort/libCxx/sort_MergeSort_Impl.cc"
// DO-NOT-DELETE splicer.begin(sort.MergeSort._dtor)
// add destruction details here
// DO-NOT-DELETE splicer.end(sort.MergeSort._dtor)
#line 76 "sort_MergeSort_Impl.cc"
}
// static class initializer.
void sort::MergeSort_impl::_load() {
#line 75 "../../../../babel/regression/sort/libCxx/sort_MergeSort_Impl.cc"
// DO-NOT-DELETE splicer.begin(sort.MergeSort._load)
// guaranteed to be called at most once before any other method in this class
// DO-NOT-DELETE splicer.end(sort.MergeSort._load)
#line 85 "sort_MergeSort_Impl.cc"
}
// user-defined static methods: (none)
// user-defined non-static methods:
/**
* Sort elements using Merge Sort.
*/
void
sort::MergeSort_impl::sort (
/* in */ ::sort::Container elems,
/* in */ ::sort::Comparator comp )
throw ()
{
#line 92 "../../../../babel/regression/sort/libCxx/sort_MergeSort_Impl.cc"
// DO-NOT-DELETE splicer.begin(sort.MergeSort.sort)
const int32_t num = elems.getLength();
sort::Counter cmp = self.getCompareCounter();
sort::Counter swp = self.getSwapCounter();
mergeSort(elems, comp, cmp, swp, 0, num);
// DO-NOT-DELETE splicer.end(sort.MergeSort.sort)
#line 107 "sort_MergeSort_Impl.cc"
}
/**
* Return merge sort.
*/
::std::string
sort::MergeSort_impl::getName ()
throw ()
{
#line 108 "../../../../babel/regression/sort/libCxx/sort_MergeSort_Impl.cc"
// DO-NOT-DELETE splicer.begin(sort.MergeSort.getName)
return "Merge sort";
// DO-NOT-DELETE splicer.end(sort.MergeSort.getName)
#line 122 "sort_MergeSort_Impl.cc"
}
#line 114 "../../../../babel/regression/sort/libCxx/sort_MergeSort_Impl.cc"
// DO-NOT-DELETE splicer.begin(sort.MergeSort._misc)
// Put miscellaneous code here
// DO-NOT-DELETE splicer.end(sort.MergeSort._misc)
#line 130 "sort_MergeSort_Impl.cc"
|