Hey All
I have some code pasted below making use of PriorityQueue from DataStructures package
I’d like to store key value pairs in a sorted manner to easily retrieve the lowest key from the set.
I need to be able to use duplicated key values
PriorityQueue from DataStructures package does not allow for duplicated key values
I understand there is a number of heap functions and data structures that do allow for duplicated key values
But after a few hours of searching I can not find a clear example showing how to use these heap functions or data structures
What few clear examples I can find seem to not allow for key value pair storage
Please can you clearly write an example showing how to store integer keys and string values in a sorted manner
Thank you very much for the help
julia> using DataStructures
julia> my_q = PriorityQueue{Int64, String}()
PriorityQueue{Int64, String, Base.Order.ForwardOrdering}()
julia> enqueue!(my_q, 1, "First one")
PriorityQueue{Int64, String, Base.Order.ForwardOrdering} with 1 entry:
1 => "First one"
julia> enqueue!(my_q, 4, "Fourth one")
PriorityQueue{Int64, String, Base.Order.ForwardOrdering} with 2 entries:
1 => "First one"
4 => "Fourth one"
julia> enqueue!(my_q, 1, "first one again")
ERROR: ArgumentError: PriorityQueue keys must be unique
Stacktrace:
[1] enqueue!(pq::PriorityQueue{Int64, String, Base.Order.ForwardOrdering}, pair::Pair{Int64, String})
@ DataStructures C:\Users\Lee.Phillips\.julia\packages\DataStructures\MKv4P\src\priorityqueue.jl:231
[2] enqueue!(pq::PriorityQueue{Int64, String, Base.Order.ForwardOrdering}, key::Int64, value::String)
@ DataStructures C:\Users\Lee.Phillips\.julia\packages\DataStructures\MKv4P\src\priorityqueue.jl:246
[3] top-level scope
@ REPL[5]:1
julia>