File: sort_MergeSort_Impl.cc

package info (click to toggle)
babel 0.10.2-1
  • links: PTS
  • area: contrib
  • in suites: sarge
  • size: 43,932 kB
  • ctags: 29,707
  • sloc: java: 74,695; ansic: 73,142; cpp: 40,649; sh: 18,411; f90: 10,062; fortran: 6,727; python: 6,406; makefile: 3,866; xml: 118; perl: 48
file content (149 lines) | stat: -rw-r--r-- 4,300 bytes parent folder | download
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
// 
// 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"

// 
// Includes for all method dependencies.
// 
#ifndef included_sidl_BaseInterface_hh
#include "sidl_BaseInterface.hh"
#endif
#ifndef included_sidl_ClassInfo_hh
#include "sidl_ClassInfo.hh"
#endif
#ifndef included_sort_Comparator_hh
#include "sort_Comparator.hh"
#endif
#ifndef included_sort_Container_hh
#include "sort_Container.hh"
#endif
#ifndef included_sort_Counter_hh
#include "sort_Counter.hh"
#endif
#line 32 "../../../../babel/regression/sort/libUCxx/sort_MergeSort_Impl.cc"
// DO-NOT-DELETE splicer.begin(sort.MergeSort._includes)
static void
mergeLists(ucxx::sort::Container  &elems,
           ucxx::sort::Comparator &comp,
           ucxx::sort::Counter    &cmp,
           ucxx::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(ucxx::sort::Container  &elems,
          ucxx::sort::Comparator &comp,
          ucxx::sort::Counter    &cmp,
          ucxx::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 77 "sort_MergeSort_Impl.cc"

// user defined constructor
void sort::MergeSort_impl::_ctor() {
#line 79 "../../../../babel/regression/sort/libUCxx/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 85 "sort_MergeSort_Impl.cc"
}

// user defined destructor
void sort::MergeSort_impl::_dtor() {
#line 86 "../../../../babel/regression/sort/libUCxx/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 94 "sort_MergeSort_Impl.cc"
}

// static class initializer
void sort::MergeSort_impl::_load() {
#line 93 "../../../../babel/regression/sort/libUCxx/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 103 "sort_MergeSort_Impl.cc"
}

// user defined static methods: (none)

// user defined non-static methods:
/**
 * Sort elements using Merge Sort.
 */
void
sort::MergeSort_impl::sort_impl (
  /* in */::ucxx::sort::Container elems,
  /* in */::ucxx::sort::Comparator comp ) 
throw () 
{
#line 110 "../../../../babel/regression/sort/libUCxx/sort_MergeSort_Impl.cc"
  // DO-NOT-DELETE splicer.begin(sort.MergeSort.sort)
  const int32_t num = elems.getLength();
  ucxx::sort::Counter cmp = getCompareCounter();
  ucxx::sort::Counter swp = getSwapCounter();
  mergeSort(elems, comp, cmp, swp, 0, num);
  // DO-NOT-DELETE splicer.end(sort.MergeSort.sort)
#line 125 "sort_MergeSort_Impl.cc"
}

/**
 * Return merge sort.
 */
::std::string
sort::MergeSort_impl::getName_impl () 
throw () 

{
#line 126 "../../../../babel/regression/sort/libUCxx/sort_MergeSort_Impl.cc"
  // DO-NOT-DELETE splicer.begin(sort.MergeSort.getName)
  return "Merge sort";
  // DO-NOT-DELETE splicer.end(sort.MergeSort.getName)
#line 140 "sort_MergeSort_Impl.cc"
}


#line 132 "../../../../babel/regression/sort/libUCxx/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 148 "sort_MergeSort_Impl.cc"