@@ -46,7 +46,7 @@ public struct Heap<T> {
4646 fileprivate mutating func buildHeap( fromArray array: [ T ] ) {
4747 elements = array
4848 for i in stride ( from: ( elements. count/ 2 - 1 ) , through: 0 , by: - 1 ) {
49- shiftDown ( index : i, heapSize: elements. count)
49+ shiftDown ( i, heapSize: elements. count)
5050 }
5151 }
5252
@@ -98,7 +98,7 @@ public struct Heap<T> {
9898 */
9999 public mutating func insert( _ value: T ) {
100100 elements. append ( value)
101- shiftUp ( index : elements. count - 1 )
101+ shiftUp ( elements. count - 1 )
102102 }
103103
104104 public mutating func insert< S: Sequence > ( _ sequence: S ) where S. Iterator. Element == T {
@@ -116,7 +116,7 @@ public struct Heap<T> {
116116
117117 assert ( isOrderedBefore ( value, elements [ i] ) )
118118 elements [ i] = value
119- shiftUp ( index : i)
119+ shiftUp ( i)
120120 }
121121
122122 /**
@@ -142,14 +142,14 @@ public struct Heap<T> {
142142 * Removes an arbitrary node from the heap. Performance: O(log n). You need
143143 * to know the node's index, which may actually take O(n) steps to find.
144144 */
145- public mutating func removeAt( index: Int ) -> T ? {
145+ public mutating func removeAt( _ index: Int ) -> T ? {
146146 guard index < elements. count else { return nil }
147147
148148 let size = elements. count - 1
149149 if index != size {
150150 swap ( & elements[ index] , & elements[ size] )
151- shiftDown ( index: index , heapSize: size)
152- shiftUp ( index: index )
151+ shiftDown ( index, heapSize: size)
152+ shiftUp ( index)
153153 }
154154 return elements. removeLast ( )
155155 }
@@ -158,7 +158,7 @@ public struct Heap<T> {
158158 * Takes a child node and looks at its parents; if a parent is not larger
159159 * (max-heap) or not smaller (min-heap) than the child, we exchange them.
160160 */
161- mutating func shiftUp( index: Int ) {
161+ mutating func shiftUp( _ index: Int ) {
162162 var childIndex = index
163163 let child = elements [ childIndex]
164164 var parentIndex = self . parentIndex ( ofIndex: childIndex)
@@ -173,14 +173,14 @@ public struct Heap<T> {
173173 }
174174
175175 mutating func shiftDown( ) {
176- shiftDown ( index : 0 , heapSize: elements. count)
176+ shiftDown ( 0 , heapSize: elements. count)
177177 }
178178
179179 /**
180180 * Looks at a parent node and makes sure it is still larger (max-heap) or
181181 * smaller (min-heap) than its childeren.
182182 */
183- mutating func shiftDown( index: Int , heapSize: Int ) {
183+ mutating func shiftDown( _ index: Int , heapSize: Int ) {
184184 var parentIndex = index
185185
186186 while true {
0 commit comments