MCPcopy Create free account
hub / github.com/Effect-TS/effect / minHeapPop

Function minHeapPop

packages/effect/src/Graph.ts:4020–4042  ·  view source on GitHub ↗
(heap: Array<MinHeapEntry>)

Source from the content-addressed store, hash-verified

4018}
4019
4020const minHeapPop = (heap: Array<MinHeapEntry>): MinHeapEntry | undefined => {
4021 const first = heap[0]
4022 const last = heap.pop()
4023 if (last === undefined || heap.length === 0) {
4024 return first
4025 }
4026 let index = 0
4027 while (true) {
4028 const left = index * 2 + 1
4029 if (left >= heap.length) {
4030 break
4031 }
4032 const right = left + 1
4033 const child = right < heap.length && minHeapLessThan(heap[right], heap[left]) ? right : left
4034 if (!minHeapLessThan(heap[child], last)) {
4035 break
4036 }
4037 heap[index] = heap[child]
4038 index = child
4039 }
4040 heap[index] = last
4041 return first
4042}
4043
4044/**
4045 * Configuration for finding a shortest path with Dijkstra's algorithm.

Callers 1

Graph.tsFile · 0.85

Calls 1

minHeapLessThanFunction · 0.85

Tested by

no test coverage detected