Search code examples
juliapriority-queue

Julia popfirst! is throwing error for PriorityQueue


using DataStructures
x = PriorityQueue(Base.Order.Forward, "a" => 2, "b" => 3, "c" => 1)
Base.popfirst!(x)

is throwing error

ERROR: MethodError: no method matching popfirst!(::PriorityQueue{String, Int64, Base.Order.ForwardOrdering})
Closest candidates are:
  popfirst!(::OrderedSet) at C:\Users\Vinod\.julia\packages\OrderedCollections\SInLM\src\ordered_set.jl:58
  popfirst!(::AbstractChannel) at channels.jl:11
  popfirst!(::CircularDeque) at C:\Users\Vinod\.julia\packages\DataStructures\MKv4P\src\circ_deque.jl:91
  ...
Stacktrace:
 [1] top-level scope
   @ REPL[34]:1

all other methods seems to be working.

DataStructures


Solution

  • That is the documentation for the in-development version (you can see that on the bottom left in the sidebar, it says "Version [dev]"). So popfirst! will be available in the next version of DataStructures (unless that decision changes for some reason - since it's still an in-development version).

    To access the documentation for the current version, you can click on that [dev] box on the bottom left and choose stable instead (or if you're using an older version of DataStructures for some reason, choose that instead). For the current stable version, you can use dequeue_pair! or dequeue! instead of popfirst!:

    dequeue!(pq)              # remove and return the lowest priority key
    dequeue_pair!(pq)         # remove and return the lowest priorty key and value
    

    from https://juliacollections.github.io/DataStructures.jl/stable/priority-queue/#Priority-Queue-1