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
|
C
C File: sort_HeapSort_Impl.f
C Symbol: sort.HeapSort-v0.1
C Symbol Type: class
C Babel Version: 0.10.2
C Description: Server-side implementation for sort.HeapSort
C
C WARNING: Automatically generated; only changes within splicers preserved
C
C babel-version = 0.10.2
C
C
C Symbol "sort.HeapSort" (version 0.1)
C
C Heap sort
C
C DO-NOT-DELETE splicer.begin(_miscellaneous_code_start)
subroutine remakeHeap(elem, comp, cmp, swp, last, first)
implicit none
integer*8 elem, comp, cmp, swp
integer*4 last, first, half, child, result, counter
integer*4 f
f = first
half = (last/2) - 1
do while (f .le. half)
child = f + f + 1
if ((child + 1) .lt. last) then
call sort_Counter_inc_f(cmp, counter)
call sort_Container_compare_f(elem, child, child+1,
$ comp, result)
if (result .lt. 0) then
child = child + 1
endif
endif
call sort_Counter_inc_f(cmp, counter)
call sort_Container_compare_f(elem, f, child, comp,
$ result)
if (result .ge. 0) goto 100
call sort_Counter_inc_f(swp, counter)
call sort_Container_swap_f(elem, f, child)
f = child
enddo
100 return
end
C DO-NOT-DELETE splicer.end(_miscellaneous_code_start)
C
C Class constructor called when the class is created.
C
subroutine sort_HeapSort__ctor_fi(self)
implicit none
C in sort.HeapSort self
integer*8 self
C DO-NOT-DELETE splicer.begin(sort.HeapSort._ctor)
C Insert the implementation here...
C DO-NOT-DELETE splicer.end(sort.HeapSort._ctor)
end
C
C Class destructor called when the class is deleted.
C
subroutine sort_HeapSort__dtor_fi(self)
implicit none
C in sort.HeapSort self
integer*8 self
C DO-NOT-DELETE splicer.begin(sort.HeapSort._dtor)
C Insert the implementation here...
C DO-NOT-DELETE splicer.end(sort.HeapSort._dtor)
end
C
C Static class initializer called exactly once before any user-defined method is dispatched
C
subroutine sort_HeapSort__load_fi()
implicit none
C DO-NOT-DELETE splicer.begin(sort.HeapSort._load)
C Insert the implementation here...
C DO-NOT-DELETE splicer.end(sort.HeapSort._load)
end
C
C Sort elements using Heap Sort.
C
subroutine sort_HeapSort_sort_fi(self, elems, comp)
implicit none
C in sort.HeapSort self
integer*8 self
C in sort.Container elems
integer*8 elems
C in sort.Comparator comp
integer*8 comp
C DO-NOT-DELETE splicer.begin(sort.HeapSort.sort)
integer*4 i, num, counter
integer*8 cmp, swp
call sort_Container_getLength_f(elems, num)
call sort_HeapSort_getCompareCounter_f(self, cmp)
call sort_HeapSort_getSwapCounter_f(self, swp)
C make the heap
do i = ((num / 2) - 1), 0, -1
call remakeHeap(elems, comp, cmp, swp, num, i)
enddo
C put top of heap at back and remake the heap
i = num - 1
do while (i .gt. 0)
call sort_Counter_inc_f(swp, counter)
call sort_Container_swap_f(elems, 0, i)
call remakeHeap(elems, comp, cmp, swp, i, 0)
i = i - 1
enddo
call sort_Counter_deleteRef_f(cmp)
call sort_Counter_deleteRef_f(swp)
C DO-NOT-DELETE splicer.end(sort.HeapSort.sort)
end
C
C Return heap sort.
C
subroutine sort_HeapSort_getName_fi(self, retval)
implicit none
C in sort.HeapSort self
integer*8 self
C out string retval
character*(*) retval
C DO-NOT-DELETE splicer.begin(sort.HeapSort.getName)
retval = 'Heap sort'
C DO-NOT-DELETE splicer.end(sort.HeapSort.getName)
end
C DO-NOT-DELETE splicer.begin(_miscellaneous_code_end)
C Insert extra code here...
C DO-NOT-DELETE splicer.end(_miscellaneous_code_end)
|