let cond_pop_with_key t f = match Heap.cond_pop t.heap (fun (k, v) -> f ~key:k ~data:v) with | None -> None | Some (k, v) -> Hashtbl.remove t.tbl k; Some (k, v)