MCPcopy Create free account
hub / github.com/EdwardRaff/JSAT / heapDown

Method heapDown

JSAT/src/jsat/utils/IntPriorityQueue.java:243–265  ·  view source on GitHub ↗
(int i)

Source from the content-addressed store, hash-verified

241 }
242
243 private void heapDown(int i)
244 {
245 int iL = leftChild(i);
246 int iR = rightChild(i);
247 //While we have two children, make sure we are smaller
248 while (childIsSmallerAndValid(i, iL) || childIsSmallerAndValid(i, iR))
249 {
250 //we are larger then one of ours children, so swap with the smallest of the two
251 if ( iR < size && cmp(iL, iR) > 0 )//Right is the smallest
252 {
253 swapHeapValues(i, iR);
254 i = iR;
255 }
256 else//Left is smallest or lef tis only option
257 {
258 swapHeapValues(i, iL);
259 i = iL;
260 }
261
262 iL = leftChild(i);
263 iR = rightChild(i);
264 }
265 }
266
267 /**
268 * Heapify up from the given index in the heap and make sure everything is

Callers 1

removeHeapNodeMethod · 0.95

Calls 5

leftChildMethod · 0.95
rightChildMethod · 0.95
cmpMethod · 0.95
swapHeapValuesMethod · 0.95

Tested by

no test coverage detected