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 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184
|
!
! File: sort_HeapSort_Impl.F90
! 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
!
!
! Symbol "sort.HeapSort" (version 0.1)
!
! Heap sort
!
#include "sort_HeapSort_fAbbrev.h"
#include "sort_SortingAlgorithm_fAbbrev.h"
#include "sidl_ClassInfo_fAbbrev.h"
#include "sort_Comparator_fAbbrev.h"
#include "sidl_BaseInterface_fAbbrev.h"
#include "sort_Container_fAbbrev.h"
#include "sort_Counter_fAbbrev.h"
#include "sidl_BaseClass_fAbbrev.h"
! DO-NOT-DELETE splicer.begin(_miscellaneous_code_start)
subroutine remakeHeap(elem, comp, cmp, swp, last, first)
use sort_Counter
use sort_Comparator
use sort_Container
implicit none
type(sort_Counter_t) cmp, swp
type(sort_Comparator_t) comp
type(sort_Container_t) elem
integer(selected_int_kind(9)) last, first, half, child, result, counter
integer(selected_int_kind(9)) f
f = first
half = (last/2) - 1
do while (f .le. half)
child = f + f + 1
if ((child + 1) .lt. last) then
call inc(cmp, counter)
call compare(elem, child, child+1, comp, result)
if (result .lt. 0) then
child = child + 1
endif
endif
call inc(cmp, counter)
call compare(elem, f, child, comp, result)
if (result .ge. 0) goto 100
call inc(swp, counter)
call swap(elem, f, child)
f = child
enddo
100 return
end subroutine remakeHeap
! DO-NOT-DELETE splicer.end(_miscellaneous_code_start)
!
! Class constructor called when the class is created.
!
recursive subroutine sort_HeapSort__ctor_mi(self)
use sort_HeapSort
use sort_HeapSort_impl
! DO-NOT-DELETE splicer.begin(sort.HeapSort._ctor.use)
! Insert use statements here...
! DO-NOT-DELETE splicer.end(sort.HeapSort._ctor.use)
implicit none
type(sort_HeapSort_t) :: self ! in
! DO-NOT-DELETE splicer.begin(sort.HeapSort._ctor)
! Insert the implementation here...
! DO-NOT-DELETE splicer.end(sort.HeapSort._ctor)
end subroutine sort_HeapSort__ctor_mi
!
! Class destructor called when the class is deleted.
!
recursive subroutine sort_HeapSort__dtor_mi(self)
use sort_HeapSort
use sort_HeapSort_impl
! DO-NOT-DELETE splicer.begin(sort.HeapSort._dtor.use)
! Insert use statements here...
! DO-NOT-DELETE splicer.end(sort.HeapSort._dtor.use)
implicit none
type(sort_HeapSort_t) :: self ! in
! DO-NOT-DELETE splicer.begin(sort.HeapSort._dtor)
! Insert the implementation here...
! DO-NOT-DELETE splicer.end(sort.HeapSort._dtor)
end subroutine sort_HeapSort__dtor_mi
!
! Static class initializer called exactly once before any user-defined method is dispatched
!
recursive subroutine sort_HeapSort__load_mi()
use sort_HeapSort
use sort_HeapSort_impl
! DO-NOT-DELETE splicer.begin(sort.HeapSort._load.use)
! Insert use statements here...
! DO-NOT-DELETE splicer.end(sort.HeapSort._load.use)
implicit none
! DO-NOT-DELETE splicer.begin(sort.HeapSort._load)
! Insert the implementation here...
! DO-NOT-DELETE splicer.end(sort.HeapSort._load)
end subroutine sort_HeapSort__load_mi
!
! Sort elements using Heap Sort.
!
recursive subroutine sort_HeapSort_sort_mi(self, elems, comp)
use sort_HeapSort
use sort_Container
use sort_Comparator
use sort_HeapSort_impl
! DO-NOT-DELETE splicer.begin(sort.HeapSort.sort.use)
use sort_Counter
! DO-NOT-DELETE splicer.end(sort.HeapSort.sort.use)
implicit none
type(sort_HeapSort_t) :: self ! in
type(sort_Container_t) :: elems ! in
type(sort_Comparator_t) :: comp ! in
! DO-NOT-DELETE splicer.begin(sort.HeapSort.sort)
integer(selected_int_kind(9)) i, num, counter
type(sort_Counter_t) cmp, swp
call getLength(elems, num)
call getCompareCounter(self, cmp)
call getSwapCounter(self, swp)
! make the heap
do i = ((num / 2) - 1), 0, -1
call remakeHeap(elems, comp, cmp, swp, num, i)
enddo
! put top of heap at back and remake the heap
i = num - 1
do while (i .gt. 0)
call inc(swp, counter)
call swap(elems, 0, i)
call remakeHeap(elems, comp, cmp, swp, i, 0)
i = i - 1
enddo
call deleteRef(cmp)
call deleteRef(swp)
! DO-NOT-DELETE splicer.end(sort.HeapSort.sort)
end subroutine sort_HeapSort_sort_mi
!
! Return heap sort.
!
recursive subroutine sort_HeapSort_getName_mi(self, retval)
use sort_HeapSort
use sort_HeapSort_impl
! DO-NOT-DELETE splicer.begin(sort.HeapSort.getName.use)
! Insert use statements here...
! DO-NOT-DELETE splicer.end(sort.HeapSort.getName.use)
implicit none
type(sort_HeapSort_t) :: self ! in
character (len=*) :: retval ! out
! DO-NOT-DELETE splicer.begin(sort.HeapSort.getName)
retval = 'Heap sort'
! DO-NOT-DELETE splicer.end(sort.HeapSort.getName)
end subroutine sort_HeapSort_getName_mi
! DO-NOT-DELETE splicer.begin(_miscellaneous_code_end)
! Insert extra code here...
! DO-NOT-DELETE splicer.end(_miscellaneous_code_end)
|