1 import Base 2 import ./binary_heap.bend as K 3 import ./types/binary_heap.bend as E 4 5 # Single-threaded queue API; storage and algorithms are shared with binary_heap. 6 def new(~A: Data) -> K.Heap: 7 K.new(~A) 8 9 def qsize(~A: Data, h: K.Heap) -> K.Heap & Nat: 10 K.length(~A, h) 11 12 def put(~A: Data, ~cmp: A -> A -> Cmp, h: K.Heap, x: A) -> K.Heap: 13 K.push(~A, ~cmp, h, x) 14 15 def peek(~A: Data, h: K.Heap) -> K.Heap & Result<&2, &2, E.Error, A>: 16 K.peek(~A, h) 17 18 def get(~A: Data, ~cmp: A -> A -> Cmp, h: K.Heap) -> K.Heap & Result<&2, &2, E.Error, A>: 19 K.pop(~A, ~cmp, h) 20 21 def from_list(~A: Data, ~cmp: A -> A -> Cmp, xs: List<&2, A>) -> K.Heap: 22 K.from_list(~A, ~cmp, xs) 23 24 def to_sorted_list(~A: Data, ~cmp: A -> A -> Cmp, h: K.Heap) -> K.Heap & List<&2, A>: 25 K.to_sorted_list(~A, ~cmp, h)