(heap)
| 2138 | return 0 === heap.length ? null : heap[0]; |
| 2139 | } |
| 2140 | function pop(heap) { |
| 2141 | if (0 === heap.length) return null; |
| 2142 | var first = heap[0], |
| 2143 | last = heap.pop(); |
| 2144 | if (last !== first) { |
| 2145 | heap[0] = last; |
| 2146 | a: for ( |
| 2147 | var index = 0, length = heap.length, halfLength = length >>> 1; |
| 2148 | index < halfLength; |
| 2149 | |
| 2150 | ) { |
| 2151 | var leftIndex = 2 * (index + 1) - 1, |
| 2152 | left = heap[leftIndex], |
| 2153 | rightIndex = leftIndex + 1, |
| 2154 | right = heap[rightIndex]; |
| 2155 | if (0 > compare(left, last)) |
| 2156 | rightIndex < length && 0 > compare(right, left) |
| 2157 | ? ((heap[index] = right), |
| 2158 | (heap[rightIndex] = last), |
| 2159 | (index = rightIndex)) |
| 2160 | : ((heap[index] = left), |
| 2161 | (heap[leftIndex] = last), |
| 2162 | (index = leftIndex)); |
| 2163 | else if (rightIndex < length && 0 > compare(right, last)) |
| 2164 | (heap[index] = right), (heap[rightIndex] = last), (index = rightIndex); |
| 2165 | else break a; |
| 2166 | } |
| 2167 | } |
| 2168 | return first; |
| 2169 | } |
| 2170 | function compare(a, b) { |
| 2171 | var diff = a.sortIndex - b.sortIndex; |
| 2172 | return 0 !== diff ? diff : a.id - b.id; |
no test coverage detected