Heap.Heap.merge.go: def of bend-kit-collections@0.1.4.1 Import: import bend-kit-collections@0.1.4.1/heap.bend as Heap Lines 33-58 of bend-kit-collections@0.1.4.1/heap.bend: https://jend.leeeet.dev/read.txt?path=bend-kit-collections@0.1.4.1/heap.bend&start_line=33&end_line=58 import Base # The smaller root wins: its right child merges with the other heap and # becomes the left, and its old left becomes the right (a skew heap's # swap, which keeps merges short on average). The fuel is the size of both # heaps: every step takes a root out, so it never runs short. def Heap.merge.go( ~A: Data, ~le: A -> A -> Bool, fuel: Nat, a: Heap, b: Heap ) -> Heap: match fuel: case 0n: a case 1n+f: match a b: case HLeaf{} HLeaf{}: HLeaf{} case HLeaf{} HNode{nb, y, bl, br}: HNode{nb, y, bl, br} case HNode{na, x, al, ar} HLeaf{}: HNode{na, x, al, ar} case HNode{+na, +x, +al, +ar} HNode{+nb, +y, +bl, +br}: +c = le(x, y) HNode{Nat.add(na, nb), Bool.pick(A, c, x, y), Heap.merge.go(~A, ~le, f, Bool.pick(Heap, c, ar, br), Bool.pick(Heap, c, HNode{nb, y, bl, br}, HNode{na, x, al, ar})), Bool.pick(Heap, c, al, bl)} Uses (5): https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Bool https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Bool.pick https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat https://jend.leeeet.dev/definition.txt?path=Base/base.bend&name=Nat.add https://jend.leeeet.dev/definition.txt?path=bend-kit-collections@0.1.4.1/heap.bend&name=Heap