JuliaCollections / DataStructures.jl

Julia implementation of Data structures
https://juliacollections.github.io/DataStructures.jl/latest/
MIT License
689 stars 243 forks source link

`push!` for `Queue` failed #900

Closed HaoxuanGuo closed 7 months ago

HaoxuanGuo commented 7 months ago

No methods matching push! for Queue.

❯ julia
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.10.1 (2024-02-13)
 _/ |\__'_|_|_|\__'_|  |  Built by Homebrew (v1.10.1)
|__/                   |

julia> using DataStructures

julia> q = Queue{Int}()
Queue{Int64}(Deque [Int64[]])

julia> push!(q, 1)
ERROR: MethodError: no method matching push!(::Queue{Int64}, ::Int64)

Closest candidates are:
  push!(::Any, ::Any, ::Any)
   @ Base abstractarray.jl:3413
  push!(::Any, ::Any, ::Any, ::Any...)
   @ Base abstractarray.jl:3414
  push!(::Vector{Any}, ::Any)
   @ Base array.jl:1125
  ...

Stacktrace:
 [1] top-level scope
   @ REPL[3]:1

julia>
oxinabox commented 7 months ago

You can only add elements to the start of a Queue, so use pushfirst!

If you want to be able to push onto either end use a Deque.

We should register an error hint for this

HaoxuanGuo commented 7 months ago

Thank you for your help.