Checking if a value is contained in a MutableBinaryHeap?

Hello guys, I need to test if a value is contained in a MutableBinaryHeap.

I may have the following Tuple t:

6-element Vector{Tuple{Int64, Float64}}:
 (1, Inf)
 (2, Inf)
 (3, Inf)
 (4, Inf)
 (5, Inf)
 (6, Inf)

For the Tuple case I can just do:

a=first.(t)

And check whether a value is contained in a.
The problem is that I need to do this test on a MutableBinaryHeap.

I have the heap h

MutableBinaryHeap((1, 0.0), (2, Inf), (3, Inf), (4, Inf), (5, Inf), (6, Inf))

and doing

c=first.(h)

gives the following error:

ERROR: MethodError: no method matching iterate(::MutableBinaryHeap{Tuple{Int64, Float64}, Base.Order.By{typeof(last), Base.Order.ForwardOrdering}})

Any idea on how to test is a value is contained on the first element of a MutableBinaryHeap?

Thank you so much in advance.

Waiting for a more specific answer you could try this workaround

a=[(1, 0.0), (2, Inf), (3, Inf), (4, Inf), (5, Inf), (6, Inf)]

mbh=MutableBinaryMinHeap(a)

findfirst(t->first(t)==(2),[pop!(mbh) for _ in 1:length(mbh)])

#or


searchsorted([pop!(mbh) for _ in 1:length(mbh)],2; by=first)

Would this work for your case? (I wouldn’t usually go for directly accessing fields of structs defined in other packages, as the implementation might change. But it seems unlikely that the implementation in this case will change and it’s a pretty compact solution in my opinion)

using DataStructures

heap = MutableBinaryMinHeap([(1, 0.0), (2, Inf), (3, Inf), (4, Inf), (5, Inf), (6, Inf)])
get_value(node) = node.value

first.(get_value.(heap.nodes))

# gives
6-element Vector{Int64}:
 1
 2
 3
 4
 5
 6

The corresponding structs are defined here