I'm using Mathematica 12.1. The documentation for DataStructure["PriorityQueue"]
claims that,
... the highest-priority element is always returned.
The priority of two elements is determined by the
Order
function.
I'm wondering if I could use my own priority function with it, so I tried "overloading" the Order
function (semantically) like
With[{f = 20 - # &},
Block[{Order = Order[f[#1], f[#2]] &},
Module[{hp = CreateDataStructure["PriorityQueue"]},
Scan[hp["Push", #] &, Range[20]];
hp["Pop"]
]]]
but failed to change its behavior -- outcome is still 20 while 0 is expected.
Could this be achieved or one has to do the implementation by oneself since seemingly DataStructure
s don't support functions like SortBy
?
"Push"
operation. It seems chaotic to have an ad hocOrder
behavior for each operation. I suspect you are seeking functionality that isn't (yet) implemented. $\endgroup$Order
's behavior, but we can change what we pass to it! Then I seem able to answer my own question :-) Please contribute while there's room for improvement. $\endgroup$