# Unable to run an example code using DataStructures.jl

**URL:** https://discourse.julialang.org/t/unable-to-run-an-example-code-using-datastructures-jl/88204
**Category:** General Usage
**Created:** [October 4, 2022, 3:29am UTC](https://discourse.julialang.org/t/unable-to-run-an-example-code-using-datastructures-jl/88204 "2022-10-04T03:29:44Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Alejandro\_Quiaro\_San](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alejandro_quiaro_san/32/35437_2.png) [@Alejandro\_Quiaro\_San](https://discourse.julialang.org/u/Alejandro_Quiaro_San)
#### Post date: [October 4, 2022, 3:29am UTC](https://discourse.julialang.org/t/unable-to-run-an-example-code-using-datastructures-jl/88204/1 "2022-10-04T03:29:44Z")

</div>

I am trying to run a simple example code from the DataStructures.jl package but I get an error.

```julia
data = collect(enumerate(["foo", "bar", "baz"]))

h1 = BinaryHeap(data) # Standard lexicographic ordering for tuples
first(h1) # => (1, "foo")

h2 = BinaryHeap(Base.By(last), data) # Order by 2nd element only
first(h2) # => (2, "bar")

ERROR: MethodError: no method matching BinaryHeap(::Vector{Tuple{Int64, String}})
Closest candidates are:
  BinaryHeap(::Base.Order.Ordering, ::AbstractVector{T}) where T at ~/.julia/packages/DataStructures/59MD0/src/heaps/binary_heap.jl:47
Stacktrace:
 [1] top-level scope
   @ ~/Desktop/ShortestPath/heaptest.jl:4

```

I have been checking online, some people solved the problem by renaming the environment, others had to update the packages. But I still cannot make this work. If anyone has an idea I will be really grateful, I wrote a code that was working perfectly were the main line is precisely a BinaryHeap.

Thanks

---

<div class="post-metadata">

### Author: ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)
#### Post date: [October 4, 2022, 7:54am UTC](https://discourse.julialang.org/t/unable-to-run-an-example-code-using-datastructures-jl/88204/2 "2022-10-04T07:54:27Z")

</div>

It seems, that the default method without ordering is removed:

```julia
julia> methods(BinaryHeap)
# 1 method for type constructor:
[1] BinaryHeap(ordering::Base.Order.Ordering, xs::AbstractVector{T}) where T in DataStructures at C:\Users\Oli\.julia\packages\DataStructures\59MD0\src\heaps\binary_heap.jl:47

```

So you may work around with the default ordering give explicitly:

```julia
h1 = BinaryHeap(Base.Order.ForwardOrdering(),data)

```

I didn’t check the package change history or issues for more information about it, but either it’s a bug so that the default method doesn’t appear or it is by purpose than the documentation needs to be updated at this example. There is an open issue already: [Bug when using Base.By(last) in a BinaryHeap · Issue #828 · JuliaCollections/DataStructures.jl · GitHub](https://github.com/JuliaCollections/DataStructures.jl/issues/828) (by you, well done!).
